From 53b5974aa08f004482eea201ab69bbdc62822d01 Mon Sep 17 00:00:00 2001 From: Steven POST Date: Mon, 6 May 2024 12:15:42 +0200 Subject: [PATCH] Allow adding in other special characters in the password This mainly pertains to single quotes, but the test includes others as well. --- spec/acceptance/server_spec.rb | 4 ++-- spec/classes/server_spec.rb | 6 +++--- templates/mongoshrc.js.erb | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/acceptance/server_spec.rb b/spec/acceptance/server_spec.rb index 5f6f4897..21536995 100644 --- a/spec/acceptance/server_spec.rb +++ b/spec/acceptance/server_spec.rb @@ -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': } @@ -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 diff --git a/spec/classes/server_spec.rb b/spec/classes/server_spec.rb index 229a8681..b0234395 100644 --- a/spec/classes/server_spec.rb +++ b/spec/classes/server_spec.rb @@ -453,11 +453,11 @@ 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 } @@ -465,7 +465,7 @@ 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 diff --git a/templates/mongoshrc.js.erb b/templates/mongoshrc.js.erb index fb8647e6..51f78411 100644 --- a/templates/mongoshrc.js.erb +++ b/templates/mongoshrc.js.erb @@ -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.