File tree Expand file tree Collapse file tree 3 files changed +55
-2
lines changed Expand file tree Collapse file tree 3 files changed +55
-2
lines changed Original file line number Diff line number Diff line change @@ -151,6 +151,8 @@ def sasl_prepped_password
151151 # authorized for.
152152 # @option options [ String ] :user The user name.
153153 # @option options [ String ] :password The user's password.
154+ # @option options [ String ] :pwd Legacy option for the user's password.
155+ # If :password and :pwd are both specified, :password takes precedence.
154156 # @option options [ Symbol ] :auth_mech The authorization mechanism.
155157 # @option options [ Array<String>, Array<Hash> ] roles The user roles.
156158 # @option options [ String ] :client_key The user's client key cached from a previous
@@ -196,7 +198,11 @@ def initialize(options)
196198 #
197199 # @since 2.0.0
198200 def spec
199- { pwd : password , roles : roles }
201+ { roles : roles } . tap do |spec |
202+ if password
203+ spec [ :pwd ] = password
204+ end
205+ end
200206 end
201207
202208 private
Original file line number Diff line number Diff line change 22
33describe Mongo ::Auth ::User ::View do
44
5+ let ( :database ) { root_authorized_client . database }
6+
57 let ( :view ) do
6- described_class . new ( root_authorized_client . database )
8+ described_class . new ( database )
79 end
810
911 before do
1214
1315 describe '#create' do
1416
17+ context 'when password is not provided' do
18+
19+ let ( :database ) { root_authorized_client . use ( '$external' ) . database }
20+
21+ let ( :username ) { 'passwordless-user' }
22+
23+ let ( :response ) do
24+ view . create (
25+ username ,
26+ # https://stackoverflow.com/questions/55939832/mongodb-external-database-cannot-create-new-user-with-user-defined-role
27+ roles : [ { role : 'read' , db : 'admin' } ] ,
28+ )
29+ end
30+
31+ before do
32+ begin
33+ view . remove ( username )
34+ rescue Mongo ::Error ::OperationFailure
35+ # can be user not found, ignore
36+ end
37+ end
38+
39+ it 'creates the user' do
40+ view . info ( username ) . should == [ ]
41+
42+ lambda do
43+ response
44+ end . should_not raise_error
45+
46+ view . info ( username ) . first [ 'user' ] . should == username
47+ end
48+ end
49+
1550 context 'when a session is not used' do
1651
1752 let! ( :response ) do
Original file line number Diff line number Diff line change 284284 end
285285 end
286286 end
287+
288+ describe '#spec' do
289+ context 'when no password and no roles are set' do
290+ let ( :user ) do
291+ described_class . new ( user : 'foo' )
292+ end
293+
294+ it 'is a hash with empty roles' do
295+ user . spec . should == { roles : [ ] }
296+ end
297+ end
298+ end
287299end
You can’t perform that action at this time.
0 commit comments