Skip to content

Commit 91152b9

Browse files
authored
chore(NODE-5581): pull in bson alpha.1 and mongodb-legacy main (#3843)
1 parent ecb2e20 commit 91152b9

File tree

12 files changed

+83
-52
lines changed

12 files changed

+83
-52
lines changed

package-lock.json

Lines changed: 17 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
"email": "[email protected]"
2626
},
2727
"dependencies": {
28-
"bson": "^5.4.0",
29-
"mongodb-connection-string-url": "^2.6.0",
30-
"@mongodb-js/saslprep": "^1.1.0"
28+
"@mongodb-js/saslprep": "^1.1.0",
29+
"bson": "^6.0.0-alpha.1",
30+
"mongodb-connection-string-url": "^2.6.0"
3131
},
3232
"peerDependencies": {
3333
"@aws-sdk/credential-providers": "^3.188.0",
@@ -97,7 +97,7 @@
9797
"mocha": "^10.2.0",
9898
"mocha-sinon": "^2.1.2",
9999
"mongodb-client-encryption": "6.0.0-alpha.3",
100-
"mongodb-legacy": "^5.0.0",
100+
"mongodb-legacy": "github:mongodb-js/nodejs-mongodb-legacy#main",
101101
"nyc": "^15.1.0",
102102
"prettier": "^2.8.8",
103103
"semver": "^7.5.0",

src/cmap/auth/scram.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,11 @@ async function continueScramConversation(
138138
const processedPassword =
139139
cryptoMethod === 'sha256' ? saslprep(password) : passwordDigest(username, password);
140140

141-
const payload = Buffer.isBuffer(response.payload)
141+
const payload: Binary = Buffer.isBuffer(response.payload)
142142
? new Binary(response.payload)
143143
: response.payload;
144-
const dict = parsePayload(payload.value());
144+
145+
const dict = parsePayload(payload);
145146

146147
const iterations = parseInt(dict.i, 10);
147148
if (iterations && iterations < 4096) {
@@ -168,9 +169,11 @@ async function continueScramConversation(
168169
const clientKey = HMAC(cryptoMethod, saltedPassword, 'Client Key');
169170
const serverKey = HMAC(cryptoMethod, saltedPassword, 'Server Key');
170171
const storedKey = H(cryptoMethod, clientKey);
171-
const authMessage = [clientFirstMessageBare(username, nonce), payload.value(), withoutProof].join(
172-
','
173-
);
172+
const authMessage = [
173+
clientFirstMessageBare(username, nonce),
174+
payload.toString('utf8'),
175+
withoutProof
176+
].join(',');
174177

175178
const clientSignature = HMAC(cryptoMethod, storedKey, authMessage);
176179
const clientProof = `p=${xor(clientKey, clientSignature)}`;
@@ -184,7 +187,7 @@ async function continueScramConversation(
184187
};
185188

186189
const r = await connection.commandAsync(ns(`${db}.$cmd`), saslContinueCmd, undefined);
187-
const parsedResponse = parsePayload(r.payload.value());
190+
const parsedResponse = parsePayload(r.payload);
188191

189192
if (!compareDigest(Buffer.from(parsedResponse.v, 'base64'), serverSignature)) {
190193
throw new MongoRuntimeError('Server returned an invalid signature');
@@ -204,14 +207,14 @@ async function continueScramConversation(
204207
await connection.commandAsync(ns(`${db}.$cmd`), retrySaslContinueCmd, undefined);
205208
}
206209

207-
function parsePayload(payload: string) {
210+
function parsePayload(payload: Binary) {
211+
const payloadStr = payload.toString('utf8');
208212
const dict: Document = {};
209-
const parts = payload.split(',');
213+
const parts = payloadStr.split(',');
210214
for (let i = 0; i < parts.length; i++) {
211215
const valueParts = parts[i].split('=');
212216
dict[valueParts[0]] = valueParts[1];
213217
}
214-
215218
return dict;
216219
}
217220

test/action/dependency.test.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ import { expect } from 'chai';
66

77
import { dependencies, peerDependencies, peerDependenciesMeta } from '../../package.json';
88
import { setDifference } from '../mongodb';
9-
import { itInNodeProcess } from '../tools/utils';
9+
import { alphabetically, itInNodeProcess, sorted } from '../tools/utils';
1010

11-
const EXPECTED_DEPENDENCIES = ['bson', 'mongodb-connection-string-url', '@mongodb-js/saslprep'];
11+
const EXPECTED_DEPENDENCIES = sorted(
12+
['@mongodb-js/saslprep', 'bson', 'mongodb-connection-string-url'],
13+
alphabetically
14+
);
1215
const EXPECTED_PEER_DEPENDENCIES = [
1316
'@aws-sdk/credential-providers',
1417
'@mongodb-js/zstd',
@@ -22,7 +25,9 @@ const EXPECTED_PEER_DEPENDENCIES = [
2225
describe('package.json', function () {
2326
describe('dependencies', function () {
2427
it('only contains the expected dependencies', function () {
25-
expect(Object.keys(dependencies)).to.deep.equal(EXPECTED_DEPENDENCIES);
28+
expect(sorted(Object.keys(dependencies), alphabetically)).to.deep.equal(
29+
EXPECTED_DEPENDENCIES
30+
);
2631
});
2732
});
2833

test/integration/crud/insert.test.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,10 @@ describe('crud - insert', function () {
247247
test.equal(date.toString(), doc.date.toString());
248248
test.equal(date.getTime(), doc.date.getTime());
249249
test.equal(motherOfAllDocuments.oid.toHexString(), doc.oid.toHexString());
250-
test.equal(motherOfAllDocuments.binary.value(), doc.binary.value());
250+
test.equal(
251+
motherOfAllDocuments.binary.value().toString('hex'),
252+
doc.binary.value().toString('hex')
253+
);
251254

252255
test.equal(motherOfAllDocuments.int, doc.int);
253256
test.equal(motherOfAllDocuments.long, doc.long);
@@ -398,7 +401,10 @@ describe('crud - insert', function () {
398401
test.equal(date.toString(), doc.date.toString());
399402
test.equal(date.getTime(), doc.date.getTime());
400403
test.equal(motherOfAllDocuments.oid.toHexString(), doc.oid.toHexString());
401-
test.equal(motherOfAllDocuments.binary.value(), doc.binary.value());
404+
test.equal(
405+
motherOfAllDocuments.binary.value().toString('hex'),
406+
doc.binary.value().toString('hex')
407+
);
402408

403409
test.equal(motherOfAllDocuments.int, doc.int);
404410
test.equal(motherOfAllDocuments.long, doc.long);
@@ -1482,28 +1488,28 @@ describe('crud - insert', function () {
14821488
// in this case we are setting that node needs to be higher than 0.10.X to run
14831489
metadata: {
14841490
requires: {
1485-
topology: ['single', 'replicaset', 'ssl', 'heap', 'wiredtiger'],
14861491
mongodb: '>=2.8.0'
14871492
}
14881493
},
14891494

14901495
test: function (done) {
14911496
var configuration = this.configuration;
14921497
var client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 });
1498+
1499+
var document = {
1500+
string: 'abcdefghijkl',
1501+
objid: new ObjectId(Buffer.alloc(12, 1)),
1502+
double: new Double(1),
1503+
binary: new Binary(Buffer.from('hello world')),
1504+
minkey: new MinKey(),
1505+
maxkey: new MaxKey(),
1506+
code: new Code('function () {}', { a: 55 })
1507+
};
1508+
14931509
client.connect(function (err, client) {
14941510
var db = client.db(configuration.db);
14951511
var collection = db.collection('bson_types_insert_1');
14961512

1497-
var document = {
1498-
string: 'abcdefghijkl',
1499-
objid: new ObjectId('abcdefghijkl'),
1500-
double: new Double(1),
1501-
binary: new Binary(Buffer.from('hello world')),
1502-
minkey: new MinKey(),
1503-
maxkey: new MaxKey(),
1504-
code: new Code('function () {}', { a: 55 })
1505-
};
1506-
15071513
collection.insert(document, configuration.writeConcernMax(), function (err, result) {
15081514
expect(err).to.not.exist;
15091515
test.ok(result);
@@ -1512,9 +1518,9 @@ describe('crud - insert', function () {
15121518
expect(err).to.not.exist;
15131519
test.equal('abcdefghijkl', doc.string.toString());
15141520

1515-
collection.findOne({ objid: new ObjectId('abcdefghijkl') }, function (err, doc) {
1521+
collection.findOne({ objid: new ObjectId(Buffer.alloc(12, 1)) }, function (err, doc) {
15161522
expect(err).to.not.exist;
1517-
test.equal('6162636465666768696a6b6c', doc.objid.toString());
1523+
test.equal('01'.repeat(12), doc.objid.toString());
15181524

15191525
collection.findOne({ double: new Double(1) }, function (err, doc) {
15201526
expect(err).to.not.exist;

test/integration/crud/pk_factory.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('PkFactory', function () {
1919
// Custom factory (need to provide a 12 byte array);
2020
var CustomPKFactory = {
2121
createPk() {
22-
return new ObjectId('aaaaaaaaaaaa');
22+
return new ObjectId('a'.repeat(24));
2323
}
2424
};
2525

@@ -39,7 +39,7 @@ describe('PkFactory', function () {
3939

4040
collection.insert({ a: 1 }, { writeConcern: { w: 1 } }, function (err) {
4141
expect(err).to.not.exist;
42-
collection.find({ _id: new ObjectId('aaaaaaaaaaaa') }).toArray(function (err, items) {
42+
collection.find({ _id: new ObjectId('a'.repeat(24)) }).toArray(function (err, items) {
4343
expect(items.length).to.equal(1);
4444

4545
client.close(done);

test/tools/common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class ReplSetFixture {
122122
function genClusterTime(time) {
123123
return {
124124
clusterTime: new BSON.Timestamp(BSON.Long.fromNumber(time, true)),
125-
signature: { hash: new BSON.Binary('test'), keyId: new BSON.Long(1) }
125+
signature: { hash: new BSON.Binary(Buffer.from('test', 'utf8')), keyId: new BSON.Long(1) }
126126
};
127127
}
128128

test/tools/utils.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,12 @@ export class UnifiedTestSuiteBuilder {
476476
}
477477
}
478478

479-
export const byStrings = (a: any, b: any) => {
480-
const res = `${a}`.localeCompare(`${b}`);
479+
export const alphabetically = (a: any, b: any) => {
480+
const res = `${a}`.localeCompare(`${b}`, 'en-US', {
481+
usage: 'sort',
482+
numeric: true,
483+
ignorePunctuation: false
484+
});
481485
return res < 0 ? -1 : res > 0 ? 1 : 0;
482486
};
483487

test/types/community/collection/filterQuery.test-d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ const spot = {
9494
treats: ['kibble', 'bone'],
9595
playTimePercent: new Decimal128('0.999999'),
9696

97-
binary: new Binary('', 2),
97+
binary: new Binary(Buffer.from('', 'utf8'), 2),
9898
code: new Code(() => true),
9999
minKey: new MinKey(),
100100
maxKey: new MaxKey(),
@@ -161,7 +161,7 @@ expectNotType<Filter<PetModel>>({ bestFriend: [spot] });
161161
expectNotType<Filter<PetModel>>({ bestFriend: [{ name: 'Andersons' }] });
162162

163163
// it should permit all our BSON types as query values
164-
expectAssignable<Filter<PetModel>>({ binary: new Binary('', 2) });
164+
expectAssignable<Filter<PetModel>>({ binary: new Binary(Buffer.from('abc', 'utf8'), 2) });
165165
expectAssignable<Filter<PetModel>>({ code: new Code(() => true) });
166166
expectAssignable<Filter<PetModel>>({ minKey: new MinKey() });
167167
expectAssignable<Filter<PetModel>>({ maxKey: new MaxKey() });

test/unit/client-side-encryption/auto_encrypter.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,12 @@ describe('AutoEncrypter', function () {
191191
expect(decrypted.filter[Symbol.for('@@mdb.decryptedKeys')]).to.eql(['ssn']);
192192

193193
// The same, but with an object containing different data types as the input
194-
decrypted = await mc.decrypt({ a: [null, 1, { c: new bson.Binary('foo', 1) }] });
195-
expect(decrypted).to.eql({ a: [null, 1, { c: new bson.Binary('foo', 1) }] });
194+
decrypted = await mc.decrypt({
195+
a: [null, 1, { c: new bson.Binary(Buffer.from('foo', 'utf8'), 1) }]
196+
});
197+
expect(decrypted).to.eql({
198+
a: [null, 1, { c: new bson.Binary(Buffer.from('foo', 'utf8'), 1) }]
199+
});
196200
expect(decrypted).to.not.have.property(Symbol.for('@@mdb.decryptedKeys'));
197201

198202
// The same, but with nested data inside the decrypted input

test/unit/index.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { expect } from 'chai';
33
// Exception to the import from mongodb rule we're unit testing our public API
44
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
55
import * as mongodb from '../../src/index';
6-
import { byStrings, sorted } from '../tools/utils';
6+
import { alphabetically, sorted } from '../tools/utils';
77

88
/**
99
* TS-NODE Adds these keys but they are undefined, they are not present when you import from lib
@@ -134,8 +134,8 @@ const EXPECTED_EXPORTS = [
134134

135135
describe('mongodb entrypoint', () => {
136136
it('should export all and only the expected keys in expected_exports', () => {
137-
expect(sorted(Object.keys(mongodb), byStrings)).to.deep.equal(
138-
sorted(EXPECTED_EXPORTS, byStrings)
137+
expect(sorted(Object.keys(mongodb), alphabetically)).to.deep.equal(
138+
sorted(EXPECTED_EXPORTS, alphabetically)
139139
);
140140
});
141141

test/unit/sessions.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ describe('Sessions - unit', function () {
119119
it('sets clusterTime to the one provided when the signature.keyId is a bigint', () => {
120120
const validClusterTime = {
121121
clusterTime: new BSON.Timestamp(BSON.Long.fromNumber(1, true)),
122-
signature: { hash: new BSON.Binary('test'), keyId: 100n }
122+
signature: { hash: new BSON.Binary(Buffer.from('test', 'utf8')), keyId: 100n }
123123
};
124124

125125
session.advanceClusterTime(validClusterTime);

0 commit comments

Comments
 (0)