Skip to content

Commit

Permalink
fix(NODE-5609): node driver omits base64 padding in sasl-continue com…
Browse files Browse the repository at this point in the history
…mand (#3975)
  • Loading branch information
alenakhineika authored Jan 26, 2024
1 parent aed1cf0 commit b7d28d3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cmap/auth/scram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ function parsePayload(payload: Binary) {
const dict: Document = {};
const parts = payloadStr.split(',');
for (let i = 0; i < parts.length; i++) {
const valueParts = parts[i].split('=');
const valueParts = (parts[i].match(/^([^=]*)=(.*)$/) ?? []).slice(1);
dict[valueParts[0]] = valueParts[1];
}
return dict;
Expand Down
33 changes: 33 additions & 0 deletions test/unit/assorted/scram_iterations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,37 @@ describe('SCRAM Iterations Tests', function () {
.to.have.property('message')
.that.matches(/connection(.+)closed/);
});

it('should preserve trailing "=" from saslStart responses that are passed to saslContinue', async function () {
const credentials = new MongoCredentials({
mechanism: 'DEFAULT',
source: 'db',
username: 'user',
password: 'pencil',
mechanismProperties: {}
});
let payload;
client.s.options.credentials = credentials;

server.setMessageHandler(request => {
const doc = request.document;
if (isHello(doc)) {
return request.reply(Object.assign({}, mock.HELLO));
} else if (doc.saslStart) {
return request.reply({
ok: 1,
done: false,
payload: Buffer.from(
'n=__system,r=r7RuW8nC89hmrlIPSpatiEGnZGkuGcsq,r=r7RuW8nC89hmrlIPSpatiEGnZGkuGcsquPuvfddlU3NavdfJxv/XKg==,s=b7rCae/2BRjlcsn93RoUOfqtiwaf0nrXvSKLdQ==,i=15000'
)
});
} else if (doc.saslContinue) {
payload = doc.payload.toString('utf8');
request.connection.destroy();
}
});

await client.connect().catch(error => error);
expect(payload).to.includes('r=r7RuW8nC89hmrlIPSpatiEGnZGkuGcsquPuvfddlU3NavdfJxv/XKg==');
});
});

0 comments on commit b7d28d3

Please sign in to comment.