@@ -13,17 +13,18 @@ import {
13
13
type MongoClient ,
14
14
MongoDBAWS ,
15
15
MongoMissingCredentialsError ,
16
- MongoServerError
16
+ MongoServerError ,
17
+ setDifference
17
18
} from '../../mongodb' ;
18
19
19
- const isMongoDBURITest = ( process . env . MONGODB_URI ?? '' ) . includes ( 'MONGODB_AWS' ) ;
20
+ const isMongoDBAWSAuthEnvironment = ( process . env . MONGODB_URI ?? '' ) . includes ( 'MONGODB_AWS' ) ;
20
21
21
22
describe ( 'MONGODB-AWS' , function ( ) {
22
23
let awsSdkPresent ;
23
24
let client : MongoClient ;
24
25
25
26
beforeEach ( function ( ) {
26
- if ( ! isMongoDBURITest ) {
27
+ if ( ! isMongoDBAWSAuthEnvironment ) {
27
28
this . currentTest . skipReason = 'requires MONGODB_URI to contain MONGODB-AWS auth mechanism' ;
28
29
return this . skip ( ) ;
29
30
}
@@ -328,7 +329,7 @@ describe('MONGODB-AWS', function () {
328
329
describe ( 'AWS KMS Credential Fetching' , function ( ) {
329
330
context ( 'when the AWS SDK is not installed' , function ( ) {
330
331
beforeEach ( function ( ) {
331
- this . currentTest . skipReason = ! isMongoDBURITest
332
+ this . currentTest . skipReason = ! isMongoDBAWSAuthEnvironment
332
333
? 'Test must run in an AWS auth testing environment'
333
334
: AWSTemporaryCredentialProvider . isAWSSDKInstalled
334
335
? 'This test must run in an environment where the AWS SDK is not installed.'
@@ -343,7 +344,7 @@ describe('AWS KMS Credential Fetching', function () {
343
344
344
345
context ( 'when the AWS SDK is installed' , function ( ) {
345
346
beforeEach ( function ( ) {
346
- this . currentTest . skipReason = ! isMongoDBURITest
347
+ this . currentTest . skipReason = ! isMongoDBAWSAuthEnvironment
347
348
? 'Test must run in an AWS auth testing environment'
348
349
: AWSTemporaryCredentialProvider . isAWSSDKInstalled
349
350
? 'This test must run in an environment where the AWS SDK is installed.'
@@ -356,5 +357,17 @@ describe('AWS KMS Credential Fetching', function () {
356
357
expect ( aws ) . to . have . property ( 'accessKeyId' ) ;
357
358
expect ( aws ) . to . have . property ( 'secretAccessKey' ) ;
358
359
} ) ;
360
+
361
+ it ( 'does not return any extra keys for the `aws` credential provider' , async function ( ) {
362
+ const { aws } = await new KMSCredentialProvider ( { aws : { } } ) . refreshCredentials ( ) ;
363
+
364
+ const keys = new Set ( Object . keys ( aws ?? { } ) ) ;
365
+ const allowedKeys = [ 'accessKeyId' , 'secretAccessKey' , 'sessionToken' ] ;
366
+
367
+ expect (
368
+ setDifference ( keys , allowedKeys ) ,
369
+ 'received an unexpected key in the response refreshing KMS credentials'
370
+ ) . to . deep . equal ( [ ] ) ;
371
+ } ) ;
359
372
} ) ;
360
373
} ) ;
0 commit comments