@@ -2,7 +2,7 @@ use crate::{
2
2
bson:: { doc, Document } ,
3
3
client:: options:: ServerApi ,
4
4
cmap:: { Command , Connection , RawCommandResponse } ,
5
- error:: Result ,
5
+ error:: { Error , Result } ,
6
6
options:: Credential ,
7
7
} ;
8
8
@@ -51,10 +51,23 @@ pub(super) async fn authenticate_stream(
51
51
server_api : Option < & ServerApi > ,
52
52
server_first : impl Into < Option < Document > > ,
53
53
) -> Result < ( ) > {
54
- if server_first. into ( ) . is_none ( ) {
55
- send_client_first ( conn, credential, server_api)
54
+ let server_response = match server_first. into ( ) {
55
+ Some ( server_first) => server_first,
56
+ None => send_client_first ( conn, credential, server_api)
56
57
. await ?
57
- . auth_response_body ( "MONGODB-X509" ) ?;
58
+ . auth_response_body ( "MONGODB-X509" ) ?,
59
+ } ;
60
+
61
+ if server_response
62
+ . get ( "ok" )
63
+ . and_then ( crate :: bson_util:: get_int)
64
+ != Some ( 1 )
65
+ && server_response. get_str ( "dbname" ) != Ok ( "$external" )
66
+ {
67
+ return Err ( Error :: authentication_error (
68
+ "MONGODB-X509" ,
69
+ "Authentication failed" ,
70
+ ) ) ;
58
71
}
59
72
60
73
Ok ( ( ) )
0 commit comments