-
Type: Improvement
-
Resolution: Done
-
Priority: Minor - P4
-
None
-
Affects Version/s: 2.4.1
-
Component/s: Auth
-
None
-
Environment:MRI 2.4.0
in `Mongo::Server::Connection#authenticate!`
there is a logical test that read as :
```
if options[:user] || options[:auth_mech]
...
end
```
That seems incorrect in case the .yml file has no :user entry but a :auth_mech is provided.
In that case, the Authenticate! could be called with a Nil for user and then code calling
@user.xxx will fails miserably.
It seems to me, that the mongoid.yml file sample, should point out, that in case of 'no security', the
`auth_mech` should not by set.
Or the logic test in code, should test as :
```
def authenticate!
if options[:user] || options[:auth_mech]
user = Auth::User.new(Options::Redacted.new(:auth_mech => default_mechanism).merge(options))
@server.handle_auth_failure! do
Auth.get(user).login(self)
end
end
end
```