1+ use crate :: {
2+ client:: {
3+ auth:: { oidc, AuthMechanism , Credential } ,
4+ options:: ClientOptions ,
5+ } ,
6+ test:: log_uncaptured,
7+ Client ,
8+ } ;
9+ use std:: sync:: { Arc , Mutex } ;
10+
11+ // Machine Callback tests
112// Prose test 1.1 Single Principal Implicit Username
213#[ tokio:: test]
3- async fn single_principal_implicit_username ( ) -> anyhow:: Result < ( ) > {
4- use crate :: {
5- client:: {
6- auth:: { oidc, AuthMechanism , Credential } ,
7- options:: ClientOptions ,
8- } ,
9- test:: log_uncaptured,
10- Client ,
11- } ;
14+ async fn machine_single_principal_implicit_username ( ) -> anyhow:: Result < ( ) > {
1215 use bson:: Document ;
1316 use futures_util:: FutureExt ;
1417
@@ -17,10 +20,16 @@ async fn single_principal_implicit_username() -> anyhow::Result<()> {
1720 return Ok ( ( ) ) ;
1821 }
1922
23+ // we need to assert that the callback is only called once
24+ let call_count = Arc :: new ( Mutex :: new ( 0 ) ) ;
25+ let cb_call_count = call_count. clone ( ) ;
26+
2027 let mut opts = ClientOptions :: parse ( "mongodb://localhost/?authMechanism=MONGODB-OIDC" ) . await ?;
2128 opts. credential = Credential :: builder ( )
2229 . mechanism ( AuthMechanism :: MongoDbOidc )
23- . oidc_callback ( oidc:: Callback :: machine ( |_| {
30+ . oidc_callback ( oidc:: Callback :: machine ( move |_| {
31+ let call_count = cb_call_count. clone ( ) ;
32+ * call_count. lock ( ) . unwrap ( ) += 1 ;
2433 async move {
2534 Ok ( oidc:: IdpServerResponse {
2635 access_token : tokio:: fs:: read_to_string ( "/tmp/tokens/test_user1" ) . await ?,
@@ -38,14 +47,14 @@ async fn single_principal_implicit_username() -> anyhow::Result<()> {
3847 . collection :: < Document > ( "test" )
3948 . find_one ( None , None )
4049 . await ?;
50+ assert_eq ! ( 1 , * ( * call_count) . lock( ) . unwrap( ) ) ;
4151 Ok ( ( ) )
4252}
4353
44- // TODO RUST-1497: The following test will be removed because it is not an actual test in the spec,
45- // but just showing that the human flow is still working for two_step (nothing in caching is
46- // correctly exercised here)
54+ // Human Callback tests
55+ // Prose test 1.1 Single Principal Implicit Username
4756#[ tokio:: test]
48- async fn human_flow ( ) -> anyhow:: Result < ( ) > {
57+ async fn human_single_principal_implicit_username ( ) -> anyhow:: Result < ( ) > {
4958 use crate :: {
5059 client:: {
5160 auth:: { oidc, AuthMechanism , Credential } ,
@@ -62,10 +71,16 @@ async fn human_flow() -> anyhow::Result<()> {
6271 return Ok ( ( ) ) ;
6372 }
6473
74+ // we need to assert that the callback is only called once
75+ let call_count = Arc :: new ( Mutex :: new ( 0 ) ) ;
76+ let cb_call_count = call_count. clone ( ) ;
77+
6578 let mut opts = ClientOptions :: parse ( "mongodb://localhost/?authMechanism=MONGODB-OIDC" ) . await ?;
6679 opts. credential = Credential :: builder ( )
6780 . mechanism ( AuthMechanism :: MongoDbOidc )
68- . oidc_callback ( oidc:: Callback :: human ( |_| {
81+ . oidc_callback ( oidc:: Callback :: human ( move |_| {
82+ let call_count = cb_call_count. clone ( ) ;
83+ * call_count. lock ( ) . unwrap ( ) += 1 ;
6984 async move {
7085 Ok ( oidc:: IdpServerResponse {
7186 access_token : tokio:: fs:: read_to_string ( "/tmp/tokens/test_user1" ) . await ?,
@@ -83,5 +98,6 @@ async fn human_flow() -> anyhow::Result<()> {
8398 . collection :: < Document > ( "test" )
8499 . find_one ( None , None )
85100 . await ?;
101+ assert_eq ! ( 1 , * ( * call_count) . lock( ) . unwrap( ) ) ;
86102 Ok ( ( ) )
87103}
0 commit comments