3 describe 'apt::key', :type => :define do
5 :lsbdistid => 'Debian',
8 GPG_KEY_ID = '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30'
18 describe 'normal operation' do
19 describe 'default options' do
20 it 'contains the apt_key' do
21 should contain_apt_key(title).with({
25 :server => 'keyserver.ubuntu.com',
27 :keyserver_options => nil,
30 it 'contains the apt_key present anchor' do
31 should contain_anchor("apt_key #{title} present")
35 describe 'title and key =>' do
44 it 'contains the apt_key' do
45 should contain_apt_key(title).with({
49 :server => 'keyserver.ubuntu.com',
51 :keyserver_options => nil,
54 it 'contains the apt_key present anchor' do
55 should contain_anchor("apt_key #{GPG_KEY_ID} present")
59 describe 'ensure => absent' do
64 it 'contains the apt_key' do
65 should contain_apt_key(title).with({
69 :server => 'keyserver.ubuntu.com',
71 :keyserver_options => nil,
74 it 'contains the apt_key absent anchor' do
75 should contain_anchor("apt_key #{title} absent")
79 describe 'set a bunch of things!' do
81 :key_content => 'GPG key content',
82 :key_source => 'http://apt.puppetlabs.com/pubkey.gpg',
83 :key_server => 'pgp.mit.edu',
84 :key_options => 'debug',
87 it 'contains the apt_key' do
88 should contain_apt_key(title).with({
91 :source => 'http://apt.puppetlabs.com/pubkey.gpg',
92 :server => 'pgp.mit.edu',
93 :content => params[:key_content],
97 it 'contains the apt_key present anchor' do
98 should contain_anchor("apt_key #{title} present")
102 context "domain with dash" do
104 :key_server => 'p-gp.m-it.edu',
106 it 'contains the apt_key' do
107 should contain_apt_key(title).with({
109 :server => 'p-gp.m-it.edu',
117 :key_server => 'hkp://pgp.mit.edu',
120 it 'contains the apt_key' do
121 should contain_apt_key(title).with({
123 :server => 'hkp://pgp.mit.edu',
127 context "url with port number" do
130 :key_server => 'hkp://pgp.mit.edu:80',
133 it 'contains the apt_key' do
134 should contain_apt_key(title).with({
136 :server => 'hkp://pgp.mit.edu:80',
142 describe 'validation' do
143 context "domain begin with dash" do
145 :key_server => '-pgp.mit.edu',
148 expect { subject.call } .to raise_error(/does not match/)
152 context "domain begin with dot" do
154 :key_server => '.pgp.mit.edu',
157 expect { subject.call } .to raise_error(/does not match/)
161 context "domain end with dot" do
163 :key_server => "pgp.mit.edu.",
166 expect { subject.call } .to raise_error(/does not match/)
169 context "exceed character url" do
172 :key_server => 'hkp://pgpiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.mit.edu'
176 expect { subject.call }.to raise_error(/does not match/)
179 context "incorrect port number url" do
182 :key_server => 'hkp://pgp.mit.edu:8008080'
186 expect { subject.call }.to raise_error(/does not match/)
189 context "incorrect protocol for url" do
192 :key_server => 'abc://pgp.mit.edu:80'
196 expect { subject.call }.to raise_error(/does not match/)
199 context "missing port number url" do
202 :key_server => 'hkp://pgp.mit.edu:'
206 expect { subject.call }.to raise_error(/does not match/)
209 context "url ending with a dot" do
212 :key_server => 'hkp://pgp.mit.edu.'
216 expect { subject.call }.to raise_error(/does not match/)
219 context "url begin with a dash" do
221 :key_server => "hkp://-pgp.mit.edu",
224 expect { subject.call }.to raise_error(/does not match/)
227 context 'invalid key' do
229 'Out of rum. Why? Why are we out of rum?'
232 expect { subject.call }.to raise_error(/does not match/)
236 context 'invalid source' do
238 :key_source => 'afp://puppetlabs.com/key.gpg',
241 expect { subject.call }.to raise_error(/does not match/)
245 context 'invalid content' do
250 expect { subject.call }.to raise_error(/is not a string/)
254 context 'invalid server' do
256 :key_server => 'two bottles of rum',
259 expect { subject.call }.to raise_error(/does not match/)
263 context 'invalid keyserver_options' do
268 expect { subject.call }.to raise_error(/is not a string/)
272 context 'invalid ensure' do
279 expect { subject.call }.to raise_error(/does not match/)
283 describe 'duplication' do
284 context 'two apt::key resources for same key, different titles' do
285 let :pre_condition do
286 "#{super()}\napt::key { 'duplicate': key => '#{title}', }"
289 it 'contains two apt::key resources' do
290 should contain_apt__key('duplicate').with({
292 :ensure => 'present',
294 should contain_apt__key(title).with({
296 :ensure => 'present',
300 it 'contains only a single apt_key' do
301 should contain_apt_key('duplicate').with({
303 :ensure => 'present',
305 :server => 'keyserver.ubuntu.com',
307 :keyserver_options => nil,
309 should_not contain_apt_key(title)
313 context 'two apt::key resources, different ensure' do
314 let :pre_condition do
315 "#{super()}\napt::key { 'duplicate': key => '#{title}', ensure => 'absent', }"
317 it 'informs the user of the impossibility' do
318 expect { subject.call }.to raise_error(/already ensured as absent/)