1 # frozen_string_literal: true
5 sources_list = { ensure: 'file',
6 path: '/etc/apt/sources.list',
9 notify: 'Class[Apt::Update]' }
11 sources_list_d = { ensure: 'directory',
12 path: '/etc/apt/sources.list.d',
17 notify: 'Class[Apt::Update]' }
19 preferences = { ensure: 'file',
20 path: '/etc/apt/preferences',
23 notify: 'Class[Apt::Update]' }
25 preferences_d = { ensure: 'directory',
26 path: '/etc/apt/preferences.d',
31 notify: 'Class[Apt::Update]' }
33 apt_conf_d = { ensure: 'directory',
34 path: '/etc/apt/apt.conf.d',
39 notify: 'Class[Apt::Update]' }
59 context 'with defaults' do
61 is_expected.to contain_file('sources.list').that_notifies('Class[Apt::Update]').only_with(sources_list)
65 is_expected.to contain_file('sources.list.d').that_notifies('Class[Apt::Update]').only_with(sources_list_d)
69 is_expected.to contain_file('preferences').that_notifies('Class[Apt::Update]').only_with(preferences)
73 is_expected.to contain_file('preferences.d').that_notifies('Class[Apt::Update]').only_with(preferences_d)
77 is_expected.to contain_file('apt.conf.d').that_notifies('Class[Apt::Update]').only_with(apt_conf_d)
80 it { is_expected.to contain_file('/etc/apt/auth.conf').with_ensure('absent') }
82 it 'lays down /etc/apt/apt.conf.d/15update-stamp' do
83 is_expected.to contain_file('/etc/apt/apt.conf.d/15update-stamp').with(group: 'root',
84 owner: 'root').with_content(
85 %r{APT::Update::Post-Invoke-Success {"touch /var/lib/apt/periodic/update-success-stamp 2>/dev/null || true";};},
90 is_expected.to contain_exec('apt_update').with(refreshonly: 'true')
93 it { is_expected.not_to contain_apt__setting('conf-proxy') }
97 context 'when host=localhost' do
98 let(:params) { { proxy: { 'host' => 'localhost' } } }
101 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
102 %r{Acquire::http::proxy "http://localhost:8080/";},
104 %r{Acquire::https::proxy},
109 context 'when host=localhost and port=8180' do
110 let(:params) { { proxy: { 'host' => 'localhost', 'port' => 8180 } } }
113 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
114 %r{Acquire::http::proxy "http://localhost:8180/";},
116 %r{Acquire::https::proxy},
121 context 'when host=localhost and https=true' do
122 let(:params) { { proxy: { 'host' => 'localhost', 'https' => true } } }
125 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
126 %r{Acquire::http::proxy "http://localhost:8080/";},
128 %r{Acquire::https::proxy "https://localhost:8080/";},
133 context 'when host=localhost and direct=true' do
134 let(:params) { { proxy: { 'host' => 'localhost', 'direct' => true } } }
137 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
138 %r{Acquire::http::proxy "http://localhost:8080/";},
140 %r{Acquire::https::proxy "DIRECT";},
145 context 'when host=localhost and https=true and direct=true' do
146 let(:params) { { proxy: { 'host' => 'localhost', 'https' => true, 'direct' => true } } }
149 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
150 %r{Acquire::http::proxy "http://localhost:8080/";},
152 %r{Acquire::https::proxy "https://localhost:8080/";},
156 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
157 %r{Acquire::http::proxy "http://localhost:8080/";},
159 %r{Acquire::https::proxy "DIRECT";},
164 context 'when ensure=absent' do
165 let(:params) { { proxy: { 'ensure' => 'absent' } } }
168 is_expected.to contain_apt__setting('conf-proxy').with(ensure: 'absent',
173 context 'with lots of non-defaults' do
176 update: { 'frequency' => 'always', 'timeout' => 1, 'tries' => 3 },
177 purge: { 'sources.list' => false, 'sources.list.d' => false,
178 'preferences' => false, 'preferences.d' => false,
179 'apt.conf.d' => false },
184 is_expected.to contain_file('sources.list').with(content: nil)
188 is_expected.to contain_file('sources.list.d').with(purge: false,
193 is_expected.to contain_file('preferences').with(ensure: 'file')
197 is_expected.to contain_file('preferences.d').with(purge: false,
202 is_expected.to contain_file('apt.conf.d').with(purge: false,
207 is_expected.to contain_exec('apt_update').with(refreshonly: false,
213 context 'with lots of non-defaults' do
216 update: { 'frequency' => 'always', 'timeout' => 1, 'tries' => 3 },
217 purge: { 'sources.list' => true, 'sources.list.d' => true,
218 'preferences' => true, 'preferences.d' => true,
219 'apt.conf.d' => true },
224 is_expected.to contain_file('sources.list').with(content: "# Repos managed by puppet.\n")
228 is_expected.to contain_file('sources.list.d').with(purge: true,
233 is_expected.to contain_file('preferences').with(ensure: 'absent')
237 is_expected.to contain_file('preferences.d').with(purge: true,
242 is_expected.to contain_file('apt.conf.d').with(purge: true,
247 is_expected.to contain_exec('apt_update').with(refreshonly: false,
253 context 'with defaults for sources_list_force' do
256 update: { 'frequency' => 'always', 'timeout' => 1, 'tries' => 3 },
257 purge: { 'sources.list' => true },
258 sources_list_force: false,
263 is_expected.to contain_file('sources.list').with(content: "# Repos managed by puppet.\n")
267 context 'with non defaults for sources_list_force' do
270 update: { 'frequency' => 'always', 'timeout' => 1, 'tries' => 3 },
271 purge: { 'sources.list' => true },
272 sources_list_force: true,
277 is_expected.to contain_file('sources.list').with(ensure: 'absent')
281 context 'with entries for /etc/apt/auth.conf' do
383 facts_hash.each do |os, facts|
384 context "on #{os}" do
392 machine: 'deb.example.net',
397 machine: 'apt.example.com',
399 password: 'supersecret',
405 context 'with manage_auth_conf => true' do
407 super().merge(manage_auth_conf: true)
410 # Going forward starting with Ubuntu 16.04 and Debian 9.0
411 # /etc/apt/auth.conf is owned by _apt. In previous versions it is
413 auth_conf_owner = case os
414 when 'Ubuntu 14.04', 'Debian 7.0', 'Debian 8.0'
420 auth_conf_content = "// This file is managed by Puppet. DO NOT EDIT.
421 machine deb.example.net login foologin password secret
422 machine apt.example.com login aptlogin password supersecret
426 is_expected.to contain_file('/etc/apt/auth.conf').with(ensure: 'present',
427 owner: auth_conf_owner,
430 notify: 'Class[Apt::Update]',
431 content: sensitive(auth_conf_content))
435 context 'with manage_auth_conf => false' do
437 super().merge(manage_auth_conf: false)
441 is_expected.not_to contain_file('/etc/apt/auth.conf')
446 context 'with improperly specified entries for /etc/apt/auth.conf' do
451 machinn: 'deb.example.net',
452 username: 'foologin',
456 machine: 'apt.example.com',
458 password: 'supersecret',
464 it { is_expected.to raise_error(Puppet::Error) }
469 context 'with sources defined on valid os.family' do
488 'debian_unstable' => {
489 'location' => 'http://debian.mirror.iweb.ca/debian/',
490 'release' => 'unstable',
491 'repos' => 'main contrib non-free',
492 'key' => { 'id' => '150C8614919D8446E01E83AF9AA38DCD55BE302B', 'server' => 'subkeys.pgp.net' },
494 'include' => { 'src' => true },
497 'location' => 'http://apt.puppetlabs.com',
499 'key' => { 'id' => '6F6B15509CF8E59E6E469F327F438280EF8D349F', 'server' => 'pgp.mit.edu' },
505 is_expected.to contain_apt__setting('list-debian_unstable').with(ensure: 'present')
508 it { is_expected.to contain_file('/etc/apt/sources.list.d/debian_unstable.list').with_content(%r{^deb http://debian.mirror.iweb.ca/debian/ unstable main contrib non-free$}) }
509 it { is_expected.to contain_file('/etc/apt/sources.list.d/debian_unstable.list').with_content(%r{^deb-src http://debian.mirror.iweb.ca/debian/ unstable main contrib non-free$}) }
512 is_expected.to contain_apt__setting('list-puppetlabs').with(ensure: 'present')
515 it { is_expected.to contain_file('/etc/apt/sources.list.d/puppetlabs.list').with_content(%r{^deb http://apt.puppetlabs.com xenial main$}) }
518 context 'with confs defined on valid os.family' do
547 is_expected.to contain_apt__conf('foo').with(content: 'foo')
551 is_expected.to contain_apt__conf('bar').with(content: 'bar')
555 context 'with keys defined on valid os.family' do
575 'server' => 'subkeys.pgp.net',
578 'server' => 'pgp.mit.edu',
584 is_expected.to contain_apt__key('55BE302B').with(server: 'subkeys.pgp.net')
588 is_expected.to contain_apt__key('EF8D349F').with(server: 'pgp.mit.edu')
592 context 'with ppas defined on valid os.family' do
611 'ppa:drizzle-developers/ppa' => {},
612 'ppa:nginx/stable' => {},
616 it { is_expected.to contain_apt__ppa('ppa:drizzle-developers/ppa') }
617 it { is_expected.to contain_apt__ppa('ppa:nginx/stable') }
620 context 'with settings defined on valid os.family' do
639 'conf-banana' => { 'content' => 'banana' },
640 'pref-banana' => { 'content' => 'banana' },
644 it { is_expected.to contain_apt__setting('conf-banana') }
645 it { is_expected.to contain_apt__setting('pref-banana') }
648 context 'with pins defined on valid os.family' do
667 'stable' => { 'priority' => 600, 'order' => 50 },
668 'testing' => { 'priority' => 700, 'order' => 100 },
672 it { is_expected.to contain_apt__pin('stable') }
673 it { is_expected.to contain_apt__pin('testing') }
676 describe 'failing tests' do
677 context "with purge['sources.list']=>'banana'" do
678 let(:params) { { purge: { 'sources.list' => 'banana' } } }
681 is_expected.to raise_error(Puppet::Error)
685 context "with purge['sources.list.d']=>'banana'" do
686 let(:params) { { purge: { 'sources.list.d' => 'banana' } } }
689 is_expected.to raise_error(Puppet::Error)
693 context "with purge['preferences']=>'banana'" do
694 let(:params) { { purge: { 'preferences' => 'banana' } } }
697 is_expected.to raise_error(Puppet::Error)
701 context "with purge['preferences.d']=>'banana'" do
702 let(:params) { { purge: { 'preferences.d' => 'banana' } } }
705 is_expected.to raise_error(Puppet::Error)
709 context "with purge['apt.conf.d']=>'banana'" do
710 let(:params) { { purge: { 'apt.conf.d' => 'banana' } } }
713 is_expected.to raise_error(Puppet::Error)