Skip to content

Commit

Permalink
Allow adding in other special characters in the password
Browse files Browse the repository at this point in the history
This mainly pertains to single quotes, but the test includes others as
well.
  • Loading branch information
stevenpost committed May 6, 2024
1 parent 45026a0 commit 2ab8ca2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions spec/acceptance/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class { 'mongodb::globals':
handle_creds => true,
store_creds => true,
admin_username => 'admin',
admin_password => 'admin_\\_password',
admin_password => 'admin_\\\\_\\'_"_&_password',
restart => true,
}
class { 'mongodb::client': }
Expand Down Expand Up @@ -220,7 +220,7 @@ class { 'mongodb::client': }
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\')' }
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
Expand Down
6 changes: 3 additions & 3 deletions spec/classes/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -453,19 +453,19 @@
with_content(%r{admin\.auth\('admin', 'password'\)})
}

context 'with backslash in password' do
context 'with complex password' do
let :params do
{
admin_username: 'admin',
admin_password: 'password_\_with_backslash',
admin_password: 'complex_\\_\'_"_&_password',
auth: true,
store_creds: true
}
end

it {
is_expected.to contain_file('/root/.mongoshrc.js').
with_content(%r{admin\.auth\('admin', 'password_\\\\_with_backslash'\)})
with_content(%r{admin\.auth\('admin', 'complex_\\\\_\\'_"_&_password'\)})
}
end
end
Expand Down
2 changes: 1 addition & 1 deletion templates/mongoshrc.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ if (authRequired()) {
<%- end -%>
try {
admin = db.getSiblingDB('admin')
admin.auth('<%= @admin_username %>', '<%= @admin_password_unsensitive.gsub('\\','\\\\\\\\') %>')
admin.auth('<%= @admin_username %>', '<%= @admin_password_unsensitive.gsub('\\','\\\\\\\\').gsub("'","\\\\'") %>')
}
catch (err) {
// Silently ignore this error, we can't really do anything about it.
Expand Down

0 comments on commit 2ab8ca2

Please sign in to comment.