@@ -74,17 +74,26 @@ func main() {
7474 fmt .Println ("...Ok" )
7575 }
7676 }
77- aux ("machine_1_1_callbackIsCalled" , machine11callbackIsCalled )
78- aux ("machine_1_2_callbackIsCalledOnlyOneForMultipleConnections" , machine12callbackIsCalledOnlyOneForMultipleConnections )
79- aux ("machine_2_1_validCallbackInputs" , machine21validCallbackInputs )
80- aux ("machine_2_3_oidcCallbackReturnMissingData" , machine23oidcCallbackReturnMissingData )
81- aux ("machine_2_4_invalidClientConfigurationWithCallback" , machine24invalidClientConfigurationWithCallback )
82- aux ("machine_3_1_failureWithCachedTokensFetchANewTokenAndRetryAuth" , machine31failureWithCachedTokensFetchANewTokenAndRetryAuth )
83- aux ("machine_3_2_authFailuresWithoutCachedTokensReturnsAnError" , machine32authFailuresWithoutCachedTokensReturnsAnError )
84- aux ("machine_3_3_UnexpectedErrorCodeDoesNotClearTheCache" , machine33UnexpectedErrorCodeDoesNotClearTheCache )
85- aux ("machine_4_1_reauthenticationSucceeds" , machine41ReauthenticationSucceeds )
86- aux ("machine_4_2_readCommandsFailIfReauthenticationFails" , machine42ReadCommandsFailIfReauthenticationFails )
87- aux ("machine_4_3_writeCommandsFailIfReauthenticationFails" , machine43WriteCommandsFailIfReauthenticationFails )
77+ env := os .Getenv ("OIDC_ENV" )
78+ switch env {
79+ case "" :
80+ aux ("machine_1_1_callbackIsCalled" , machine11callbackIsCalled )
81+ aux ("machine_1_2_callbackIsCalledOnlyOneForMultipleConnections" , machine12callbackIsCalledOnlyOneForMultipleConnections )
82+ aux ("machine_2_1_validCallbackInputs" , machine21validCallbackInputs )
83+ aux ("machine_2_3_oidcCallbackReturnMissingData" , machine23oidcCallbackReturnMissingData )
84+ aux ("machine_2_4_invalidClientConfigurationWithCallback" , machine24invalidClientConfigurationWithCallback )
85+ aux ("machine_3_1_failureWithCachedTokensFetchANewTokenAndRetryAuth" , machine31failureWithCachedTokensFetchANewTokenAndRetryAuth )
86+ aux ("machine_3_2_authFailuresWithoutCachedTokensReturnsAnError" , machine32authFailuresWithoutCachedTokensReturnsAnError )
87+ aux ("machine_3_3_UnexpectedErrorCodeDoesNotClearTheCache" , machine33UnexpectedErrorCodeDoesNotClearTheCache )
88+ aux ("machine_4_1_reauthenticationSucceeds" , machine41ReauthenticationSucceeds )
89+ aux ("machine_4_2_readCommandsFailIfReauthenticationFails" , machine42ReadCommandsFailIfReauthenticationFails )
90+ aux ("machine_4_3_writeCommandsFailIfReauthenticationFails" , machine43WriteCommandsFailIfReauthenticationFails )
91+ case "azure" :
92+ aux ("machine_5_1_azureWithNoUsername" , machine51azureWithNoUsername )
93+ aux ("machine_5_2_azureWithNoUsername" , machine52azureWithBadUsername )
94+ default :
95+ log .Fatal ("Unknown OIDC_ENV: " , env )
96+ }
8897 if hasError {
8998 log .Fatal ("One or more tests failed" )
9099 }
@@ -686,3 +695,44 @@ func machine43WriteCommandsFailIfReauthenticationFails() error {
686695 }
687696 return callbackFailed
688697}
698+
699+ func machine51azureWithNoUsername () error {
700+ opts := options .Client ().ApplyURI (uriSingle )
701+ if opts == nil || opts .Auth == nil {
702+ return fmt .Errorf ("machine_5_1: failed parsing uri: %q" , uriSingle )
703+ }
704+ client , err := mongo .Connect (context .Background (), opts )
705+ if err != nil {
706+ return fmt .Errorf ("machine_5_1: failed connecting client: %v" , err )
707+ }
708+ defer client .Disconnect (context .Background ())
709+
710+ coll := client .Database ("test" ).Collection ("test" )
711+
712+ _ , err = coll .Find (context .Background (), bson.D {})
713+ if err != nil {
714+ return fmt .Errorf ("machine_5_1: failed executing Find: %v" , err )
715+ }
716+ return nil
717+ }
718+
719+ func machine52azureWithBadUsername () error {
720+ opts := options .Client ().ApplyURI (uriSingle )
721+ if opts == nil || opts .Auth == nil {
722+ return fmt .Errorf ("machine_5_2: failed parsing uri: %q" , uriSingle )
723+ }
724+ opts .Auth .Username = "bad"
725+ client , err := mongo .Connect (context .Background (), opts )
726+ if err != nil {
727+ return fmt .Errorf ("machine_5_2: failed connecting client: %v" , err )
728+ }
729+ defer client .Disconnect (context .Background ())
730+
731+ coll := client .Database ("test" ).Collection ("test" )
732+
733+ _ , err = coll .Find (context .Background (), bson.D {})
734+ if err == nil {
735+ return fmt .Errorf ("machine_5_2: Find succeeded when it should fail" )
736+ }
737+ return nil
738+ }
0 commit comments