Skip to content

Commit 53105f4

Browse files
committed
Allow adding in other special characters in the password
This mainly pertains to single quotes, but the test includes others as well.
1 parent 45026a0 commit 53105f4

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

spec/acceptance/server_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class { 'mongodb::globals':
184184
handle_creds => true,
185185
store_creds => true,
186186
admin_username => 'admin',
187-
admin_password => 'admin_\\_password',
187+
admin_password => 'admin_\\_'_"_&_password',
188188
restart => true,
189189
}
190190
class { 'mongodb::client': }
@@ -220,7 +220,7 @@ class { 'mongodb::client': }
220220
it { is_expected.to be_owned_by 'root' }
221221
it { is_expected.to be_grouped_into 'root' }
222222
it { is_expected.to be_mode 600 }
223-
it { is_expected.to contain 'admin.auth(\'admin\', \'admin_\\\\_password\')' }
223+
it { is_expected.to contain 'admin.auth(\'admin\', \'admin_\\\\_\\\'_"_&_password\')' }
224224
end
225225

226226
describe command("mongosh admin --quiet --eval \"load('/root/.mongoshrc.js');EJSON.stringify(db.getUser('admin')['customData'])\"") do

spec/classes/server_spec.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -453,19 +453,19 @@
453453
with_content(%r{admin\.auth\('admin', 'password'\)})
454454
}
455455

456-
context 'with backslash in password' do
456+
context 'with complex password' do
457457
let :params do
458458
{
459459
admin_username: 'admin',
460-
admin_password: 'password_\_with_backslash',
460+
admin_password: 'complex_\\_\'_"_&_password',
461461
auth: true,
462462
store_creds: true
463463
}
464464
end
465465

466466
it {
467467
is_expected.to contain_file('/root/.mongoshrc.js').
468-
with_content(%r{admin\.auth\('admin', 'password_\\\\_with_backslash'\)})
468+
with_content(%r{admin\.auth\('admin', 'complex_\\\\_\\'_"_&_password'\)})
469469
}
470470
end
471471
end

templates/mongoshrc.js.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ if (authRequired()) {
3434
<%- end -%>
3535
try {
3636
admin = db.getSiblingDB('admin')
37-
admin.auth('<%= @admin_username %>', '<%= @admin_password_unsensitive.gsub('\\','\\\\\\\\') %>')
37+
admin.auth('<%= @admin_username %>', '<%= @admin_password_unsensitive.gsub('\\','\\\\\\\\').gsub("'","\\\\'") %>')
3838
}
3939
catch (err) {
4040
// Silently ignore this error, we can't really do anything about it.

0 commit comments

Comments
 (0)