@@ -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,37 @@ 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 : 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
+
84
121
describe ( 'EC2 with missing credentials' , ( ) => {
85
122
let client ;
86
123
0 commit comments