Skip to content

Commit 38da528

Browse files
committed
Unwrap sensitive values for testing
When testing, sensitive values can be compared to the String `Sensitive [value redacted]`, but if we want to check that the redacted content is the one we expect, we should compare with another Sensitive wrapper.
1 parent 795a202 commit 38da528

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

spec/defines/server/role_spec.rb

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@
2424

2525
it 'has create role for "test" user with password as ****' do
2626
expect(subject).to contain_postgresql_psql('CREATE ROLE test ENCRYPTED PASSWORD ****')
27-
.with('command' => 'Sensitive [value redacted]',
27+
.with('command' => sensitive(%(CREATE ROLE "test" ENCRYPTED PASSWORD 'new-pa$s' LOGIN NOCREATEROLE NOCREATEDB NOSUPERUSER CONNECTION LIMIT -1)),
2828
'sensitive' => 'true',
2929
'unless' => "SELECT 1 FROM pg_roles WHERE rolname = 'test'",
3030
'port' => '5432')
3131
end
3232

3333
it 'has alter role for "test" user with password as ****' do
3434
expect(subject).to contain_postgresql_psql('ALTER ROLE test ENCRYPTED PASSWORD ****')
35-
.with('command' => 'Sensitive [value redacted]',
35+
.with('command' => sensitive(%(ALTER ROLE "test" ENCRYPTED PASSWORD 'md5b6f7fcbbabb4befde4588a26c1cfd2fa')),
3636
'sensitive' => 'true',
37-
'unless' => 'Sensitive [value redacted]',
37+
'unless' => sensitive(%(SELECT 1 FROM pg_shadow WHERE usename = 'test' AND passwd = 'md5b6f7fcbbabb4befde4588a26c1cfd2fa')),
3838
'port' => '5432')
3939
end
4040
end
@@ -50,17 +50,19 @@
5050

5151
it 'has create role for "test" user with password as ****' do
5252
expect(subject).to contain_postgresql_psql('CREATE ROLE test ENCRYPTED PASSWORD ****')
53-
.with('command' => 'Sensitive [value redacted]',
53+
.with('command' => sensitive(%(CREATE ROLE "test" ENCRYPTED PASSWORD 'new-pa$s' LOGIN NOCREATEROLE NOCREATEDB NOSUPERUSER CONNECTION LIMIT -1)),
5454
'sensitive' => 'true',
5555
'unless' => "SELECT 1 FROM pg_roles WHERE rolname = 'test'",
5656
'port' => '5432')
5757
end
5858

5959
it 'has alter role for "test" user with password as ****' do
6060
expect(subject).to contain_postgresql_psql('ALTER ROLE test ENCRYPTED PASSWORD ****')
61-
.with('command' => 'Sensitive [value redacted]',
61+
.with('command' => sensitive(%(ALTER ROLE "test" ENCRYPTED PASSWORD 'Sensitive [value redacted]')),
62+
# FIXME: This is obviously wrong ^^^^^^^^^^^^^^^^^^^^^^^^^^
6263
'sensitive' => 'true',
63-
'unless' => 'Sensitive [value redacted]',
64+
'unless' => sensitive(%(SELECT 1 FROM pg_shadow WHERE usename = 'test' AND passwd = 'Sensitive [value redacted]')),
65+
# FIXME: This is obviously wrong ^^^^^^^^^^^^^^^^^^^^^^^^^^
6466
'port' => '5432')
6567
end
6668
end
@@ -84,7 +86,7 @@
8486

8587
it 'has create role for "test" user with password as ****' do
8688
expect(subject).to contain_postgresql_psql('CREATE ROLE test ENCRYPTED PASSWORD ****')
87-
.with_command('Sensitive [value redacted]')
89+
.with_command(sensitive(%(CREATE ROLE "test" ENCRYPTED PASSWORD 'new-pa$s' LOGIN NOCREATEROLE NOCREATEDB NOSUPERUSER CONNECTION LIMIT -1)))
8890
.with_sensitive('true')
8991
.with_unless("SELECT 1 FROM pg_roles WHERE rolname = 'test'")
9092
.with_port(5432)
@@ -94,8 +96,8 @@
9496

9597
it 'has alter role for "test" user with password as ****' do
9698
expect(subject).to contain_postgresql_psql('ALTER ROLE test ENCRYPTED PASSWORD ****')
97-
.with('command' => 'Sensitive [value redacted]', 'sensitive' => 'true',
98-
'unless' => 'Sensitive [value redacted]', 'port' => '5432',
99+
.with('command' => sensitive(%(ALTER ROLE "test" ENCRYPTED PASSWORD 'md5b6f7fcbbabb4befde4588a26c1cfd2fa')), 'sensitive' => 'true',
100+
'unless' => sensitive(%(SELECT 1 FROM pg_shadow WHERE usename = 'test' AND passwd = 'md5b6f7fcbbabb4befde4588a26c1cfd2fa')), 'port' => '5432',
99101
'connect_settings' => { 'PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1',
100102
'PGUSER' => 'login-user', 'PGPASSWORD' => 'login-pass' })
101103
end
@@ -121,16 +123,16 @@
121123

122124
it 'has create role for "test" user with password as ****' do
123125
expect(subject).to contain_postgresql_psql('CREATE ROLE test ENCRYPTED PASSWORD ****')
124-
.with('command' => 'Sensitive [value redacted]',
126+
.with('command' => sensitive(%(CREATE ROLE "test" ENCRYPTED PASSWORD 'new-pa$s' LOGIN NOCREATEROLE NOCREATEDB NOSUPERUSER CONNECTION LIMIT -1)),
125127
'sensitive' => 'true', 'unless' => "SELECT 1 FROM pg_roles WHERE rolname = 'test'",
126128
'connect_settings' => { 'PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1',
127129
'PGPORT' => '1234', 'PGUSER' => 'login-user', 'PGPASSWORD' => 'login-pass' })
128130
end
129131

130132
it 'has alter role for "test" user with password as ****' do
131133
expect(subject).to contain_postgresql_psql('ALTER ROLE test ENCRYPTED PASSWORD ****')
132-
.with('command' => 'Sensitive [value redacted]', 'sensitive' => 'true',
133-
'unless' => 'Sensitive [value redacted]',
134+
.with('command' => sensitive(%(ALTER ROLE "test" ENCRYPTED PASSWORD 'md5b6f7fcbbabb4befde4588a26c1cfd2fa')), 'sensitive' => 'true',
135+
'unless' => sensitive(%(SELECT 1 FROM pg_shadow WHERE usename = 'test' AND passwd = 'md5b6f7fcbbabb4befde4588a26c1cfd2fa')),
134136
'connect_settings' => { 'PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1',
135137
'PGPORT' => '1234', 'PGUSER' => 'login-user', 'PGPASSWORD' => 'login-pass' })
136138
end

0 commit comments

Comments
 (0)