Skip to content

Commit 87b7e4d

Browse files
committed
Merge pull request #766 from DavidS/modules-2683-fix-root-password-hiding
(MODULES-2683) fix version compare to properly suppress show_diff for…
2 parents 5e6db0b + 5f49c45 commit 87b7e4d

14 files changed

+763
-700
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ group :development, :unit_tests do
1414
gem 'rspec-core', '3.1.7', :require => false
1515
gem 'puppetlabs_spec_helper', :require => false
1616
gem 'simplecov', :require => false
17-
gem 'puppet_facts', :require => false
1817
gem 'json', :require => false
1918
gem 'metadata-json-lint', :require => false
19+
gem 'rspec-puppet-facts', :require => false
2020
end
2121

2222
group :system_tests do

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
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
require 'spec_helper'
22

33
describe 'mysql::server' do
4-
on_pe_unsupported_platforms.each do |pe_version,pe_platforms|
5-
pe_platforms.each do |pe_platform,facts|
6-
describe "on #{pe_version} #{pe_platform}" do
7-
let(:facts) { facts }
4+
context "on an unsupported OS" do
5+
# fetch any sets of facts to modify them
6+
os, facts = on_supported_os.first
87

9-
context 'should gracefully fail' do
10-
it { expect { is_expected.to compile}.to raise_error(Puppet::Error, /Unsupported platform:/) }
11-
end
12-
end
8+
let(:facts) {
9+
facts.merge({
10+
:osfamily => 'UNSUPPORTED',
11+
:operatingsystem => 'UNSUPPORTED',
12+
})
13+
}
14+
15+
it 'should gracefully fail' do
16+
is_expected.to compile.and_raise_error(/Unsupported platform:/)
1317
end
1418
end
1519
end

spec/classes/mycnf_template_spec.rb

Lines changed: 59 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2,76 +2,78 @@
22

33
describe 'mysql::server' do
44
context 'my.cnf template' do
5-
on_pe_supported_platforms(PLATFORMS).each do |pe_version,pe_platforms|
6-
pe_platforms.each do |pe_platform,facts|
7-
describe "on #{pe_version} #{pe_platform}" do
8-
let(:facts) { facts }
5+
on_supported_os.each do |os, facts|
6+
context "on #{os}" do
7+
let(:facts) {
8+
facts.merge({
9+
:root_home => '/root',
10+
})
11+
}
912

10-
context 'normal entry' do
11-
let(:params) {{ :override_options => { 'mysqld' => { 'socket' => '/var/lib/mysql/mysql.sock' } } }}
12-
it do
13-
is_expected.to contain_file('mysql-config-file').with({
14-
:mode => '0644',
15-
:selinux_ignore_defaults => true,
16-
}).with_content(/socket = \/var\/lib\/mysql\/mysql.sock/)
17-
end
18-
end
19-
20-
describe 'array entry' do
21-
let(:params) {{ :override_options => { 'mysqld' => { 'replicate-do-db' => ['base1', 'base2'], } }}}
22-
it do
23-
is_expected.to contain_file('mysql-config-file').with_content(
24-
/.*replicate-do-db = base1\nreplicate-do-db = base2.*/
25-
)
26-
end
13+
context 'normal entry' do
14+
let(:params) {{ :override_options => { 'mysqld' => { 'socket' => '/var/lib/mysql/mysql.sock' } } }}
15+
it do
16+
is_expected.to contain_file('mysql-config-file').with({
17+
:mode => '0644',
18+
:selinux_ignore_defaults => true,
19+
}).with_content(/socket = \/var\/lib\/mysql\/mysql.sock/)
2720
end
21+
end
2822

29-
describe 'ssl set to true' do
30-
let(:params) {{ :override_options => { 'mysqld' => { 'ssl' => true }}}}
31-
it { is_expected.to contain_file('mysql-config-file').with_content(/ssl/) }
32-
it { is_expected.to contain_file('mysql-config-file').without_content(/ssl = true/) }
23+
describe 'array entry' do
24+
let(:params) {{ :override_options => { 'mysqld' => { 'replicate-do-db' => ['base1', 'base2'], } }}}
25+
it do
26+
is_expected.to contain_file('mysql-config-file').with_content(
27+
/.*replicate-do-db = base1\nreplicate-do-db = base2.*/
28+
)
3329
end
30+
end
3431

35-
describe 'ssl set to false' do
36-
let(:params) {{ :override_options => { 'mysqld' => { 'ssl' => false }}}}
37-
it { is_expected.to contain_file('mysql-config-file').with_content(/ssl = false/) }
38-
end
32+
describe 'ssl set to true' do
33+
let(:params) {{ :override_options => { 'mysqld' => { 'ssl' => true }}}}
34+
it { is_expected.to contain_file('mysql-config-file').with_content(/ssl/) }
35+
it { is_expected.to contain_file('mysql-config-file').without_content(/ssl = true/) }
36+
end
3937

