Skip to content

Commit d9a21db

Browse files
ianballouekohl
authored andcommitted
Refs #37325 - use lest to hide default DB password
1 parent df5fd95 commit d9a21db

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

manifests/plugin/container_gateway.pp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
Optional[Stdlib::Port] $postgresql_port = undef,
4545
String $postgresql_database = 'container_gateway',
4646
String $postgresql_user = pick($foreman_proxy::globals::user, 'foreman-proxy'),
47-
String $postgresql_password = extlib::cache_data('container_gateway_cache_data', 'db_password', extlib::random_password(32))
47+
Optional[String] $postgresql_password = undef
4848
) {
4949
foreman_proxy::plugin::module { 'container_gateway':
5050
version => $version,
@@ -60,7 +60,9 @@
6060
user => $foreman_proxy::plugin::container_gateway::postgresql_user,
6161
password => postgresql::postgresql_password(
6262
$foreman_proxy::plugin::container_gateway::postgresql_user,
63-
$foreman_proxy::plugin::container_gateway::postgresql_password
63+
$foreman_proxy::plugin::container_gateway::postgresql_password.lest || {
64+
extlib::cache_data('container_gateway_cache_data', 'db_password', extlib::random_password(32))
65+
}
6466
),
6567
encoding => 'utf8',
6668
locale => 'C.utf8',

spec/classes/foreman_proxy__plugin__container_gateway_spec.rb

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,41 @@
99
describe 'with default settings' do
1010
it { should contain_foreman_proxy__plugin__module('container_gateway') }
1111
it 'container_gateway.yml should contain the correct configuration' do
12-
expect(get_content(catalogue, '/etc/foreman-proxy/settings.d/container_gateway.yml')).to include("---")
13-
expect(get_content(catalogue, '/etc/foreman-proxy/settings.d/container_gateway.yml')).to include(":enabled: https")
14-
expect(get_content(catalogue, '/etc/foreman-proxy/settings.d/container_gateway.yml')).to include(":pulp_endpoint: https://#{facts[:fqdn]}")
15-
expect(get_content(catalogue, '/etc/foreman-proxy/settings.d/container_gateway.yml')).to include(":sqlite_db_path: /var/lib/foreman-proxy/smart_proxy_container_gateway.db")
16-
connection_string = get_content(catalogue, '/etc/foreman-proxy/settings.d/container_gateway.yml').find { |str| str.include?("db_connection_string") }
17-
expect(connection_string.split(/[:@\/]/)[6]).to be_a(String).and have_attributes(length: 32)
12+
verify_exact_contents(catalogue, '/etc/foreman-proxy/settings.d/container_gateway.yml', [
13+
'---',
14+
':enabled: https',
15+
":pulp_endpoint: https://#{facts[:fqdn]}",
16+
':sqlite_db_path: /var/lib/foreman-proxy/smart_proxy_container_gateway.db',
17+
':db_connection_string: postgres://foreman-proxy:@:/container_gateway'
18+
])
19+
end
20+
end
21+
22+
describe 'with overwritten postgres parameters' do
23+
let :params do {
24+
:pulp_endpoint => 'https://test.example.com',
25+
:sqlite_db_path => '/dev/null.db',
26+
:database_backend => 'postgres',
27+
:postgresql_host => 'test.example.com',
28+
:postgresql_port => 5432,
29+
:postgresql_database => 'container_gateway',
30+
:postgresql_user => 'foreman-proxy',
31+
:postgresql_password => 'changeme'
32+
} end
33+
34+
it 'container_gateway.yml should contain the correct configuration' do
35+
verify_exact_contents(catalogue, '/etc/foreman-proxy/settings.d/container_gateway.yml', [
36+
'---',
37+
':enabled: https',
38+
':pulp_endpoint: https://test.example.com',
39+
':sqlite_db_path: /dev/null.db',
40+
':sqlite_timeout: 12345',
41+
':db_connection_string: postgres://foreman-proxy:[email protected]:5432/container_gateway'
42+
])
1843
end
1944
end
2045

21-
describe 'with overwritten parameters' do
46+
describe 'with overwritten sqlite parameters' do
2247
let :params do {
2348
:pulp_endpoint => 'https://test.example.com',
2449
:sqlite_db_path => '/dev/null.db',

0 commit comments

Comments
 (0)