diff --git a/lib/core/auth/scram.js b/lib/core/auth/scram.js index 32fb4cd57b..de29817dcf 100644 --- a/lib/core/auth/scram.js +++ b/lib/core/auth/scram.js @@ -183,7 +183,8 @@ class ScramSHA extends AuthProvider { saslStart: 1, mechanism, payload: new Binary(Buffer.concat([Buffer.from('n,,', 'utf8'), firstBare])), - autoAuthorize: 1 + autoAuthorize: 1, + options: { skipEmptyExchange: true } }; // Write the commmand on the connection diff --git a/test/functional/scram_sha_256.test.js b/test/functional/scram_sha_256.test.js index 3192422887..8ca0838aa2 100644 --- a/test/functional/scram_sha_256.test.js +++ b/test/functional/scram_sha_256.test.js @@ -168,6 +168,32 @@ describe('SCRAM-SHA-256 auth', function() { } }); + it('should shorten SCRAM conversations if the server supports it ', { + metadata: { requires: { mongodb: '>=4.3.x' } }, + test: function() { + const options = { + auth: { + user: userMap.both.username, + password: userMap.both.password + }, + authSource: this.configuration.db + }; + + let sendAuthCommandSpy; + test.sandbox + .stub(ScramSHA256.prototype, '_executeScram') + .callsFake(function(sendAuthCommand, connection, credentials, nonce, callback) { + const executeScram = ScramSHA256.prototype._executeScram.wrappedMethod; + sendAuthCommandSpy = test.sandbox.spy(sendAuthCommand); + executeScram.apply(this, [sendAuthCommandSpy, connection, credentials, nonce, callback]); + }); + + return withClient(this.configuration.newClient({}, options), () => { + expect(sendAuthCommandSpy.callCount).to.equal(2); + }); + } + }); + // Step 3 // For test users that support only one mechanism, verify that explictly specifying the other mechanism fails. it('should fail to connect if incorrect auth mechanism is explicitly specified', {