Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(NODE-5609): node driver omits base64 padding in sasl-continue command #3975

Merged
merged 4 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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==');
});
});
Loading