+ it {
+ is_expected.to contain_file('sources.list').with(ensure: 'absent')
+ }
+ end
+
+ context 'with entries for /etc/apt/auth.conf' do
+ facts_hash = {
+ 'Ubuntu 14.04' => {
+ os: {
+ family: 'Debian',
+ name: 'Ubuntu',
+ release: {
+ major: '14',
+ full: '14.04',
+ },
+ distro: {
+ codename: 'trusty',
+ id: 'Ubuntu',
+ },
+ },
+ },
+ 'Ubuntu 16.04' => {
+ os: {
+ family: 'Debian',
+ name: 'Ubuntu',
+ release: {
+ major: '16',
+ full: '16.04',
+ },
+ distro: {
+ codename: 'xenial',
+ id: 'Ubuntu',
+ },
+ },
+ },
+ 'Ubuntu 18.04' => {
+ os: {
+ family: 'Debian',
+ name: 'Ubuntu',
+ release: {
+ major: '18',
+ full: '18.04',
+ },
+ distro: {
+ codename: 'bionic',
+ id: 'Ubuntu',
+ },
+ },
+ },
+ 'Debian 7.0' => {
+ os: {
+ family: 'Debian',
+ name: 'Debian',
+ release: {
+ major: '7',
+ full: '7.0',
+ },
+ distro: {
+ codename: 'wheezy',
+ id: 'Debian',
+ },
+ },
+ },
+ 'Debian 8.0' => {
+ os: {
+ family: 'Debian',
+ name: 'Debian',
+ release: {
+ major: '8',
+ full: '8.0',
+ },
+ distro: {
+ codename: 'jessie',
+ id: 'Debian',
+ },
+ },
+ },
+ 'Debian 9.0' => {
+ os: {
+ family: 'Debian',
+ name: 'Debian',
+ release: {
+ major: '9',
+ full: '9.0',
+ },
+ distro: {
+ codename: 'stretch',
+ id: 'Debian',
+ },
+ },
+ },
+ 'Debian 10.0' => {
+ os: {
+ family: 'Debian',
+ name: 'Debian',
+ release: {
+ major: '10',
+ full: '10.0',
+ },
+ distro: {
+ codename: 'buster',
+ id: 'Debian',
+ },
+ },
+ },
+ }
+
+ facts_hash.each do |os, facts|
+ context "on #{os}" do
+ let(:facts) do
+ facts
+ end
+ let(:params) do
+ {
+ auth_conf_entries: [
+ {
+ machine: 'deb.example.net',
+ login: 'foologin',
+ password: 'secret',
+ },
+ {
+ machine: 'apt.example.com',
+ login: 'aptlogin',
+ password: 'supersecret',
+ },
+ ],
+ }
+ end
+
+ context 'with manage_auth_conf => true' do
+ let(:params) do
+ super().merge(manage_auth_conf: true)
+ end
+
+ # Going forward starting with Ubuntu 16.04 and Debian 9.0
+ # /etc/apt/auth.conf is owned by _apt. In previous versions it is
+ # root.
+ auth_conf_owner = case os
+ when 'Ubuntu 14.04', 'Debian 7.0', 'Debian 8.0'
+ 'root'
+ else
+ '_apt'
+ end
+
+ auth_conf_content = "// This file is managed by Puppet. DO NOT EDIT.
+machine deb.example.net login foologin password secret
+machine apt.example.com login aptlogin password supersecret
+"
+
+ it {
+ is_expected.to contain_file('/etc/apt/auth.conf').with(ensure: 'present',
+ owner: auth_conf_owner,
+ group: 'root',
+ mode: '0600',
+ notify: 'Class[Apt::Update]',
+ content: sensitive(auth_conf_content))
+ }
+ end
+
+ context 'with manage_auth_conf => false' do
+ let(:params) do
+ super().merge(manage_auth_conf: false)
+ end
+
+ it {
+ is_expected.not_to contain_file('/etc/apt/auth.conf')
+ }
+ end
+ end
+
+ context 'with improperly specified entries for /etc/apt/auth.conf' do
+ let(:params) do
+ {
+ auth_conf_entries: [
+ {
+ machinn: 'deb.example.net',
+ username: 'foologin',
+ password: 'secret',
+ },
+ {
+ machine: 'apt.example.com',
+ login: 'aptlogin',
+ password: 'supersecret',
+ },
+ ],
+ }
+ end
+
+ it { is_expected.to raise_error(Puppet::Error) }
+ end
+ end