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

feat(NODE-4892)!: error on bson types not from this version #543

Merged
merged 26 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c95f4c1
feat(NODE-4892)!: error on bson types not from this version
nbbeeken Dec 15, 2022
c0ce081
chore(release): 5.0.0-alpha.0
nbbeeken Dec 19, 2022
5b38dd8
fix: BSONSymbol issue
nbbeeken Dec 19, 2022
6557ebc
fix: use common constant for versioning
nbbeeken Dec 19, 2022
7596086
chore(release): 5.0.0-alpha.1
nbbeeken Dec 19, 2022
1cd6a31
Merge branch 'main' into NODE-4892-version-tag
durran Dec 20, 2022
9132939
Merge branch 'main' into NODE-4892-version-tag
nbbeeken Dec 30, 2022
c4715c1
Merge branch 'main' into NODE-4892-version-tag
nbbeeken Jan 4, 2023
90d2467
Merge branch 'main' into NODE-4892-version-tag
nbbeeken Jan 5, 2023
02f26dd
fix: calculate object size and test for error case
nbbeeken Jan 5, 2023
9e6a976
Merge branch 'main' into NODE-4892-version-tag
nbbeeken Jan 10, 2023
ff249e9
chore(release): 5.0.0-alpha.2
nbbeeken Jan 10, 2023
60bf3d4
feat: add BSONValue super class with version getter
nbbeeken Jan 11, 2023
40ed19e
test: name fix
nbbeeken Jan 11, 2023
120d026
fix: rm getter from uuid
nbbeeken Jan 11, 2023
3860c8c
fix: lint
nbbeeken Jan 12, 2023
b7c0e01
feat: add other common apis
nbbeeken Jan 12, 2023
3887429
fix: add access annotations
nbbeeken Jan 12, 2023
56e348d
fix: comments
nbbeeken Jan 12, 2023
11159bb
fix: revert history file
nbbeeken Jan 12, 2023
06911d1
fix: lint
nbbeeken Jan 12, 2023
b11e13d
fix tests checking for BSONVersionError
nbbeeken Jan 12, 2023
ee1c500
docs: migrate
nbbeeken Jan 12, 2023
c3b4cc2
docs: add jira ticket
nbbeeken Jan 12, 2023
814f52f
address comments
nbbeeken Jan 12, 2023
7614863
docs: update guide
nbbeeken Jan 12, 2023
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
9 changes: 5 additions & 4 deletions test/node/bson_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1808,7 +1808,8 @@ describe('BSON', function () {

it('should throw if invalid BSON types are input to BSON serializer', function () {
const oid = new ObjectId('111111111111111111111111');
const badBsonType = Object.assign({}, oid, { _bsontype: 'bogus' });
const badBsonType = new ObjectId('111111111111111111111111');
Object.defineProperty(badBsonType, '_bsontype', { value: 'bogus' });
const badDoc = { bad: badBsonType };
const badArray = [oid, badDoc];
const badMap = new Map([
Expand All @@ -1817,9 +1818,9 @@ describe('BSON', function () {
['c', badArray]
]);

expect(() => BSON.serialize(badDoc)).to.throw(BSONError);
expect(() => BSON.serialize(badArray)).to.throw(BSONError);
expect(() => BSON.serialize(badMap)).to.throw(BSONError);
expect(() => BSON.serialize(badDoc)).to.throw(/invalid _bsontype/);
expect(() => BSON.serialize({ badArray })).to.throw(/invalid _bsontype/);
expect(() => BSON.serialize(badMap)).to.throw(/invalid _bsontype/);
});

describe('Should support util.inspect for', function () {
Expand Down
14 changes: 8 additions & 6 deletions test/node/extended_json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as BSON from '../register-bson';
const EJSON = BSON.EJSON;
import * as vm from 'node:vm';
import { expect } from 'chai';
import { BSONError } from '../../src';
import { BSONVersionError } from '../../src';

// BSON types
const Binary = BSON.Binary;
Expand Down Expand Up @@ -300,14 +300,16 @@ describe('Extended JSON', function () {
expect(serialized).to.equal('{"a":10}');
});

it('should throw if invalid BSON types are input to EJSON serializer', function () {
it.skip('should throw if invalid BSON types are input to EJSON serializer', function () {
// TODO This doesn't throw for the reason you'd expect it to
nbbeeken marked this conversation as resolved.
Show resolved Hide resolved
const oid = new ObjectId('111111111111111111111111');
const badBsonType = Object.assign({}, oid, { _bsontype: 'bogus' });
const badBsonType = new ObjectId('111111111111111111111111');
Object.defineProperty(badBsonType, '_bsontype', { value: 'bogus' });
const badDoc = { bad: badBsonType };
const badArray = [oid, badDoc];
// const badMap = new Map([['a', badBsonType], ['b', badDoc], ['c', badArray]]);
expect(() => EJSON.serialize(badDoc)).to.throw(BSONError);
expect(() => EJSON.serialize(badArray)).to.throw(BSONError);
expect(() => EJSON.serialize(badDoc)).to.throw(/invalid _bsontype/);
expect(() => EJSON.serialize({ badArray })).to.throw(/invalid _bsontype/);
// expect(() => EJSON.serialize(badMap)).to.throw(); // uncomment when EJSON supports ES6 Map
});

Expand Down Expand Up @@ -556,6 +558,6 @@ describe('Extended JSON', function () {
EJSON.stringify({
a: { _bsontype: 'Int32', value: 2, [Symbol.for('@@mdb.bson.version')]: 1 }
})
).to.throw(BSONError, /Unsupported BSON version/i);
).to.throw(BSONVersionError, /Unsupported BSON version/i);
});
});
4 changes: 2 additions & 2 deletions test/node/parser/calculate_size.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as BSON from '../../register-bson';
import { expect } from 'chai';
import { BSONError } from '../../register-bson';
import { BSONVersionError } from '../../register-bson';

describe('calculateSize()', () => {
it('should only enumerate own property keys from input objects', () => {
Expand All @@ -14,6 +14,6 @@ describe('calculateSize()', () => {
BSON.calculateObjectSize({
a: { _bsontype: 'Int32', value: 2, [Symbol.for('@@mdb.bson.version')]: 1 }
})
).to.throw(BSONError, /Unsupported BSON version/i);
).to.throw(BSONVersionError, /Unsupported BSON version/i);
});
});
4 changes: 2 additions & 2 deletions test/node/parser/serializer.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as BSON from '../../register-bson';
import { bufferFromHexArray } from '../tools/utils';
import { expect } from 'chai';
import { BSONError } from '../../register-bson';
import { BSONVersionError } from '../../register-bson';

describe('serialize()', () => {
it('should only enumerate own property keys from input objects', () => {
Expand Down Expand Up @@ -97,7 +97,7 @@ describe('serialize()', () => {
BSON.serialize({
a: { _bsontype: 'Int32', value: 2, [Symbol.for('@@mdb.bson.version')]: 1 }
})
).to.throw(BSONError, /Unsupported BSON version/i);
).to.throw(BSONVersionError, /Unsupported BSON version/i);
});
});
});