@@ -4,6 +4,7 @@ import type Sinon from 'sinon';
44import * as sinon from 'sinon' ;
55
66import {
7+ connect ,
78 Connection ,
89 LEGACY_HELLO_COMMAND ,
910 MongoServerError ,
@@ -130,4 +131,38 @@ describe('MongoDB Handshake', () => {
130131 }
131132 } ) ;
132133 } ) ;
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+ ) ;
133168} ) ;
0 commit comments