Skip to content

Commit

Permalink
Add an acceptance test with a backslash in the password
Browse files Browse the repository at this point in the history
This test also lets the server class create the admin user, this
abbreviates the test code a bit and increases the coverage of the
acceptance test.

Note that the explicit ordering of client and server was dropped.
  • Loading branch information
stevenpost committed May 6, 2024
1 parent 0428248 commit 45026a0
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions spec/acceptance/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,24 @@ class { 'mongodb::globals':
end

describe 'installation using authentication' do
after :all do
pp = <<-EOS
class { 'mongodb::globals':
#{repo_ver_param}
}
-> class { 'mongodb::server':
ensure => absent,
package_ensure => purged,
service_ensure => stopped
}
-> class { 'mongodb::client':
ensure => purged
}
EOS

apply_manifest(pp, catch_failures: true)
end

it 'works with no errors' do
pp = <<-EOS
class { 'mongodb::globals':
Expand Down Expand Up @@ -154,6 +172,67 @@ class { 'mongodb::globals':
end
end

describe 'installation using authentication with complex password' do
it 'works with no errors' do
pp = <<-EOS
class { 'mongodb::globals':
#{repo_ver_param}
}
-> class { 'mongodb::server':
auth => true,
create_admin => true,
handle_creds => true,
store_creds => true,
admin_username => 'admin',
admin_password => 'admin_\\_password',
restart => true,
}
class { 'mongodb::client': }
EOS

apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
end

describe package(package_name) do
it { is_expected.to be_installed }
end

describe file(config_file) do
it { is_expected.to be_file }
end

describe service(service_name) do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end

describe port(27_017) do
it { is_expected.to be_listening }
end

describe command('mongosh --quiet --eval "db.serverCmdLineOpts().ok"') do
its(:stderr) { is_expected.to match %r{requires authentication} }
end

describe file('/root/.mongoshrc.js') do
it { is_expected.to be_file }
it { is_expected.to be_owned_by 'root' }
it { is_expected.to be_grouped_into 'root' }
it { is_expected.to be_mode 600 }
it { is_expected.to contain 'admin.auth(\'admin\', \'admin_\\\\_password\')' }
end

describe command("mongosh admin --quiet --eval \"load('/root/.mongoshrc.js');EJSON.stringify(db.getUser('admin')['customData'])\"") do
its(:exit_status) { is_expected.to eq 0 }
its(:stdout) { is_expected.to match "{\"createdBy\":\"Puppet Mongodb_user['User admin on db admin']\"}\n" }
end

describe command('mongod --version') do
its(:exit_status) { is_expected.to eq 0 }
end
end

describe 'uninstallation' do
it 'uninstalls mongodb' do
pp = <<-EOS
Expand Down

0 comments on commit 45026a0

Please sign in to comment.