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
146 :key_server => 'pgp.mit.edu',
149 it 'contains the apt::key' do
150 should contain_apt__key(title).with({
152 :ensure => 'present',
153 :key_server => 'pgp.mit.edu',
156 it 'contains the apt_key' do
157 should contain_apt_key(title).with({
159 :ensure => 'present',
161 :server => params[:key_server],
163 :keyserver_options => nil,
166 it 'contains the apt_key present anchor' do
167 should contain_anchor("apt_key #{title} present")
171 describe 'key_options =>' do
173 :key_options => 'debug',
176 it 'contains the apt::key' do
177 should contain_apt__key(title).with({
179 :ensure => 'present',
180 :key_options => 'debug',
183 it 'contains the apt_key' do
184 should contain_apt_key(title).with({
186 :ensure => 'present',
190 :keyserver_options => params[:key_options],
193 it 'contains the apt_key present anchor' do
194 should contain_anchor("apt_key #{title} present")
199 describe 'validation' do
200 context 'invalid key' do
202 'Out of rum. Why? Why are we out of rum?'
205 expect { subject }.to raise_error(/does not match/)
209 context 'invalid source' do
211 :key_source => 'afp://puppetlabs.com/key.gpg',
214 expect { subject }.to raise_error(/does not match/)
218 context 'invalid content' do
223 expect { subject }.to raise_error(/is not a string/)
227 context 'invalid server' do
229 :key_server => 'two bottles of rum',
232 expect { subject }.to raise_error(/must be a valid domain name/)
236 context 'invalid keyserver_options' do
241 expect { subject }.to raise_error(/is not a string/)
246 describe 'duplication' do
247 context 'two apt::key resources for same key, different titles' do
248 let :pre_condition do
249 "apt::key { 'duplicate': key => #{title}, }"
252 it 'contains two apt::key resources' do
253 should contain_apt__key('duplicate').with({
255 :ensure => 'present',
257 should contain_apt__key(title).with({
259 :ensure => 'present',
263 it 'contains only a single apt_key' do
264 should contain_apt_key('duplicate').with({
266 :ensure => 'present',
270 :keyserver_options => nil,
272 should_not contain_apt_key(title)
276 context 'two apt::key resources, different ensure' do
277 let :pre_condition do
278 "apt::key { 'duplicate': key => #{title}, ensure => 'absent', }"
280 it 'informs the user of the impossibility' do
281 expect { subject }.to raise_error(/already ensured as absent/)