Skip to content

Commit

Permalink
feat: support shorter SCRAM conversations
Browse files Browse the repository at this point in the history
MongoDB 4.4+ will support removing an extra unnecessary empty
exchange during SCRAM handshaking

NODE-2301
  • Loading branch information
mbroadst committed Feb 10, 2020
1 parent 68170da commit 6b9ff05
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/core/auth/scram.js
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions test/functional/scram_sha_256.test.js
Expand Up @@ -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', {
Expand Down

0 comments on commit 6b9ff05

Please sign in to comment.