@@ -16,13 +16,14 @@ import {
16
16
MongoServerError
17
17
} from '../../mongodb' ;
18
18
19
+ const isMongoDBURITest = ( process . env . MONGODB_URI ?? '' ) . includes ( 'MONGODB_AWS' ) ;
20
+
19
21
describe ( 'MONGODB-AWS' , function ( ) {
20
22
let awsSdkPresent ;
21
23
let client : MongoClient ;
22
24
23
25
beforeEach ( function ( ) {
24
- const MONGODB_URI = process . env . MONGODB_URI ;
25
- if ( ! MONGODB_URI || MONGODB_URI . indexOf ( 'MONGODB-AWS' ) === - 1 ) {
26
+ if ( ! isMongoDBURITest ) {
26
27
this . currentTest . skipReason = 'requires MONGODB_URI to contain MONGODB-AWS auth mechanism' ;
27
28
return this . skip ( ) ;
28
29
}
@@ -327,33 +328,33 @@ describe('MONGODB-AWS', function () {
327
328
describe ( 'AWS KMS Credential Fetching' , function ( ) {
328
329
context ( 'when the AWS SDK is not installed' , function ( ) {
329
330
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 ( ) ;
335
337
} ) ;
336
338
it ( 'fetching AWS KMS credentials throws an error' , async function ( ) {
337
339
const error = await new KMSCredentialProvider ( { aws : { } } ) . refreshCredentials ( ) . catch ( e => e ) ;
338
-
339
340
expect ( error ) . to . be . instanceOf ( MongoAWSError ) ;
340
341
} ) ;
341
342
} ) ;
342
343
343
344
context ( 'when the AWS SDK is installed' , function ( ) {
344
345
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 ( ) ;
350
352
} ) ;
351
353
it ( 'KMS credentials are successfully fetched.' , async function ( ) {
352
354
const { aws } = await new KMSCredentialProvider ( { aws : { } } ) . refreshCredentials ( ) ;
353
355
354
356
expect ( aws ) . to . have . property ( 'accessKeyId' ) ;
355
357
expect ( aws ) . to . have . property ( 'secretAccessKey' ) ;
356
- expect ( aws ) . to . have . property ( 'sessionToken' ) ;
357
358
} ) ;
358
359
} ) ;
359
360
} ) ;
0 commit comments