@@ -16,13 +16,14 @@ import {
1616 MongoServerError
1717} from '../../mongodb' ;
1818
19+ const isMongoDBURITest = ( process . env . MONGODB_URI ?? '' ) . includes ( 'MONGODB_AWS' ) ;
20+
1921describe ( 'MONGODB-AWS' , function ( ) {
2022 let awsSdkPresent ;
2123 let client : MongoClient ;
2224
2325 beforeEach ( function ( ) {
24- const MONGODB_URI = process . env . MONGODB_URI ;
25- if ( ! MONGODB_URI || MONGODB_URI . indexOf ( 'MONGODB-AWS' ) === - 1 ) {
26+ if ( ! isMongoDBURITest ) {
2627 this . currentTest . skipReason = 'requires MONGODB_URI to contain MONGODB-AWS auth mechanism' ;
2728 return this . skip ( ) ;
2829 }
@@ -327,33 +328,33 @@ describe('MONGODB-AWS', function () {
327328describe ( 'AWS KMS Credential Fetching' , function ( ) {
328329 context ( 'when the AWS SDK is not installed' , function ( ) {
329330 beforeEach ( function ( ) {
330- if ( AWSTemporaryCredentialProvider . isAWSSDKInstalled ) {
331- this . currentTest . skipReason =
332- 'This test must run in an environment where the AWS SDK is not installed.' ;
333- this . skip ( ) ;
334- }
331+ this . currentTest . skipReason = ! isMongoDBURITest
332+ ? 'Test must run in an AWS auth testing environment'
333+ : AWSTemporaryCredentialProvider . isAWSSDKInstalled
334+ ? 'This test must run in an environment where the AWS SDK is not installed.'
335+ : undefined ;
336+ this . currentTest ?. skipReason && this . skip ( ) ;
335337 } ) ;
336338 it ( 'fetching AWS KMS credentials throws an error' , async function ( ) {
337339 const error = await new KMSCredentialProvider ( { aws : { } } ) . refreshCredentials ( ) . catch ( e => e ) ;
338-
339340 expect ( error ) . to . be . instanceOf ( MongoAWSError ) ;
340341 } ) ;
341342 } ) ;
342343
343344 context ( 'when the AWS SDK is installed' , function ( ) {
344345 beforeEach ( function ( ) {
345- if ( ! AWSTemporaryCredentialProvider . isAWSSDKInstalled ) {
346- this . currentTest . skipReason =
347- 'This test must run in an environment where the AWS SDK is installed.' ;
348- this . skip ( ) ;
349- }
346+ this . currentTest . skipReason = ! isMongoDBURITest
347+ ? 'Test must run in an AWS auth testing environment'
348+ : AWSTemporaryCredentialProvider . isAWSSDKInstalled
349+ ? 'This test must run in an environment where the AWS SDK is installed.'
350+ : undefined ;
351+ this . currentTest ?. skipReason && this . skip ( ) ;
350352 } ) ;
351353 it ( 'KMS credentials are successfully fetched.' , async function ( ) {
352354 const { aws } = await new KMSCredentialProvider ( { aws : { } } ) . refreshCredentials ( ) ;
353355
354356 expect ( aws ) . to . have . property ( 'accessKeyId' ) ;
355357 expect ( aws ) . to . have . property ( 'secretAccessKey' ) ;
356- expect ( aws ) . to . have . property ( 'sessionToken' ) ;
357358 } ) ;
358359 } ) ;
359360} ) ;
0 commit comments