unattended_upgrades: Fix matching security archive
[puppet-modules/puppetlabs-apt.git] / spec / classes / unattended_upgrades_spec.rb
1 require 'spec_helper'
2 describe 'apt::unattended_upgrades', :type => :class do
3   let(:file_unattended) { '/etc/apt/apt.conf.d/50unattended-upgrades' }
4   let(:file_periodic) { '/etc/apt/apt.conf.d/10periodic' }
5   let(:facts) { { :lsbdistid => 'Debian' } }
6
7   it { should contain_package("unattended-upgrades") }
8
9   it {
10     should create_file("/etc/apt/apt.conf.d/50unattended-upgrades").with({
11       "owner"   => "root",
12       "group"   => "root",
13       "mode"    => "0644",
14       "require" => "Package[unattended-upgrades]",
15     })
16   }
17
18   it {
19     should create_file("/etc/apt/apt.conf.d/10periodic").with({
20       "owner"   => "root",
21       "group"   => "root",
22       "mode"    => "0644",
23       "require" => "Package[unattended-upgrades]",
24     })
25   }
26
27   describe "origins" do
28     describe 'on Debian' do
29       default_facts = { :lsbdistid => 'Debian' }
30       context 'defaults' do
31         let :facts do default_facts end
32         it {
33           should contain_file(file_unattended).with_content(
34             /^Unattended-Upgrade::Origins-Pattern/
35           ).with_content(
36             /"origin=Debian,archive=stable,label=Debian-Security";/
37           )
38         }
39       end
40       context 'defaults with custom origin' do
41         let :facts do default_facts end
42         let :params do { :origins => ['bananana']} end
43         it {
44           should contain_file(file_unattended).with_content(
45             /^Unattended-Upgrade::Origins-Pattern/
46           ).with_content(
47             /"bananana";/
48           )
49         }
50       end
51       context 'defaults with invalid origin' do
52         let :facts do default_facts end
53         let :params do { :origins => 'bananana'} end
54         it {
55           expect {subject}.to raise_error(/is not an Array/)
56         }
57       end
58       context 'squeeze' do
59         let :facts do default_facts.merge({:lsbdistcodename => 'squeeze'}) end
60         it {
61           should contain_file(file_unattended).with_content(
62             /^Unattended-Upgrade::Allowed-Origins/
63           ).with_content(
64             /"\${distro_id} \${distro_codename}-security";/
65           )
66         }
67       end
68       context 'wheezy' do
69         let :facts do default_facts.merge({:lsbdistcodename => 'wheezy'}) end
70         it {
71           should contain_file(file_unattended).with_content(
72             /^Unattended-Upgrade::Origins-Pattern/
73           ).with_content(
74             /"origin=Debian,archive=stable,label=Debian-Security";/
75           )
76         }
77       end
78     end
79
80     describe 'on Ubuntu' do
81       default_facts = { :lsbdistid => 'Ubuntu' }
82       context 'default' do
83         let :facts do default_facts end
84         it {
85           should contain_file(file_unattended).with_content(
86             /^Unattended-Upgrade::Allowed-Origins/
87           ).with_content(
88             /"\${distro_id}\:\${distro_codename}-security";/
89           )
90         }
91       end
92       context 'lucid' do
93         let :facts do default_facts.merge({:lsbdistcodename => 'lucid'}) end
94         it {
95           should contain_file(file_unattended).with_content(
96             /^Unattended-Upgrade::Allowed-Origins/
97           ).with_content(
98             /"\${distro_id} \${distro_codename}-security";/
99           )
100         }
101       end
102       context 'precise' do
103         let :facts do default_facts.merge({:lsbdistcodename => 'precise'}) end
104         it {
105           should contain_file(file_unattended).with_content(
106             /^Unattended-Upgrade::Allowed-Origins/
107           ).with_content(
108             /"\${distro_id}\:\${distro_codename}-security";/
109           )
110         }
111       end
112       context 'trusty' do
113         let :facts do default_facts.merge({:lsbdistcodename => 'trusty'}) end
114         it {
115           should contain_file(file_unattended).with_content(
116             /^Unattended-Upgrade::Allowed-Origins/
117           ).with_content(
118             /"\${distro_id}\:\${distro_codename}-security";/
119           )
120         }
121       end
122     end
123   end
124
125   describe "blacklist" do
126     describe "with param defaults" do
127       let(:params) {{ }}
128       it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Package-Blacklist \{\n\};$/) }
129     end
130
131     describe "with blacklist => []" do
132       let :params do
133         { :blacklist => ['libc6', 'libc6-dev'] }
134       end
135       it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Package-Blacklist \{\n\t"libc6";\n\t"libc6-dev";\n\};$/) }
136     end
137   end
138
139   describe "with update => 2" do
140     let :params do
141       { :update => "2" }
142     end
143     it { should contain_file(file_periodic).with_content(/^APT::Periodic::Update-Package-Lists "2";$/) }
144   end
145
146   describe "with download => 2" do
147     let :params do
148       { :download => "2" }
149     end
150     it { should contain_file(file_periodic).with_content(/^APT::Periodic::Download-Upgradeable-Packages "2";$/) }
151   end
152
153   describe "with upgrade => 2" do
154     let :params do
155       { :upgrade => "2" }
156     end
157     it { should contain_file(file_periodic).with_content(/^APT::Periodic::Unattended-Upgrade "2";$/) }
158   end
159
160   describe "with autoclean => 2" do
161     let :params do
162       { :autoclean => "2" }
163     end
164     it { should contain_file(file_periodic).with_content(/^APT::Periodic::AutocleanInterval "2";$/) }
165   end
166
167   describe "with auto_fix => false" do
168     let :params do
169       { :auto_fix => false }
170     end
171     it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::AutoFixInterruptedDpkg "false";$/) }
172   end
173
174   describe "with minimal_steps => true" do
175     let :params do
176       { :minimal_steps => true }
177     end
178     it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::MinimalSteps "true";$/) }
179   end
180
181   describe "with install_on_shutdown => true" do
182     let :params do
183       { :install_on_shutdown => true }
184     end
185     it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::InstallOnShutdown "true";$/) }
186   end
187
188   describe "mail_to" do
189     describe "param defaults" do
190       let(:params) {{ }}
191       it { should_not contain_file(file_unattended).with_content(/^Unattended-Upgrade::Mail /) }
192       it { should_not contain_file(file_unattended).with_content(/^Unattended-Upgrade::MailOnlyOnError /) }
193     end
194
195     describe "with mail_to => user@website, mail_only_on_error => true" do
196       let :params do
197         { :mail_to => "user@website",
198           :mail_only_on_error => true }
199       end
200       it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Mail "user@website";$/) }
201       it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::MailOnlyOnError "true";$/) }
202     end
203   end
204
205   describe "with remove_unused => false" do
206     let :params do
207       { :remove_unused => false }
208     end
209     it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Remove-Unused-Dependencies "false";$/) }
210   end
211
212   describe "with auto_reboot => true" do
213     let :params do
214       { :auto_reboot => true }
215     end
216     it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Automatic-Reboot "true";$/) }
217   end
218
219   describe "dl_limit" do
220     describe "param defaults" do
221       let(:params) {{ }}
222       it { should_not contain_file(file_unattended).with_content(/^Acquire::http::Dl-Limit /) }
223     end
224
225     describe "with dl_limit => 70" do
226       let :params do
227         { :dl_limit => "70" }
228       end
229       it { should contain_file(file_unattended).with_content(/^Acquire::http::Dl-Limit "70";$/) }
230     end
231   end
232
233   describe "with enable => 0" do
234     let :params do
235       { :enable => "0" }
236     end
237     it { should contain_file(file_periodic).with_content(/^APT::Periodic::Enable "0";$/) }
238   end
239
240   describe "with backup_interval => 1" do
241     let :params do
242       { :backup_interval => "1" }
243     end
244     it { should contain_file(file_periodic).with_content(/^APT::Periodic::BackUpArchiveInterval "1";$/) }
245   end
246
247   describe "with backup_level => 0" do
248     let :params do
249       { :backup_level => "0" }
250     end
251     it { should contain_file(file_periodic).with_content(/^APT::Periodic::BackUpLevel "0";$/) }
252   end
253
254   describe "with max_age => 1" do
255     let :params do
256       { :max_age => "1" }
257     end
258     it { should contain_file(file_periodic).with_content(/^APT::Periodic::MaxAge "1";$/) }
259   end
260
261   describe "with min_age => 1" do
262     let :params do
263       { :min_age => "1" }
264     end
265     it { should contain_file(file_periodic).with_content(/^APT::Periodic::MinAge "1";$/) }
266   end
267
268   describe "with max_size => 1" do
269     let :params do
270       { :max_size => "1" }
271     end
272     it { should contain_file(file_periodic).with_content(/^APT::Periodic::MaxSize "1";$/) }
273   end
274
275   describe "with download_delta => 2" do
276     let :params do
277       { :download_delta => "2" }
278     end
279     it { should contain_file(file_periodic).with_content(/^APT::Periodic::Download-Upgradeable-Packages-Debdelta "2";$/) }
280   end
281
282   describe "with verbose => 2" do
283     let :params do
284       { :verbose => "2" }
285     end
286     it { should contain_file(file_periodic).with_content(/^APT::Periodic::Verbose "2";$/) }
287   end
288
289 end