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 GPG_KEY_ID = '6F6B15509CF8E59E6E469F327F438280EF8D349F'
51 describe 'normal operation' do
52 describe 'default options' do
54 expect(subject).to contain_apt_key(title).with(id: title,
57 server: 'keyserver.ubuntu.com',
61 it 'contains the apt_key present anchor' do
62 expect(subject).to contain_anchor("apt_key #{title} present")
66 describe 'title and key =>' do
77 it 'contains the apt_key' do
78 expect(subject).to contain_apt_key(title).with(id: GPG_KEY_ID,
81 server: 'keyserver.ubuntu.com',
85 it 'contains the apt_key present anchor' do
86 expect(subject).to contain_anchor("apt_key #{GPG_KEY_ID} present")
90 describe 'ensure => absent' do
97 it 'contains the apt_key' do
98 expect(subject).to contain_apt_key(title).with(id: title,
101 server: 'keyserver.ubuntu.com',
105 it 'contains the apt_key absent anchor' do
106 expect(subject).to contain_anchor("apt_key #{title} absent")
110 describe 'set a bunch of things!' do
113 content: 'GPG key content',
114 source: 'http://apt.puppetlabs.com/pubkey.gpg',
115 server: 'pgp.mit.edu',
120 it 'contains the apt_key' do
121 expect(subject).to contain_apt_key(title).with(contains_apt_key_example(title))
124 it 'contains the apt_key present anchor' do
125 expect(subject).to contain_anchor("apt_key #{title} present")
129 context 'when domain has dash' do
132 server: 'p-gp.m-it.edu'
136 it 'contains the apt_key' do
137 expect(subject).to contain_apt_key(title).with(id: title,
138 server: 'p-gp.m-it.edu')
142 context 'with url' do
145 server: 'hkp://pgp.mit.edu'
149 it 'contains the apt_key' do
150 expect(subject).to contain_apt_key(title).with(id: title,
151 server: 'hkp://pgp.mit.edu')
155 context 'with url and port number' do
158 server: 'hkp://pgp.mit.edu:80'
162 it 'contains the apt_key' do
163 expect(subject).to contain_apt_key(title).with(id: title,
164 server: 'hkp://pgp.mit.edu:80')
169 describe 'validation' do
170 context 'when domain begins with a dash' do
173 server: '-pgp.mit.edu'
178 expect(subject).to raise_error(%r{expects a match})
182 context 'when domain begins with dot' do
185 server: '.pgp.mit.edu'
190 expect(subject).to raise_error(%r{expects a match})
194 context 'when domain ends with dot' do
197 server: 'pgp.mit.edu.'
202 expect(subject).to raise_error(%r{expects a match})
206 context 'when url character limit is exceeded' do
209 server: 'hkp://pgpiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.mit.edu'
214 expect(subject).to raise_error(%r{expects a match})
218 context 'with incorrect port number url' do
221 server: 'hkp://pgp.mit.edu:8008080'
226 expect(subject).to raise_error(%r{expects a match})
230 context 'with incorrect protocol for url' do
233 server: 'abc://pgp.mit.edu:80'
238 expect(subject).to raise_error(%r{expects a match})
242 context 'with missing port number url' do
245 server: 'hkp://pgp.mit.edu:'
250 expect(subject).to raise_error(%r{expects a match})
254 context 'with url ending with a dot' do
257 server: 'hkp://pgp.mit.edu.'
262 expect(subject).to raise_error(%r{expects a match})
266 context 'with url begin with a dash' do
269 server: 'hkp://-pgp.mit.edu'
274 expect(subject).to raise_error(%r{expects a match})
278 context 'with invalid key' do
280 'Out of rum. Why? Why are we out of rum?'
284 expect(subject).to raise_error(%r{expects a match})
288 context 'with invalid source' do
291 source: 'afp://puppetlabs.com/key.gpg'
296 expect(subject).to raise_error(%r{evaluating a Resource})
300 context 'with invalid content' do
308 expect(subject).to raise_error(%r{expects a})
312 context 'with invalid server' do
315 server: 'two bottles of rum'
320 expect(subject).to raise_error(%r{expects a match})
324 context 'with invalid keyserver_options' do
332 expect(subject).to raise_error(%r{expects a})
336 context 'with invalid ensure' do
344 expect(subject).to raise_error(%r{Enum\['absent', 'present', 'refreshed'\]})
348 describe 'duplication - two apt::key resources for same key, different titles' do
349 let :pre_condition do
350 "#{super()}\napt::key { 'duplicate': id => '#{title}', }"
353 it 'contains the duplicate apt::key resource' do
354 expect(subject).to contain_apt__key('duplicate').with(id: title,
358 it 'contains the original apt::key resource' do
359 expect(subject).to contain_apt__key(title).with(id: title,
363 it 'contains the native apt_key' do
364 expect(subject).to contain_apt_key('duplicate').with(apt_key_example(title))
367 it 'does not contain the original apt_key' do
368 expect(subject).not_to contain_apt_key(title)
372 describe 'duplication - two apt::key resources, different ensure' do
373 let :pre_condition do
374 "#{super()}\napt::key { 'duplicate': id => '#{title}', ensure => 'absent', }"
377 it 'informs the user of the impossibility' do
378 expect(subject).to raise_error(%r{already ensured as absent})