Skip to content

Commit 6b9ff05

Browse files
committed
feat: support shorter SCRAM conversations
MongoDB 4.4+ will support removing an extra unnecessary empty exchange during SCRAM handshaking NODE-2301
1 parent 68170da commit 6b9ff05

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

lib/core/auth/scram.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ class ScramSHA extends AuthProvider {
183183
saslStart: 1,
184184
mechanism,
185185
payload: new Binary(Buffer.concat([Buffer.from('n,,', 'utf8'), firstBare])),
186-
autoAuthorize: 1
186+
autoAuthorize: 1,
187+
options: { skipEmptyExchange: true }
187188
};
188189

189190
// Write the commmand on the connection

test/functional/scram_sha_256.test.js

+26
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,32 @@ describe('SCRAM-SHA-256 auth', function() {
168168
}
169169
});
170170

171+
it('should shorten SCRAM conversations if the server supports it ', {
172+
metadata: { requires: { mongodb: '>=4.3.x' } },
173+
test: function() {
174+
const options = {
175+
auth: {
176+
user: userMap.both.username,
177+
password: userMap.both.password
178+
},
179+
authSource: this.configuration.db
180+
};
181+
182+
let sendAuthCommandSpy;
183+
test.sandbox
184+
.stub(ScramSHA256.prototype, '_executeScram')
185+
.callsFake(function(sendAuthCommand, connection, credentials, nonce, callback) {
186+
const executeScram = ScramSHA256.prototype._executeScram.wrappedMethod;
187+
sendAuthCommandSpy = test.sandbox.spy(sendAuthCommand);
188+
executeScram.apply(this, [sendAuthCommandSpy, connection, credentials, nonce, callback]);
189+
});
190+
191+
return withClient(this.configuration.newClient({}, options), () => {
192+
expect(sendAuthCommandSpy.callCount).to.equal(2);
193+
});
194+
}
195+
});
196+
171197
// Step 3
172198
// For test users that support only one mechanism, verify that explictly specifying the other mechanism fails.
173199
it('should fail to connect if incorrect auth mechanism is explicitly specified', {

0 commit comments

Comments
 (0)