@@ -5,7 +5,13 @@ import * as http from 'http';
5
5
import { performance } from 'perf_hooks' ;
6
6
import * as sinon from 'sinon' ;
7
7
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' ;
9
15
10
16
function awsSdk ( ) {
11
17
try {
@@ -81,6 +87,35 @@ describe('MONGODB-AWS', function () {
81
87
expect ( provider ) . to . be . instanceOf ( MongoDBAWS ) ;
82
88
} ) ;
83
89
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
+
84
119
describe ( 'EC2 with missing credentials' , ( ) => {
85
120
let client ;
86
121
0 commit comments