Skip to content

Commit 7bb258d

Browse files
committed
(MODULES-2683) fix version compare to properly suppress show_diff for root password
1 parent 2a86934 commit 7bb258d

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

manifests/server/root_password.pp

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
}
3636

3737
# show_diff was added with puppet 3.0
38-
if versioncmp($::puppetversion, '3.0') <= 0 {
38+
if versioncmp($::puppetversion, '3.0') >= 0 {
3939
File["${::root_home}/.my.cnf"] { show_diff => false }
4040
}
4141
if $mysql::server::create_root_user == true {

spec/acceptance/mysql_server_spec.rb

+17-1
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,21 @@ class { 'mysql::server':
6464
apply_manifest(pp, :catch_changes => true)
6565
end
6666
end
67-
end
6867

68+
describe 'when changing the password' do
69+
let(:password) { 'THE NEW SECRET' }
70+
let(:manifest) { "class { 'mysql::server': root_password => '#{password}' }" }
71+
72+
it 'should not display the password' do
73+
result = apply_manifest(manifest, :expect_changes => true)
74+
# this does not actually prove anything, as show_diff in the puppet config defaults to false.
75+
expect(result.stdout).not_to match /#{password}/
76+
end
77+
78+
it 'should be idempotent' do
79+
result = apply_manifest(manifest, :catch_changes => true)
80+
end
81+
82+
end
83+
84+
end

spec/classes/mysql_server_spec.rb

+11-3
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,20 @@
8787
describe 'when root_password set' do
8888
let(:params) {{:root_password => 'SET' }}
8989
it { is_expected.to contain_mysql_user('root@localhost') }
90-
it { is_expected.to contain_file('/root/.my.cnf').that_requires('Mysql_user[root@localhost]') }
90+
if Puppet.version.to_f >= 3.0
91+
it { is_expected.to contain_file('/root/.my.cnf').with(:show_diff => false).that_requires('Mysql_user[root@localhost]') }
92+
else
93+
it { is_expected.to contain_file('/root/.my.cnf').that_requires('Mysql_user[root@localhost]') }
94+
end
9195
end
9296
describe 'when root_password set, create_root_user set to false' do
9397
let(:params) {{ :root_password => 'SET', :create_root_user => false }}
9498
it { is_expected.not_to contain_mysql_user('root@localhost') }
95-
it { is_expected.to contain_file('/root/.my.cnf') }
99+
if Puppet.version.to_f >= 3.0
100+
it { is_expected.to contain_file('/root/.my.cnf').with(:show_diff => false) }
101+
else
102+
it { is_expected.to contain_file('/root/.my.cnf') }
103+
end
96104
end
97105
describe 'when root_password set, create_root_my_cnf set to false' do
98106
let(:params) {{ :root_password => 'SET', :create_root_my_cnf => false }}
@@ -112,7 +120,7 @@
112120
:onlyif => 'test -f /root/.mysql_secret'
113121
)
114122
}
115-
end
123+
end
116124
end
117125

118126
context 'mysql::server::providers' do

0 commit comments

Comments
 (0)