@@ -137,6 +137,8 @@ describe('MONGODB-AWS', function () {
137137 } ) ;
138138
139139 context ( 'when user supplies a credentials provider' , function ( ) {
140+ let providerCount = 0 ;
141+
140142 beforeEach ( function ( ) {
141143 if ( ! awsSdkPresent ) {
142144 this . skipReason = 'only relevant to AssumeRoleWithWebIdentity with SDK installed' ;
@@ -147,9 +149,13 @@ describe('MONGODB-AWS', function () {
147149 it ( 'authenticates with a user provided credentials provider' , async function ( ) {
148150 // @ts -expect-error We intentionally access a protected variable.
149151 const credentialProvider = AWSTemporaryCredentialProvider . awsSDK ;
152+ const provider = async ( ) => {
153+ providerCount ++ ;
154+ return await credentialProvider . fromNodeProviderChain ( ) . apply ( ) ;
155+ } ;
150156 client = this . configuration . newClient ( process . env . MONGODB_URI , {
151157 authMechanismProperties : {
152- AWS_CREDENTIAL_PROVIDER : credentialProvider . fromNodeProviderChain ( )
158+ AWS_CREDENTIAL_PROVIDER : provider
153159 }
154160 } ) ;
155161
@@ -161,6 +167,13 @@ describe('MONGODB-AWS', function () {
161167
162168 expect ( result ) . to . not . be . instanceOf ( MongoServerError ) ;
163169 expect ( result ) . to . be . a ( 'number' ) ;
170+ // If we have a username the credentials have been set from the URI, options, or environment
171+ // variables per the auth spec stated order.
172+ if ( client . options . credentials . username ) {
173+ expect ( providerCount ) . to . equal ( 0 ) ;
174+ } else {
175+ expect ( providerCount ) . to . be . greaterThan ( 0 ) ;
176+ }
164177 } ) ;
165178 } ) ;
166179
0 commit comments