@@ -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,37 @@ describe('MONGODB-AWS', function () {
8187 expect ( provider ) . to . be . instanceOf ( MongoDBAWS ) ;
8288 } ) ;
8389
90+ describe ( 'with missing aws token' , ( ) => {
91+ let awsSessionToken : string | undefined ;
92+
93+ beforeEach ( ( ) => {
94+ awsSessionToken = process . env . AWS_SESSION_TOKEN ;
95+ delete process . env . AWS_SESSION_TOKEN ;
96+ } ) ;
97+
98+ afterEach ( ( ) => {
99+ if ( awsSessionToken != null ) {
100+ process . env . AWS_SESSION_TOKEN = awsSessionToken ;
101+ }
102+ } ) ;
103+
104+ it ( 'should not throw an exception when aws token is missing' , async function ( ) {
105+ client = this . configuration . newClient ( process . env . MONGODB_URI ) ;
106+
107+ const result = await client
108+ . db ( 'aws' )
109+ . collection ( 'aws_test' )
110+ . estimatedDocumentCount ( )
111+ . catch ( error => error ) ;
112+
113+ // We check only for the MongoMissingCredentialsError
114+ // and do check for the MongoServerError as the error or numeric result
115+ // that can be returned depending on different types of environments
116+ // getting credentials from different sources.
117+ expect ( result ) . to . not . be . instanceOf ( MongoMissingCredentialsError ) ;
118+ } ) ;
119+ } ) ;
120+
84121 describe ( 'EC2 with missing credentials' , ( ) => {
85122 let client ;
86123
0 commit comments