@@ -3,6 +3,11 @@ use std::path::PathBuf;
33use once_cell:: sync:: Lazy ;
44use tokio:: sync:: OnceCell ;
55
6+ use crate :: {
7+ bson:: Bson ,
8+ test:: spec:: unified_runner:: { TestFile , TestFileEntity } ,
9+ } ;
10+
611static MONGODB_URI : Lazy < String > = Lazy :: new ( || get_env_var ( "MONGODB_URI" ) ) ;
712static MONGODB_URI_SINGLE : Lazy < String > = Lazy :: new ( || get_env_var ( "MONGODB_URI_SINGLE" ) ) ;
813#[ cfg( target_os = "linux" ) ]
@@ -30,7 +35,7 @@ async fn get_access_token_test_user(once_cell: &'static OnceCell<String>, user_n
3035 . await
3136 . to_string ( )
3237}
33- async fn get_access_token_test_user_1 ( ) -> String {
38+ pub ( crate ) async fn get_access_token_test_user_1 ( ) -> String {
3439 static ACCESS_TOKEN_TEST_USER_1 : OnceCell < String > = OnceCell :: const_new ( ) ;
3540 get_access_token_test_user ( & ACCESS_TOKEN_TEST_USER_1 , 1 ) . await
3641}
@@ -44,11 +49,37 @@ fn get_env_var(var: &str) -> String {
4449 std:: env:: var ( var) . expect ( var)
4550}
4651
52+ fn remove_mechanism_properties_placeholder ( test_file : & mut TestFile ) {
53+ if let Some ( ref mut create_entities) = test_file. create_entities {
54+ for ref mut entity in create_entities {
55+ if let TestFileEntity :: Client ( ref mut client) = entity {
56+ if let Some ( ref mut uri_options) = client. uri_options {
57+ if let Some ( mut mechanism_properties) = uri_options
58+ . remove ( "authMechanismProperties" )
59+ . and_then ( |bson| match bson {
60+ Bson :: Document ( document) => Some ( document) ,
61+ _ => None ,
62+ } )
63+ {
64+ mechanism_properties. remove ( "$$placeholder" ) ;
65+ if !mechanism_properties. is_empty ( ) {
66+ uri_options. insert ( "authMechanismProperties" , mechanism_properties) ;
67+ }
68+ }
69+ }
70+ }
71+ }
72+ }
73+ }
74+
4775mod basic {
4876 use crate :: {
4977 client:: auth:: { oidc, AuthMechanism , Credential } ,
5078 options:: ClientOptions ,
51- test:: util:: fail_point:: { FailPoint , FailPointMode } ,
79+ test:: {
80+ spec:: unified_runner:: run_unified_tests,
81+ util:: fail_point:: { FailPoint , FailPointMode } ,
82+ } ,
5283 Client ,
5384 } ;
5485 use bson:: { doc, Document } ;
@@ -61,6 +92,7 @@ mod basic {
6192
6293 use super :: {
6394 get_access_token_test_user_1,
95+ remove_mechanism_properties_placeholder,
6496 MONGODB_URI ,
6597 MONGODB_URI_SINGLE ,
6698 TEST_USER_1_USERNAME ,
@@ -74,6 +106,13 @@ mod basic {
74106 TEST_USER_2_USERNAME ,
75107 } ;
76108
109+ #[ tokio:: test( flavor = "multi_thread" ) ]
110+ async fn run_unified ( ) {
111+ run_unified_tests ( & [ "auth" , "unified" ] )
112+ . transform_files ( remove_mechanism_properties_placeholder)
113+ . await ;
114+ }
115+
77116 // Machine Callback tests
78117 #[ tokio:: test]
79118 async fn machine_1_1_callback_is_called ( ) -> anyhow:: Result < ( ) > {
@@ -1281,10 +1320,25 @@ mod basic {
12811320}
12821321
12831322mod azure {
1284- use crate :: client:: { options:: ClientOptions , Client } ;
1285- use bson:: { doc, Document } ;
1323+ use crate :: {
1324+ bson:: { doc, Document } ,
1325+ client:: {
1326+ auth:: oidc:: { AZURE_ENVIRONMENT_VALUE_STR , ENVIRONMENT_PROP_STR } ,
1327+ options:: ClientOptions ,
1328+ Client ,
1329+ } ,
1330+ test:: spec:: unified_runner:: run_unified_tests,
1331+ } ;
12861332
1287- use super :: MONGODB_URI_SINGLE ;
1333+ use super :: { remove_mechanism_properties_placeholder, MONGODB_URI_SINGLE } ;
1334+
1335+ #[ tokio:: test( flavor = "multi_thread" ) ]
1336+ async fn run_unified ( ) {
1337+ run_unified_tests ( & [ "test_files" ] )
1338+ . transform_files ( remove_mechanism_properties_placeholder)
1339+ . use_exact_path ( )
1340+ . await ;
1341+ }
12881342
12891343 #[ tokio:: test]
12901344 async fn machine_5_1_azure_with_no_username ( ) -> anyhow:: Result < ( ) > {
@@ -1318,8 +1372,6 @@ mod azure {
13181372
13191373 #[ tokio:: test]
13201374 async fn machine_5_3_token_resource_must_be_set_for_azure ( ) -> anyhow:: Result < ( ) > {
1321- use crate :: client:: auth:: oidc:: { AZURE_ENVIRONMENT_VALUE_STR , ENVIRONMENT_PROP_STR } ;
1322-
13231375 let mut opts = ClientOptions :: parse ( & * MONGODB_URI_SINGLE ) . await ?;
13241376 opts. credential . as_mut ( ) . unwrap ( ) . mechanism_properties = Some ( doc ! {
13251377 ENVIRONMENT_PROP_STR : AZURE_ENVIRONMENT_VALUE_STR ,
@@ -1341,10 +1393,21 @@ mod azure {
13411393}
13421394
13431395mod gcp {
1344- use crate :: client:: { options:: ClientOptions , Client } ;
1345- use bson:: { doc, Document } ;
1396+ use crate :: {
1397+ bson:: { doc, Document } ,
1398+ client:: { options:: ClientOptions , Client } ,
1399+ test:: spec:: unified_runner:: run_unified_tests,
1400+ } ;
13461401
1347- use super :: MONGODB_URI_SINGLE ;
1402+ use super :: { remove_mechanism_properties_placeholder, MONGODB_URI_SINGLE } ;
1403+
1404+ #[ tokio:: test( flavor = "multi_thread" ) ]
1405+ async fn run_unified ( ) {
1406+ run_unified_tests ( & [ "test_files" ] )
1407+ . transform_files ( remove_mechanism_properties_placeholder)
1408+ . use_exact_path ( )
1409+ . await ;
1410+ }
13481411
13491412 #[ tokio:: test]
13501413 async fn machine_5_4_gcp_with_no_username ( ) -> anyhow:: Result < ( ) > {
@@ -1385,23 +1448,15 @@ mod gcp {
13851448}
13861449
13871450mod k8s {
1388- use crate :: {
1389- bson:: { doc, Document } ,
1390- Client ,
1391- } ;
1451+ use crate :: test:: spec:: unified_runner:: run_unified_tests;
13921452
1393- use super :: MONGODB_URI_SINGLE ;
1453+ use super :: remove_mechanism_properties_placeholder ;
13941454
1395- // There's no spec test for K8s, so we run this simple sanity check.
1396- #[ tokio:: test]
1397- async fn successfully_authenticates ( ) -> anyhow:: Result < ( ) > {
1398- let client = Client :: with_uri_str ( & * MONGODB_URI_SINGLE ) . await ?;
1399- client
1400- . database ( "test" )
1401- . collection :: < Document > ( "test" )
1402- . find_one ( doc ! { } )
1403- . await ?;
1404-
1405- Ok ( ( ) )
1455+ #[ tokio:: test( flavor = "multi_thread" ) ]
1456+ async fn run_unified ( ) {
1457+ run_unified_tests ( & [ "test_files" ] )
1458+ . transform_files ( remove_mechanism_properties_placeholder)
1459+ . use_exact_path ( )
1460+ . await ;
14061461 }
14071462}
0 commit comments