Skip to content

Commit 4dd6fc7

Browse files
committed
allow ok or dbname
1 parent a89fecb commit 4dd6fc7

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/client/auth/x509.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::{
22
bson::{doc, Document},
33
client::options::ServerApi,
44
cmap::{Command, Connection, RawCommandResponse},
5-
error::Result,
5+
error::{Error, Result},
66
options::Credential,
77
};
88

@@ -51,10 +51,23 @@ pub(super) async fn authenticate_stream(
5151
server_api: Option<&ServerApi>,
5252
server_first: impl Into<Option<Document>>,
5353
) -> 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)
5657
.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+
));
5871
}
5972

6073
Ok(())

0 commit comments

Comments
 (0)