40-
# ssl-disable (and ssl) are special cased within mysql.
41-
describe 'possibility of disabling ssl completely' do
42-
let(:params) {{ :override_options => { 'mysqld' => { 'ssl' => true, 'ssl-disable' => true }}}}
43-
it { is_expected.to contain_file('mysql-config-file').without_content(/ssl = true/) }
44-
end
38+
describe 'ssl set to false' do
39+
let(:params) {{ :override_options => { 'mysqld' => { 'ssl' => false }}}}
40+
it { is_expected.to contain_file('mysql-config-file').with_content(/ssl = false/) }
41+
end
4542

46-
describe 'a non ssl option set to true' do
47-
let(:params) {{ :override_options => { 'mysqld' => { 'test' => true }}}}
48-
it { is_expected.to contain_file('mysql-config-file').with_content(/^test$/) }
49-
it { is_expected.to contain_file('mysql-config-file').without_content(/test = true/) }
50-
end
43+
# ssl-disable (and ssl) are special cased within mysql.
44+
describe 'possibility of disabling ssl completely' do
45+
let(:params) {{ :override_options => { 'mysqld' => { 'ssl' => true, 'ssl-disable' => true }}}}
46+
it { is_expected.to contain_file('mysql-config-file').without_content(/ssl = true/) }
47+
end
5148

52-
context 'with includedir' do
53-
let(:params) {{ :includedir => '/etc/my.cnf.d' }}
54-
it 'makes the directory' do
55-
is_expected.to contain_file('/etc/my.cnf.d').with({
56-
:ensure => :directory,
57-
:mode => '0755',
58-
})
59-
end
49+
describe 'a non ssl option set to true' do
50+
let(:params) {{ :override_options => { 'mysqld' => { 'test' => true }}}}
51+
it { is_expected.to contain_file('mysql-config-file').with_content(/^test$/) }
52+
it { is_expected.to contain_file('mysql-config-file').without_content(/test = true/) }
53+
end
6054

61-
it { is_expected.to contain_file('mysql-config-file').with_content(/!includedir/) }
55+
context 'with includedir' do
56+
let(:params) {{ :includedir => '/etc/my.cnf.d' }}
57+
it 'makes the directory' do
58+
is_expected.to contain_file('/etc/my.cnf.d').with({
59+
:ensure => :directory,
60+
:mode => '0755',
61+
})
6262
end
6363

64-
context 'without includedir' do
65-
let(:params) {{ :includedir => '' }}
66-
it 'shouldnt contain the directory' do
67-
is_expected.not_to contain_file('mysql-config-file').with({
68-
:ensure => :directory,
69-
:mode => '0755',
70-
})
71-
end
64+
it { is_expected.to contain_file('mysql-config-file').with_content(/!includedir/) }
65+
end
7266

73-
it { is_expected.to contain_file('mysql-config-file').without_content(/!includedir/) }
67+
context 'without includedir' do
68+
let(:params) {{ :includedir => '' }}
69+
it 'shouldnt contain the directory' do
70+
is_expected.not_to contain_file('mysql-config-file').with({
71+
:ensure => :directory,
72+
:mode => '0755',
73+
})
7474
end
75+
76+
it { is_expected.to contain_file('mysql-config-file').without_content(/!includedir/) }
7577
end
7678
end
7779
end

spec/classes/mysql_bindings_spec.rb

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
11
require 'spec_helper'
22

33
describe 'mysql::bindings' do
4-
on_pe_supported_platforms(PLATFORMS).each do |pe_version,pe_platforms|
5-
pe_platforms.each do |pe_platform,facts|
6-
describe "on #{pe_version} #{pe_platform}" do
7-
let(:facts) { facts }
4+
on_supported_os.each do |os, facts|
5+
context "on #{os}" do
6+
let(:facts) {
7+
facts.merge({
8+
:root_home => '/root',
9+
})
10+
}
811

9-
let(:params) {{
10-
'java_enable' => true,
11-
'perl_enable' => true,
12-
'php_enable' => true,
13-
'python_enable' => true,
14-
'ruby_enable' => true,
15-
'client_dev' => true,
16-
'daemon_dev' => true,
17-
'client_dev_package_name' => 'libmysqlclient-devel',
18-
'daemon_dev_package_name' => 'mysql-devel',
19-
}}
12+
let(:params) {{
13+
'java_enable' => true,
14+
'perl_enable' => true,
15+
'php_enable' => true,
16+
'python_enable' => true,
17+
'ruby_enable' => true,
18+
'client_dev' => true,
19+
'daemon_dev' => true,
20+
'client_dev_package_name' => 'libmysqlclient-devel',
21+
'daemon_dev_package_name' => 'mysql-devel',
22+
}}
2023

