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")
174 :key_server => 'hkp://pgp.mit.edu',
176 it "should contain apt::key" do
177 should contain_apt__key(title).with({
179 :ensure => 'present',
180 :key_server => 'hkp://pgp.mit.edu',
184 context "url with port number" do
186 :key_server => 'hkp://pgp.mit.edu:80',
188 it "should contain apt::key" do
189 should contain_apt__key(title).with({
191 :ensure => 'present',
192 :key_server => 'hkp://pgp.mit.edu:80',
197 context "incorrect port number url" do
199 :key_server => 'hkp://pgp.mit.edu:8008080'
202 expect { subject }.to raise_error(/does not match/)
205 context "incorrect protocol for url" do
207 :key_server => 'abc://pgp.mit.edu:80'
210 expect { subject }.to raise_error(/does not match/)
213 context "missing port number url" do
215 :key_server => 'hkp://pgp.mit.edu:'
218 expect { subject }.to raise_error(/does not match/)
221 context "malform url" do
223 :key_server => 'hkp://pgp.mit.edu.'
226 expect { subject }.to raise_error(/does not match/)
229 context "exceed characher url" do
231 :key_server => 'hkp://pgpiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.mit.edu'
234 expect { subject }.to raise_error(/does not match/)
240 describe 'key_options =>' do
242 :key_options => 'debug',
245 it 'contains the apt::key' do
246 should contain_apt__key(title).with({
248 :ensure => 'present',
249 :key_options => 'debug',
252 it 'contains the apt_key' do
253 should contain_apt_key(title).with({
255 :ensure => 'present',
259 :keyserver_options => params[:key_options],
262 it 'contains the apt_key present anchor' do
263 should contain_anchor("apt_key #{title} present")
268 describe 'validation' do
269 context 'invalid key' do
271 'Out of rum. Why? Why are we out of rum?'
274 expect { subject }.to raise_error(/does not match/)
278 context 'invalid source' do
280 :key_source => 'afp://puppetlabs.com/key.gpg',
283 expect { subject }.to raise_error(/does not match/)
287 context 'invalid content' do
292 expect { subject }.to raise_error(/is not a string/)
296 context 'invalid server' do
298 :key_server => 'two bottles of rum',
301 expect { subject }.to raise_error(/does not match/)
305 context 'invalid keyserver_options' do
310 expect { subject }.to raise_error(/is not a string/)
315 describe 'duplication' do
316 context 'two apt::key resources for same key, different titles' do
317 let :pre_condition do
318 "apt::key { 'duplicate': key => #{title}, }"
321 it 'contains two apt::key resources' do
322 should contain_apt__key('duplicate').with({
324 :ensure => 'present',
326 should contain_apt__key(title).with({
328 :ensure => 'present',
332 it 'contains only a single apt_key' do
333 should contain_apt_key('duplicate').with({
335 :ensure => 'present',
339 :keyserver_options => nil,
341 should_not contain_apt_key(title)
345 context 'two apt::key resources, different ensure' do
346 let :pre_condition do
347 "apt::key { 'duplicate': key => #{title}, ensure => 'absent', }"
349 it 'informs the user of the impossibility' do
350 expect { subject }.to raise_error(/already ensured as absent/)