@@ -11,17 +11,21 @@ defmodule Mongo.Auth.CR do
11
11
do: nonce ( message , username , password , s )
12
12
end
13
13
14
- defp nonce ( % { "nonce" => nonce , "ok" => ok } , username , password , s )
15
- # to support a response that returns 1 or 1.0
16
- when ok == 1 do
14
+ # Note that we use numeric comparisons in guards (e.g., `... when ok == 1`)
15
+ # instead of pattern matching below. This is to accommodate responses that
16
+ # return either integer or float values. Pattern matching treats 1 and 1.0,
17
+ # and 0, 0.0 and -0.0 (OTP 27+), as distinct values due to their different
18
+ # types/internal representation. By using numeric comparisons, we can ensure
19
+ # correct behavior regardless of the numeric type returned.
20
+ defp nonce ( % { "nonce" => nonce , "ok" => ok } , username , password , s ) when ok == 1 do
17
21
digest = Utils . digest ( nonce , username , password )
18
22
command = [ authenticate: 1 , user: username , nonce: nonce , key: digest ]
19
23
20
24
case Utils . command ( - 3 , command , s ) do
21
25
{ :ok , _flags , % { "ok" => ok } } when ok == 1 ->
22
26
:ok
23
27
24
- { :ok , _flags , % { "ok" => 0.0 , "errmsg" => reason , "code" => code } } ->
28
+ { :ok , _flags , % { "ok" => ok , "errmsg" => reason , "code" => code } } when ok == 0 ->
25
29
{ :error , Mongo.Error . exception ( message: "auth failed for '#{ username } ': #{ reason } " , code: code ) }
26
30
27
31
{ :ok , _flags , nil } ->
0 commit comments