@@ -5,7 +5,13 @@ import * as http from 'http';
55import { performance } from 'perf_hooks' ;
66import * as sinon from 'sinon' ;
77
8- import { MongoAWSError , type MongoClient , MongoDBAWS , MongoServerError } from '../../mongodb' ;
8+ import {
9+ MongoAWSError ,
10+ type MongoClient ,
11+ MongoDBAWS ,
12+ MongoMissingCredentialsError ,
13+ MongoServerError
14+ } from '../../mongodb' ;
915
1016function awsSdk ( ) {
1117 try {
@@ -81,6 +87,35 @@ describe('MONGODB-AWS', function () {
8187 expect ( provider ) . to . be . instanceOf ( MongoDBAWS ) ;
8288 } ) ;
8389
90+ describe ( 'with missing aws token' , ( ) => {
91+ let awsSessionToken ;
92+
93+ beforeEach ( function ( ) {
94+ awsSessionToken = process . env . AWS_SESSION_TOKEN ;
95+ delete process . env . AWS_SESSION_TOKEN ;
96+ } ) ;
97+
98+ afterEach ( async ( ) => {
99+ process . env . AWS_SESSION_TOKEN = awsSessionToken ;
100+ } ) ;
101+
102+ it ( 'should not throw an exception when aws token is missing' , async function ( ) {
103+ client = this . configuration . newClient ( process . env . MONGODB_URI ) ;
104+
105+ const result = await client
106+ . db ( 'aws' )
107+ . collection ( 'aws_test' )
108+ . estimatedDocumentCount ( )
109+ . catch ( error => error ) ;
110+
111+ // We check only for the MongoMissingCredentialsError
112+ // and do check for the MongoServerError as the error or numeric result
113+ // that can be returned depending on different types of environments
114+ // getting credentials from different sources.
115+ expect ( result ) . to . not . be . instanceOf ( MongoMissingCredentialsError ) ;
116+ } ) ;
117+ } ) ;
118+
84119 describe ( 'EC2 with missing credentials' , ( ) => {
85120 let client ;
86121
0 commit comments