|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +case platform.family |
| 4 | +when 'redhat' |
| 5 | + repo_file = '/etc/yum.repos.d/pgdg13.repo' |
| 6 | + repo_url = 'https://download.postgresql.org/pub/repos/yum/13/redhat/rhel-$releasever-$basearch' |
| 7 | +when 'debian' |
| 8 | + # Inspec does not provide a `codename` matcher, so we add ours |
| 9 | + finger_codename = { |
| 10 | + 'ubuntu-18.04' => 'bionic', |
| 11 | + 'ubuntu-20.04' => 'focal', |
| 12 | + 'debian-9' => 'stretch', |
| 13 | + 'debian-10' => 'buster', |
| 14 | + 'debian-11' => 'bullseye' |
| 15 | + } |
| 16 | + codename = finger_codename[system.platform[:finger]] |
| 17 | + |
| 18 | + repo_keyring = '/usr/share/postgresql-common/pgdg/apt.postgresql.org.gpg' |
| 19 | + repo_file = '/etc/apt/sources.list.d/pgdg.list' |
| 20 | + # rubocop:disable Metrics/LineLength |
| 21 | + repo_url = "deb [signed-by=#{repo_keyring}] http://apt.postgresql.org/pub/repos/apt #{codename}-pgdg main" |
| 22 | + # rubocop:enable Metrics/LineLength |
| 23 | +end |
| 24 | + |
| 25 | +control 'Postgresql repository keyring' do |
| 26 | + title 'should be installed' |
| 27 | + |
| 28 | + only_if('Requirement for Debian family') do |
| 29 | + os.debian? |
| 30 | + end |
| 31 | + |
| 32 | + describe package('pgdg-keyring') do |
| 33 | + it { should be_installed } |
| 34 | + end |
| 35 | + |
| 36 | + describe file(repo_keyring) do |
| 37 | + it { should exist } |
| 38 | + it { should be_owned_by 'root' } |
| 39 | + it { should be_grouped_into 'root' } |
| 40 | + its('mode') { should cmp '0644' } |
| 41 | + end |
| 42 | +end |
| 43 | + |
| 44 | +control 'Postgresql repository' do |
| 45 | + impact 1 |
| 46 | + title 'should be configured' |
| 47 | + describe file(repo_file) do |
| 48 | + its('content') { should include repo_url } |
| 49 | + end |
| 50 | +end |
0 commit comments