@@ -4,6 +4,7 @@ import type Sinon from 'sinon';
4
4
import * as sinon from 'sinon' ;
5
5
6
6
import {
7
+ connect ,
7
8
Connection ,
8
9
LEGACY_HELLO_COMMAND ,
9
10
MongoServerError ,
@@ -130,4 +131,38 @@ describe('MongoDB Handshake', () => {
130
131
}
131
132
} ) ;
132
133
} ) ;
134
+
135
+ context (
136
+ `when the handshake response includes 'saslSupportedMechs' and the array includes an unknown mechanism` ,
137
+ function ( ) {
138
+ beforeEach ( ( ) => {
139
+ sinon . stub ( Connection . prototype , 'command' ) . callsFake ( async function ( ns , cmd , options ) {
140
+ // @ts -expect-error: sinon will place wrappedMethod there
141
+ const command = Connection . prototype . command . wrappedMethod . bind ( this ) ;
142
+ if ( cmd . hello || cmd [ LEGACY_HELLO_COMMAND ] ) {
143
+ return stub ( ) ;
144
+ }
145
+ return command ( ns , cmd , options ) ;
146
+
147
+ async function stub ( ) {
148
+ const response = await command ( ns , cmd , options ) ;
149
+ // console.error({ response });
150
+ return {
151
+ ...response ,
152
+ saslSupportedMechs : [ ...( response . saslSupportedMechs ?? [ ] ) , 'random string' ]
153
+ } ;
154
+ }
155
+ } ) ;
156
+ } ) ;
157
+
158
+ afterEach ( ( ) => sinon . restore ( ) ) ;
159
+
160
+ it ( 'no error is thrown' , { requires : { auth : 'enabled' } } , async function ( ) {
161
+ client = this . configuration . newClient ( ) ;
162
+ await client . connect ( ) ;
163
+ await client . db ( 'foo' ) . collection ( 'bar' ) . insertOne ( { name : 'john doe' } ) ;
164
+ await client . close ( ) ;
165
+ } ) ;
166
+ }
167
+ ) ;
133
168
} ) ;
0 commit comments