21-
it { is_expected.to contain_package('mysql-connector-java') }
22-
it { is_expected.to contain_package('perl_mysql') }
23-
it { is_expected.to contain_package('python-mysqldb') }
24-
it { is_expected.to contain_package('ruby_mysql') }
25-
it { is_expected.to contain_package('mysql-client_dev') }
26-
it { is_expected.to contain_package('mysql-daemon_dev') }
27-
end
24+
it { is_expected.to contain_package('mysql-connector-java') }
25+
it { is_expected.to contain_package('perl_mysql') }
26+
it { is_expected.to contain_package('python-mysqldb') }
27+
it { is_expected.to contain_package('ruby_mysql') }
28+
it { is_expected.to contain_package('mysql-client_dev') }
29+
it { is_expected.to contain_package('mysql-daemon_dev') }
2830
end
2931
end
3032
end

spec/classes/mysql_client_spec.rb

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,38 @@
11
require 'spec_helper'
22

33
describe 'mysql::client' do
4-
on_pe_supported_platforms(PLATFORMS).each do |pe_version,pe_platforms|
5-
pe_platforms.each do |pe_platform,facts|
6-
describe "on #{pe_version} #{pe_platform}" do
7-
let(:facts) { facts }
8-
9-
context 'with defaults' do
10-
it { is_expected.not_to contain_class('mysql::bindings') }
11-
it { is_expected.to contain_package('mysql_client') }
12-
end
13-
14-
context 'with bindings enabled' do
15-
let(:params) {{ :bindings_enable => true }}
4+
on_supported_os.each do |os, facts|
5+
context "on #{os}" do
6+
let(:facts) {
7+
facts.merge({
8+
:root_home => '/root',
9+
})
10+
}
11+
12+
context 'with defaults' do
13+
it { is_expected.not_to contain_class('mysql::bindings') }
14+
it { is_expected.to contain_package('mysql_client') }
15+
end
1616

17-
it { is_expected.to contain_class('mysql::bindings') }
18-
it { is_expected.to contain_package('mysql_client') }
19-
end
17+
context 'with bindings enabled' do
18+
let(:params) {{ :bindings_enable => true }}
2019

21-
context 'with package_manage set to true' do
22-
let(:params) {{ :package_manage => true }}
20+
it { is_expected.to contain_class('mysql::bindings') }
21+
it { is_expected.to contain_package('mysql_client') }
22+
end
2323

24-
it { is_expected.to contain_package('mysql_client') }
25-
end
24+
context 'with package_manage set to true' do
25+
let(:params) {{ :package_manage => true }}
2626

27-
context 'with package_manage set to false' do
28-
let(:params) {{ :package_manage => false }}
27+
it { is_expected.to contain_package('mysql_client') }
28+
end
2929

30-
it { is_expected.not_to contain_package('mysql_client') }
31-
end
30+
context 'with package_manage set to false' do
31+
let(:params) {{ :package_manage => false }}
3232

33+
it { is_expected.not_to contain_package('mysql_client') }
3334
end
35+
3436
end
3537
end
3638
end

spec/classes/mysql_server_account_security_spec.rb

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
require 'spec_helper'
22

33
describe 'mysql::server::account_security' do
4-
on_pe_supported_platforms(PLATFORMS).each do |pe_version,pe_platforms|
5-
pe_platforms.each do |pe_platform,facts|
6-
describe "on #{pe_version} #{pe_platform}" do
7-
let(:facts) { facts.merge({:fqdn => 'myhost.mydomain', :hostname => 'myhost'}) }
4+
on_supported_os.each do |os, facts|
5+
context "on #{os}" do
6+
context "with fqdn==myhost.mydomain" do
7+
let(:facts) {
8+
facts.merge({
9+
:root_home => '/root',
10+
:fqdn => 'myhost.mydomain',
11+
:hostname => 'myhost',
12+
})
13+
}
814

915
[ 'root@myhost.mydomain',
1016
'root@127.0.0.1',
@@ -32,8 +38,14 @@
3238
end
3339
end
3440

35-
describe "on #{pe_version} #{pe_platform} with fqdn==localhost" do
36-
let(:facts) { facts.merge({:fqdn => 'localhost', :hostname => 'localhost'}) }
41+
context "with fqdn==localhost" do
42+
let(:facts) {
43+
facts.merge({
44+
:root_home => '/root',
45+
:fqdn => 'localhost',
46+
:hostname => 'localhost',
47+
})
48+
}
3749

3850
[ 'root@127.0.0.1',
3951
'root@::1',
@@ -48,8 +60,14 @@
4860
end
4961
end
5062

51-
describe "on #{pe_version} #{pe_platform} with fqdn==localhost.localdomain" do
52-
let(:facts) { facts.merge({:fqdn => 'localhost.localdomain', :hostname => 'localhost'}) }
63+
context "with fqdn==localhost.localdomain" do
64+
let(:facts) {
65+
facts.merge({
66+
:root_home => '/root',
67+
:fqdn => 'localhost.localdomain',
68+
:hostname => 'localhost',
69+
})
70+
}
5371

5472
[ 'root@127.0.0.1',
5573
'root@::1',

0 commit comments

Comments
 (0)