Skip to content

Commit 5f49c45

Browse files
committed
(MODULES-2683) fix version compare to properly suppress show_diff for root password
1 parent 6527a3a commit 5f49c45

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

manifests/server/root_password.pp

Lines changed: 1 addition & 1 deletion
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

Lines changed: 17 additions & 1 deletion
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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,20 @@
9090
describe 'when root_password set' do
9191
let(:params) {{:root_password => 'SET' }}
9292
it { is_expected.to contain_mysql_user('root@localhost') }
93-
it { is_expected.to contain_file('/root/.my.cnf').that_requires('Mysql_user[root@localhost]') }
93+
if Puppet.version.to_f >= 3.0
94+
it { is_expected.to contain_file('/root/.my.cnf').with(:show_diff => false).that_requires('Mysql_user[root@localhost]') }
95+
else
96+
it { is_expected.to contain_file('/root/.my.cnf').that_requires('Mysql_user[root@localhost]') }
97+
end
9498
end
9599
describe 'when root_password set, create_root_user set to false' do
96100
let(:params) {{ :root_password => 'SET', :create_root_user => false }}
97101
it { is_expected.not_to contain_mysql_user('root@localhost') }
98-
it { is_expected.to contain_file('/root/.my.cnf') }
102+
if Puppet.version.to_f >= 3.0
103+
it { is_expected.to contain_file('/root/.my.cnf').with(:show_diff => false) }
104+
else
105+
it { is_expected.to contain_file('/root/.my.cnf') }
106+
end
99107
end
100108
describe 'when root_password set, create_root_my_cnf set to false' do
101109
let(:params) {{ :root_password => 'SET', :create_root_my_cnf => false }}

0 commit comments

Comments
 (0)