Skip to content

Commit c2d152e

Browse files
committed
Set correct auth_mechanism for updateUser
Currently the mongodb command `updateUser` defaults to SCRAM-SHA-256 but you can't update these passwords. And also show an error when the update goes wrong.
1 parent 60e16ce commit c2d152e

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/puppet/provider/mongodb_user/mongodb.rb

+7-2
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,15 @@ def password_hash=(_value)
101101
command = {
102102
updateUser: @resource[:username],
103103
pwd: @resource[:password_hash],
104-
digestPassword: false
104+
digestPassword: false,
105+
mechanisms: @resource[:auth_mechanism] == :scram_sha_1 ? ['SCRAM-SHA-1'] : ['SCRAM-SHA-256'],
105106
}
106107

107-
mongo_eval("db.runCommand(#{command.to_json})", @resource[:database])
108+
out = mongo_eval("db.runCommand(#{command.to_json})", @resource[:database])
109+
return if out.nil? # we do this to satisfy the rspec test as no real mongo command wil be executed
110+
111+
out = JSON.parse(out)
112+
raise "Failed update User password for user '#{@resource[:username]}'\n#{out}" if out['ok'].zero?
108113
else
109114
Puppet.warning 'User password operations are available only from master host'
110115
end

spec/unit/puppet/provider/mongodb_user/mongodb_spec.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@
9393
{
9494
"updateUser":"new_user",
9595
"pwd":"pass",
96-
"digestPassword":false
96+
"digestPassword":false,
97+
"mechanisms":["SCRAM-SHA-1"]
9798
}
9899
EOS
99100
allow(provider).to receive(:mongo_eval).

0 commit comments

Comments
 (0)