Skip to content

Commit a63d472

Browse files
Copilotdamacus
authored andcommitted
Add integration tests for multiple pg_ident mappings per map name
Co-authored-by: damacus <40786+damacus@users.noreply.github.com>
1 parent 6f6fc74 commit a63d472

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

test/cookbooks/test/recipes/ident.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,27 @@
3636
notifies :reload, 'postgresql_service[postgresql]', :delayed
3737
end
3838

39+
# Test the fix for issue #787 - multiple mappings per map name
40+
postgresql_ident 'someuser to postgres mapping' do
41+
map_name 'someuser_postgres'
42+
system_username 'someuser'
43+
database_username 'postgres'
44+
comment 'Test mapping for issue #787'
45+
46+
notifies :reload, 'postgresql_service[postgresql]', :delayed
47+
end
48+
49+
# Make sure that the postgres keeps its own identity
50+
# Without this, the cookbook would previously fail to run
51+
postgresql_ident 'postgres to postgres mapping' do
52+
map_name 'someuser_postgres'
53+
system_username 'postgres'
54+
database_username 'postgres'
55+
comment 'Second mapping with same map_name for issue #787'
56+
57+
notifies :reload, 'postgresql_service[postgresql]', :delayed
58+
end
59+
3960
postgresql_ident 'shef remove mapping' do
4061
map_name 'testmap3'
4162
system_username 'shef_remove'
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
control 'postgresql-ident-map' do
2+
impact 1.0
3+
desc 'This test ensures postgres configures ident access correctly'
4+
5+
describe command("sudo -u shef bash -c \"psql -U sous_chef -d postgres -c 'SELECT 1;'\"") do
6+
its('exit_status') { should eq 0 }
7+
end
8+
end
9+
10+
control 'postgresql-ident-multiple-mappings' do
11+
impact 1.0
12+
desc 'This test ensures multiple mappings per map name work correctly (issue #787)'
13+
14+
# Use a command to find and check the pg_ident.conf file
15+
describe command("find /etc /var -name 'pg_ident.conf' 2>/dev/null | head -1 | xargs cat") do
16+
its('stdout') { should match(/^someuser_postgres\s+someuser\s+postgres/) }
17+
its('stdout') { should match(/^someuser_postgres\s+postgres\s+postgres/) }
18+
end
19+
end
20+
21+
control 'shef and postgres roles should exist' do
22+
impact 1.0
23+
desc 'The shef & postgres database user role should exist'
24+
25+
postgres_access = postgres_session('postgres', '12345', '127.0.0.1')
26+
27+
describe postgres_access.query('SELECT rolname FROM pg_roles;') do
28+
its('output') { should include 'postgres' }
29+
its('output') { should include 'sous_chef' }
30+
end
31+
end

0 commit comments

Comments
 (0)