1 # frozen_string_literal: true
5 def contains_apt_key_example(title)
8 source: 'http://apt.puppetlabs.com/pubkey.gpg',
10 content: params[:content],
14 def apt_key_example(title)
18 server: 'keyserver.ubuntu.com',
20 keyserver_options: nil }
23 describe 'apt::key', type: :define do
24 let(:title) { '6F6B15509CF8E59E6E469F327F438280EF8D349F' }
25 let(:pre_condition) { 'include apt' }
43 describe 'normal operation' do
44 describe 'default options' do
46 expect(subject).to contain_apt_key(title).with(id: title,
49 server: 'keyserver.ubuntu.com',
53 it 'contains the apt_key present anchor' do
54 expect(subject).to contain_anchor("apt_key #{title} present")
58 describe 'title and key =>' do
69 it 'contains the apt_key' do
70 expect(subject).to contain_apt_key(title).with(id: title,
73 server: 'keyserver.ubuntu.com',
77 it 'contains the apt_key present anchor' do
78 expect(subject).to contain_anchor("apt_key #{title} present")
82 describe 'ensure => absent' do
89 it 'contains the apt_key' do
90 expect(subject).to contain_apt_key(title).with(id: title,
93 server: 'keyserver.ubuntu.com',
97 it 'contains the apt_key absent anchor' do
98 expect(subject).to contain_anchor("apt_key #{title} absent")
102 describe 'set a bunch of things!' do
105 content: 'GPG key content',
106 source: 'http://apt.puppetlabs.com/pubkey.gpg',
107 server: 'pgp.mit.edu',
112 it 'contains the apt_key' do
113 expect(subject).to contain_apt_key(title).with(contains_apt_key_example(title))
116 it 'contains the apt_key present anchor' do
117 expect(subject).to contain_anchor("apt_key #{title} present")
121 context 'when domain has dash' do
124 server: 'p-gp.m-it.edu'
128 it 'contains the apt_key' do
129 expect(subject).to contain_apt_key(title).with(id: title,
130 server: 'p-gp.m-it.edu')
134 context 'with url' do
137 server: 'hkp://pgp.mit.edu'
141 it 'contains the apt_key' do
142 expect(subject).to contain_apt_key(title).with(id: title,
143 server: 'hkp://pgp.mit.edu')
147 context 'with url and port number' do
150 server: 'hkp://pgp.mit.edu:80'
154 it 'contains the apt_key' do
155 expect(subject).to contain_apt_key(title).with(id: title,
156 server: 'hkp://pgp.mit.edu:80')
161 describe 'validation' do
162 context 'when domain begins with a dash' do
165 server: '-pgp.mit.edu'
170 expect(subject).to raise_error(%r{expects a match})
174 context 'when domain begins with dot' do
177 server: '.pgp.mit.edu'
182 expect(subject).to raise_error(%r{expects a match})
186 context 'when domain ends with dot' do
189 server: 'pgp.mit.edu.'
194 expect(subject).to raise_error(%r{expects a match})
198 context 'when url character limit is exceeded' do
201 server: 'hkp://pgpiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.mit.edu'
206 expect(subject).to raise_error(%r{expects a match})
210 context 'with incorrect port number url' do
213 server: 'hkp://pgp.mit.edu:8008080'
218 expect(subject).to raise_error(%r{expects a match})
222 context 'with incorrect protocol for url' do
225 server: 'abc://pgp.mit.edu:80'
230 expect(subject).to raise_error(%r{expects a match})
234 context 'with missing port number url' do
237 server: 'hkp://pgp.mit.edu:'
242 expect(subject).to raise_error(%r{expects a match})
246 context 'with url ending with a dot' do
249 server: 'hkp://pgp.mit.edu.'
254 expect(subject).to raise_error(%r{expects a match})
258 context 'with url begin with a dash' do
261 server: 'hkp://-pgp.mit.edu'
266 expect(subject).to raise_error(%r{expects a match})
270 context 'with invalid key' do
272 'Out of rum. Why? Why are we out of rum?'
276 expect(subject).to raise_error(%r{expects a match})
280 context 'with invalid source' do
283 source: 'afp://puppetlabs.com/key.gpg'
288 expect(subject).to raise_error(%r{evaluating a Resource})
292 context 'with invalid content' do
300 expect(subject).to raise_error(%r{expects a})
304 context 'with invalid server' do
307 server: 'two bottles of rum'
312 expect(subject).to raise_error(%r{expects a match})
316 context 'with invalid keyserver_options' do
324 expect(subject).to raise_error(%r{expects a})
328 context 'with invalid ensure' do
336 expect(subject).to raise_error(%r{Enum\['absent', 'present', 'refreshed'\]})
340 describe 'duplication - two apt::key resources for same key, different titles' do
341 let :pre_condition do
342 "#{super()}\napt::key { 'duplicate': id => '#{title}', }"
345 it 'contains the duplicate apt::key resource' do
346 expect(subject).to contain_apt__key('duplicate').with(id: title,
350 it 'contains the original apt::key resource' do
351 expect(subject).to contain_apt__key(title).with(id: title,
355 it 'contains the native apt_key' do
356 expect(subject).to contain_apt_key('duplicate').with(apt_key_example(title))
359 it 'does not contain the original apt_key' do
360 expect(subject).not_to contain_apt_key(title)
364 describe 'duplication - two apt::key resources, different ensure' do
365 let :pre_condition do
366 "#{super()}\napt::key { 'duplicate': id => '#{title}', ensure => 'absent', }"
369 it 'informs the user of the impossibility' do
370 expect(subject).to raise_error(%r{already ensured as absent})