3 describe 'apt::key', :type => :define do
4 let(:facts) { { :lsbdistid => 'Debian' } }
5 GPG_KEY_ID = '4BD6EC30'
11 describe 'normal operation' do
12 describe 'default options' do
13 it 'contains the apt::key' do
14 should contain_apt__key(title).with({
19 it 'contains the apt_key' do
20 should contain_apt_key(title).with({
26 :keyserver_options => nil,
29 it 'contains the apt_key present anchor' do
30 should contain_anchor("apt_key #{title} present")
34 describe 'title and key =>' do
43 it 'contains the apt::key' do
44 should contain_apt__key(title).with({
49 it 'contains the apt_key' do
50 should contain_apt_key(title).with({
56 :keyserver_options => nil,
59 it 'contains the apt_key present anchor' do
60 should contain_anchor("apt_key #{GPG_KEY_ID} present")
64 describe 'ensure => absent' do
69 it 'contains the apt::key' do
70 should contain_apt__key(title).with({
75 it 'contains the apt_key' do
76 should contain_apt_key(title).with({
82 :keyserver_options => nil,
85 it 'contains the apt_key absent anchor' do
86 should contain_anchor("apt_key #{title} absent")
90 describe 'key_content =>' do
92 :key_content => 'GPG key content',
95 it 'contains the apt::key' do
96 should contain_apt__key(title).with({
99 :key_content => params[:key_content],
102 it 'contains the apt_key' do
103 should contain_apt_key(title).with({
105 :ensure => 'present',
108 :content => params[:key_content],
109 :keyserver_options => nil,
112 it 'contains the apt_key present anchor' do
113 should contain_anchor("apt_key #{title} present")
117 describe 'key_source =>' do
119 :key_source => 'http://apt.puppetlabs.com/pubkey.gpg',
122 it 'contains the apt::key' do
123 should contain_apt__key(title).with({
125 :ensure => 'present',
126 :key_source => params[:key_source],
129 it 'contains the apt_key' do
130 should contain_apt_key(title).with({
132 :ensure => 'present',
133 :source => params[:key_source],
136 :keyserver_options => nil,
139 it 'contains the apt_key present anchor' do
140 should contain_anchor("apt_key #{title} present")
144 describe 'key_server =>' do
145 context 'domain name' do
147 :key_server => 'pgp.mit.edu',
150 it 'contains the apt::key' do
151 should contain_apt__key(title).with({
153 :ensure => 'present',
154 :key_server => 'pgp.mit.edu',
157 it 'contains the apt_key' do
158 should contain_apt_key(title).with({
160 :ensure => 'present',
162 :server => params[:key_server],
164 :keyserver_options => nil,
167 it 'contains the apt_key present anchor' do
168 should contain_anchor("apt_key #{title} present")
172 context "domain with dash" do
174 :key_server => 'p-gp.m-it.edu',
176 it "should contain apt::key" do
177 should contain_apt__key(title).with({
179 :ensure => 'present',
180 :key_server => 'p-gp.m-it.edu',
185 context "domain begin with dash" do
187 :key_server => '-pgp.mit.edu',
190 expect { subject } .to raise_error(/does not match/)
194 context "domain begin with dot" do
196 :key_server => '.pgp.mit.edu',
199 expect { subject } .to raise_error(/does not match/)
203 context "domain end with dot" do
205 :key_server => "pgp.mit.edu.",
208 expect { subject } .to raise_error(/does not match/)
214 :key_server => 'hkp://pgp.mit.edu',
216 it "should contain apt::key" do
217 should contain_apt__key(title).with({
219 :ensure => 'present',
220 :key_server => 'hkp://pgp.mit.edu',
224 context "url with port number" do
226 :key_server => 'hkp://pgp.mit.edu:80',
228 it "should contain apt::key" do
229 should contain_apt__key(title).with({
231 :ensure => 'present',
232 :key_server => 'hkp://pgp.mit.edu:80',
237 context "incorrect port number url" do
239 :key_server => 'hkp://pgp.mit.edu:8008080'
242 expect { subject }.to raise_error(/does not match/)
245 context "incorrect protocol for url" do
247 :key_server => 'abc://pgp.mit.edu:80'
250 expect { subject }.to raise_error(/does not match/)
253 context "missing port number url" do
255 :key_server => 'hkp://pgp.mit.edu:'
258 expect { subject }.to raise_error(/does not match/)
261 context "url ending with a dot" do
263 :key_server => 'hkp://pgp.mit.edu.'
266 expect { subject }.to raise_error(/does not match/)
269 context "url begin with a dash" do
271 :key_server => "hkp://-pgp.mit.edu",
274 expect { subject }.to raise_error(/does not match/)
277 context "url with dash" do
279 :key_server => 'hkp://p-gp.m-it.edu',
281 it "should contain apt::key" do
282 should contain_apt__key(title).with({
284 :ensure => 'present',
285 :key_server => 'hkp://p-gp.m-it.edu',
289 context "exceed characher url" do
291 :key_server => 'hkp://pgpiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.mit.edu'
294 expect { subject }.to raise_error(/does not match/)
299 describe 'key_options =>' do
301 :key_options => 'debug',
304 it 'contains the apt::key' do
305 should contain_apt__key(title).with({
307 :ensure => 'present',
308 :key_options => 'debug',
311 it 'contains the apt_key' do
312 should contain_apt_key(title).with({
314 :ensure => 'present',
318 :keyserver_options => params[:key_options],
321 it 'contains the apt_key present anchor' do
322 should contain_anchor("apt_key #{title} present")
327 describe 'validation' do
328 context 'invalid key' do
330 'Out of rum. Why? Why are we out of rum?'
333 expect { subject }.to raise_error(/does not match/)
337 context 'invalid source' do
339 :key_source => 'afp://puppetlabs.com/key.gpg',
342 expect { subject }.to raise_error(/does not match/)
346 context 'invalid content' do
351 expect { subject }.to raise_error(/is not a string/)
355 context 'invalid server' do
357 :key_server => 'two bottles of rum',
360 expect { subject }.to raise_error(/does not match/)
364 context 'invalid keyserver_options' do
369 expect { subject }.to raise_error(/is not a string/)
374 describe 'duplication' do
375 context 'two apt::key resources for same key, different titles' do
376 let :pre_condition do
377 "apt::key { 'duplicate': key => #{title}, }"
380 it 'contains two apt::key resources' do
381 should contain_apt__key('duplicate').with({
383 :ensure => 'present',
385 should contain_apt__key(title).with({
387 :ensure => 'present',
391 it 'contains only a single apt_key' do
392 should contain_apt_key('duplicate').with({
394 :ensure => 'present',
398 :keyserver_options => nil,
400 should_not contain_apt_key(title)
404 context 'two apt::key resources, different ensure' do
405 let :pre_condition do
406 "apt::key { 'duplicate': key => #{title}, ensure => 'absent', }"
408 it 'informs the user of the impossibility' do
409 expect { subject }.to raise_error(/already ensured as absent/)