From 6ff3b998c54928c046b6ed6a2c83283598031f45 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Fri, 13 Jan 2023 13:53:19 -0500 Subject: [PATCH 1/7] feat(NODE-4950)!: remove bson-ext import --- .evergreen/config.in.yml | 15 -- .evergreen/config.yml | 49 ----- .evergreen/generate_evergreen_tasks.js | 41 +--- .evergreen/run-bson-ext-test.sh | 32 --- README.md | 11 +- etc/notes/CHANGES_5.0.0.md | 4 + src/bson.ts | 31 +-- test/benchmarks/driverBench/index.js | 6 - test/tools/utils.ts | 7 - test/unit/bson.test.js | 33 +-- test/unit/commands.test.ts | 266 +++++++------------------ 11 files changed, 90 insertions(+), 405 deletions(-) delete mode 100755 .evergreen/run-bson-ext-test.sh diff --git a/.evergreen/config.in.yml b/.evergreen/config.in.yml index aeec8a62a97..3f190a3145d 100644 --- a/.evergreen/config.in.yml +++ b/.evergreen/config.in.yml @@ -832,21 +832,6 @@ functions: ${PREPARE_SHELL} ${PROJECT_DIRECTORY}/.evergreen/run-lambda-aws-tests.sh - "run bson-ext test": - - command: subprocess.exec - type: test - params: - working_dir: "src" - timeout_secs: 60 - env: - PROJECT_DIRECTORY: ${PROJECT_DIRECTORY} - MONGODB_URI: ${MONGODB_URI} - TEST_NPM_SCRIPT: ${TEST_NPM_SCRIPT} - binary: bash - args: - - '${PROJECT_DIRECTORY}/.evergreen/run-bson-ext-test.sh' - - "upload test results": # Upload the xunit-format test results. - command: attach.xunit_results diff --git a/.evergreen/config.yml b/.evergreen/config.yml index 29dcbcebcf5..739ceaf64f0 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -790,19 +790,6 @@ functions: script: | ${PREPARE_SHELL} ${PROJECT_DIRECTORY}/.evergreen/run-lambda-aws-tests.sh - run bson-ext test: - - command: subprocess.exec - type: test - params: - working_dir: src - timeout_secs: 60 - env: - PROJECT_DIRECTORY: ${PROJECT_DIRECTORY} - MONGODB_URI: ${MONGODB_URI} - TEST_NPM_SCRIPT: ${TEST_NPM_SCRIPT} - binary: bash - args: - - ${PROJECT_DIRECTORY}/.evergreen/run-bson-ext-test.sh upload test results: - command: attach.xunit_results params: @@ -2131,40 +2118,6 @@ tasks: variant: '*' status: '*' patch_optional: true - - name: run-bson-ext-integration - tags: - - run-custom-dependency-tests - commands: - - func: install dependencies - vars: - NODE_LTS_NAME: fermium - - func: bootstrap mongo-orchestration - vars: - VERSION: '5.0' - TOPOLOGY: server - AUTH: auth - - name: run-bson-ext-integration - func: run bson-ext test - vars: - NODE_LTS_NAME: fermium - TEST_NPM_SCRIPT: check:test - - name: run-bson-ext-unit - tags: - - run-custom-dependency-tests - commands: - - func: install dependencies - vars: - NODE_LTS_NAME: fermium - - func: bootstrap mongo-orchestration - vars: - VERSION: '5.0' - TOPOLOGY: server - AUTH: auth - - name: run-bson-ext-unit - func: run bson-ext test - vars: - NODE_LTS_NAME: fermium - TEST_NPM_SCRIPT: check:unit - name: run-custom-csfle-tests-5.0-pinned-commit tags: - run-custom-dependency-tests @@ -3060,8 +3013,6 @@ buildvariants: display_name: Custom Dependency Version Test run_on: rhel80-large tasks: - - run-bson-ext-integration - - run-bson-ext-unit - run-custom-csfle-tests-5.0-pinned-commit - run-custom-csfle-tests-5.0-master - run-custom-csfle-tests-rapid-pinned-commit diff --git a/.evergreen/generate_evergreen_tasks.js b/.evergreen/generate_evergreen_tasks.js index 19315718be2..295d239baf2 100644 --- a/.evergreen/generate_evergreen_tasks.js +++ b/.evergreen/generate_evergreen_tasks.js @@ -576,46 +576,7 @@ BUILD_VARIANTS.push({ tasks: AWS_AUTH_TASKS }); -const oneOffFuncs = [ - { - name: 'run-bson-ext-integration', - func: 'run bson-ext test', - vars: { - NODE_LTS_NAME: LOWEST_LTS, - TEST_NPM_SCRIPT: 'check:test' - } - }, - { - name: 'run-bson-ext-unit', - func: 'run bson-ext test', - vars: { - NODE_LTS_NAME: LOWEST_LTS, - TEST_NPM_SCRIPT: 'check:unit' - } - } -]; - -const oneOffFuncAsTasks = oneOffFuncs.map(oneOffFunc => ({ - name: oneOffFunc.name, - tags: ['run-custom-dependency-tests'], - commands: [ - { - func: 'install dependencies', - vars: { - NODE_LTS_NAME: LOWEST_LTS - } - }, - { - func: 'bootstrap mongo-orchestration', - vars: { - VERSION: '5.0', - TOPOLOGY: 'server', - AUTH: 'auth' - } - }, - oneOffFunc - ] -})); +const oneOffFuncAsTasks = [] for (const version of ['5.0', 'rapid', 'latest']) { for (const ref of ['ddb19ae22dc4a5f8b9208096f69fc23e19bae6c9', 'master']) { diff --git a/.evergreen/run-bson-ext-test.sh b/.evergreen/run-bson-ext-test.sh deleted file mode 100755 index 112ba611aa5..00000000000 --- a/.evergreen/run-bson-ext-test.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash - -[ -s "$PROJECT_DIRECTORY/node-artifacts/nvm/nvm.sh" ] && source "$PROJECT_DIRECTORY"/node-artifacts/nvm/nvm.sh - -set -o xtrace # Write all commands first to stderr -set -o errexit # Exit the script with error if any of the commands fail - -# Supported/used environment variables: -# SSL Set to enable SSL. Defaults to "nossl" -# MONGODB_URI Set the suggested connection MONGODB_URI (including credentials and topology info) -# TEST_NPM_SCRIPT Script to npm run. Defaults to "check:test" - -MONGODB_URI=${MONGODB_URI:-} -TEST_NPM_SCRIPT=${TEST_NPM_SCRIPT:-check:test} - -# ssl setup -SSL=${SSL:-nossl} -if [ "$SSL" != "nossl" ]; then - export SSL_KEY_FILE="$DRIVERS_TOOLS/.evergreen/x509gen/client.pem" - export SSL_CA_FILE="$DRIVERS_TOOLS/.evergreen/x509gen/ca.pem" -fi - -# run tests -echo "Running $AUTH tests over $SSL, connecting to $MONGODB_URI" - -npm install mongodb-client-encryption@">=2.3.0" -npm install bson-ext - -export MONGODB_API_VERSION=${MONGODB_API_VERSION} -export MONGODB_URI=${MONGODB_URI} - -npm run "${TEST_NPM_SCRIPT}" diff --git a/README.md b/README.md index 94131a8f637..9b5d63d59f9 100644 --- a/README.md +++ b/README.md @@ -73,12 +73,13 @@ npm install -D @types/node ## Troubleshooting -The MongoDB driver depends on several other packages. These are: +The MongoDB driver can optionally be enhanced by the following feature packages: -- [bson](https://github.com/mongodb/js-bson) -- [bson-ext](https://github.com/mongodb-js/bson-ext) -- [kerberos](https://github.com/mongodb-js/kerberos) -- [mongodb-client-encryption](https://github.com/mongodb/libmongocrypt#readme) +- [Zstd network compression](https://github.com/mongodb-js/zstd) +- [Snappy network compression](https://github.com/Brooooooklyn/snappy) +- [GSSAPI / SSPI / Kerberos authentication](https://github.com/mongodb-js/kerberos) +- [AWS authentication](https://github.com/aws/aws-sdk-js-v3/tree/main/packages/credential-providers) +- [MongoDB field level and queryable encryption](https://github.com/mongodb/libmongocrypt#readme) Some of these packages include native C++ extensions. Consult the [trouble shooting guide here](https://github.com/mongodb/node-mongodb-native/blob/HEAD/etc/notes/native-extensions.md) if you run into issues. diff --git a/etc/notes/CHANGES_5.0.0.md b/etc/notes/CHANGES_5.0.0.md index 048e2bbef02..d57e52963c5 100644 --- a/etc/notes/CHANGES_5.0.0.md +++ b/etc/notes/CHANGES_5.0.0.md @@ -191,3 +191,7 @@ await collection.insertMany([{ name: 'fido' }, { name: 'luna' }]) The `keepGoing` option was a legacy name for setting `ordered` to `false` for bulk inserts. It was only supported by the legacy `collection.insert()` method which is now removed as noted above. + +### `bson-ext` support removed + +The `bson-ext` package will no longer automatically import and supplant the `bson` dependency. diff --git a/src/bson.ts b/src/bson.ts index 88a4dc9005e..4f20e636762 100644 --- a/src/bson.ts +++ b/src/bson.ts @@ -1,34 +1,14 @@ -import type { - calculateObjectSize as calculateObjectSizeFn, - deserialize as deserializeFn, - DeserializeOptions, - serialize as serializeFn, - SerializeOptions -} from 'bson'; - -/** @internal */ -// eslint-disable-next-line @typescript-eslint/no-var-requires -let BSON = require('bson'); - -try { - // Ensure you always wrap an optional require in the try block NODE-3199 - BSON = require('bson-ext'); -} catch {} // eslint-disable-line - -/** @internal */ -export const deserialize = BSON.deserialize as typeof deserializeFn; -/** @internal */ -export const serialize = BSON.serialize as typeof serializeFn; -/** @internal */ -export const calculateObjectSize = BSON.calculateObjectSize as typeof calculateObjectSizeFn; +import type { DeserializeOptions, SerializeOptions } from 'bson'; export { Binary, BSONRegExp, BSONSymbol, + calculateObjectSize, Code, DBRef, Decimal128, + deserialize, Document, Double, Int32, @@ -37,11 +17,10 @@ export { MaxKey, MinKey, ObjectId, + serialize, Timestamp } from 'bson'; - -/** @internal */ -export { BSON }; +export * as BSON from 'bson'; /** * BSON Serialization options. diff --git a/test/benchmarks/driverBench/index.js b/test/benchmarks/driverBench/index.js index c798e5d81bf..f9f420e2e94 100644 --- a/test/benchmarks/driverBench/index.js +++ b/test/benchmarks/driverBench/index.js @@ -8,12 +8,6 @@ let bsonType = 'js-bson'; // TODO(NODE-4606): test against different driver configurations in CI const BSON = require('bson'); -// try { -// BSON = require('bson-ext'); -// bsonType = 'bson-ext'; -// } catch (_) { -// // do not care -// } const { inspect } = require('util'); const { writeFile } = require('fs/promises'); diff --git a/test/tools/utils.ts b/test/tools/utils.ts index 75be56c9f3b..7c278840096 100644 --- a/test/tools/utils.ts +++ b/test/tools/utils.ts @@ -507,13 +507,6 @@ export class UnifiedTestSuiteBuilder { } } -/** Test whether the driver is using bson-ext */ -export function isBSONExtImported() { - // eslint-disable-next-line @typescript-eslint/no-var-requires - const driverBSON = require('../mongodb'); - return driverBSON.deserialize.toString().includes('[native code]'); -} - export const byStrings = (a: any, b: any) => { const res = `${a}`.localeCompare(`${b}`); return res < 0 ? -1 : res > 0 ? 1 : 0; diff --git a/test/unit/bson.test.js b/test/unit/bson.test.js index 465412f7be4..dbdbd1f27fb 100644 --- a/test/unit/bson.test.js +++ b/test/unit/bson.test.js @@ -2,7 +2,6 @@ const { expect } = require('chai'); const BSON = require('../mongodb'); -const { isBSONExtImported } = require('../tools/utils'); describe('When importing BSON', function () { const types = [ @@ -47,37 +46,7 @@ describe('When importing BSON', function () { }); } - describe('bson-ext', function () { - before(function () { - if (!isBSONExtImported()) { - this.skip(); - } - }); - - it('should be imported if it exists', function () { - expect(BSON.deserialize.toString()).to.include('[native code]'); - expect(BSON.serialize.toString()).to.include('[native code]'); - expect(BSON.calculateObjectSize.toString()).to.include('[native code]'); - }); - - testTypes(); - }); - - describe('js-bson', function () { - before(function () { - if (isBSONExtImported()) { - this.skip(); - } - }); - - it('should be imported by default', function () { - expect(BSON.deserialize.toString()).to.not.include('[native code]'); - expect(BSON.serialize.toString()).to.not.include('[native code]'); - expect(BSON.calculateObjectSize.toString()).to.not.include('[native code]'); - }); - - testTypes(); - }); + testTypes(); }); describe('MongoDB export', () => { diff --git a/test/unit/commands.test.ts b/test/unit/commands.test.ts index 1979655c586..111cd4bd1a0 100644 --- a/test/unit/commands.test.ts +++ b/test/unit/commands.test.ts @@ -42,232 +42,112 @@ const nKeyWithInvalidUtf8 = const msgBodyNKeyWithInvalidUtf8 = Buffer.from(nKeyWithInvalidUtf8, 'hex'); describe('BinMsg BSON utf8 validation', () => { - describe('when bson-ext is installed', () => { - beforeEach(function () { - if (!isBSONExtImported()) { - if (this.currentTest) - this.currentTest.skipReason = 'tests require driver to be using bson-ext'; - this.skip(); - } - }); + beforeEach(function () { + if (isBSONExtImported()) { + if (this.currentTest) this.currentTest.skipReason = 'tests require driver to be using bson'; + this.skip(); + } + }); - it('throws when invalid utf8 in writeErrors object regardless of options', () => { - // this is a sanity check to make sure nothing unexpected is happening in the deserialize method itself - const options = { validation: { utf8: { writeErrors: false } as const } }; - const deserializerCall = () => BSON.deserialize(invalidUtf8ErrorMsgDeserializeInput, options); - expect(deserializerCall).to.throw(Error, 'Invalid UTF8 string found'); - }); + it('bson correctly deserializes data with replacement characters for invalid utf8 in writeErrors object', () => { + // this is a sanity check to make sure nothing unexpected is happening in the deserialize method itself - context('when enableUtf8Validation option is not specified', () => { - const binMsgInvalidUtf8ErrorMsg = new BinMsg( - Buffer.alloc(0), - msgHeader, - msgBodyInvalidUtf8WriteErrors - ); + const options = { validation: { utf8: { writeErrors: false } as const } }; + const deserializerCall = () => BSON.deserialize(invalidUtf8ErrorMsgDeserializeInput, options); + expect(deserializerCall()).to.deep.equals(invalidUtf8InWriteErrorsJSON); + }); - const options = {}; - it('should validate the writeErrors key', () => { - expect(() => binMsgInvalidUtf8ErrorMsg.parse(options)).to.throw( - Error, - 'Invalid UTF8 string found' - ); - }); + context('when enableUtf8Validation option is not specified', () => { + const binMsgInvalidUtf8ErrorMsg = new BinMsg( + Buffer.alloc(0), + msgHeader, + msgBodyInvalidUtf8WriteErrors + ); - it('should validate keys other than the writeErrors key', () => { - const binMsgAnotherKeyWithInvalidUtf8 = new BinMsg( - Buffer.alloc(0), - msgHeader, - msgBodyNKeyWithInvalidUtf8 - ); - expect(() => binMsgAnotherKeyWithInvalidUtf8.parse(options)).to.throw( - Error, - 'Invalid UTF8 string found' - ); - }); + const options = {}; + it('does not validate the writeErrors key', () => { + expect(() => binMsgInvalidUtf8ErrorMsg.parse(options)).to.not.throw(); }); - context('when validation is disabled', () => { - const binMsgInvalidUtf8ErrorMsg = new BinMsg( + it('should validate keys other than the writeErrors key', () => { + const binMsgAnotherKeyWithInvalidUtf8 = new BinMsg( Buffer.alloc(0), msgHeader, - msgBodyInvalidUtf8WriteErrors + msgBodyNKeyWithInvalidUtf8 + ); + expect(() => binMsgAnotherKeyWithInvalidUtf8.parse(options)).to.throw( + BSONError, + 'Invalid UTF-8 string in BSON document' ); + }); + }); - const options = { enableUtf8Validation: false }; - it('should validate the writeErrors key', () => { - expect(() => binMsgInvalidUtf8ErrorMsg.parse(options)).to.throw( - Error, - 'Invalid UTF8 string found' - ); - }); + context('when validation is disabled', () => { + const binMsgInvalidUtf8ErrorMsg = new BinMsg( + Buffer.alloc(0), + msgHeader, + msgBodyInvalidUtf8WriteErrors + ); - it('should validate keys other than the writeErrors key', () => { - const binMsgAnotherKeyWithInvalidUtf8 = new BinMsg( - Buffer.alloc(0), - msgHeader, - msgBodyNKeyWithInvalidUtf8 - ); - expect(() => binMsgAnotherKeyWithInvalidUtf8.parse(options)).to.throw( - Error, - 'Invalid UTF8 string found' - ); - }); + const options = { enableUtf8Validation: false }; + it('should not validate the writeErrors key', () => { + expect(() => binMsgInvalidUtf8ErrorMsg.parse(options)).to.not.throw(); }); - it('should still validate for writeErrors if no validation specified', () => { - const binMsgInvalidUtf8ErrorMsg = new BinMsg( + it('should not validate keys other than the writeErrors key', () => { + const binMsgAnotherKeyWithInvalidUtf8 = new BinMsg( Buffer.alloc(0), msgHeader, - msgBodyInvalidUtf8WriteErrors + msgBodyNKeyWithInvalidUtf8 ); - const options = { - bsonRegExp: false, - promoteBuffers: false, - promoteLongs: true, - promoteValues: true - }; - expect(() => binMsgInvalidUtf8ErrorMsg.parse(options)).to.throw( - Error, - 'Invalid UTF8 string found' + expect(() => binMsgAnotherKeyWithInvalidUtf8.parse(options)).to.not.throw( + BSONError, + 'Invalid UTF-8 string in BSON document' ); }); - - context('utf8 validation enabled', () => { - const options = { enableUtf8Validation: true }; - it('should validate the writeErrors key', () => { - const binMsgInvalidUtf8ErrorMsg = new BinMsg( - Buffer.alloc(0), - msgHeader, - msgBodyInvalidUtf8WriteErrors - ); - expect(() => binMsgInvalidUtf8ErrorMsg.parse(options)).to.throw( - Error, - 'Invalid UTF8 string found' - ); - }); - - it('should validate keys other than the writeErrors key', () => { - const binMsgAnotherKeyWithInvalidUtf8 = new BinMsg( - Buffer.alloc(0), - msgHeader, - msgBodyNKeyWithInvalidUtf8 - ); - expect(() => binMsgAnotherKeyWithInvalidUtf8.parse(options)).to.throw( - Error, - 'Invalid UTF8 string found' - ); - }); - }); }); - describe('when js-bson is installed', () => { - beforeEach(function () { - if (isBSONExtImported()) { - if (this.currentTest) this.currentTest.skipReason = 'tests require driver to be using bson'; - this.skip(); - } - }); - - it('bson correctly deserializes data with replacement characters for invalid utf8 in writeErrors object', () => { - // this is a sanity check to make sure nothing unexpected is happening in the deserialize method itself - - const options = { validation: { utf8: { writeErrors: false } as const } }; - const deserializerCall = () => BSON.deserialize(invalidUtf8ErrorMsgDeserializeInput, options); - expect(deserializerCall()).to.deep.equals(invalidUtf8InWriteErrorsJSON); - }); + it('should by default disable validation for writeErrors if no validation specified', () => { + const binMsgInvalidUtf8ErrorMsg = new BinMsg( + Buffer.alloc(0), + msgHeader, + msgBodyInvalidUtf8WriteErrors + ); + const options = { + bsonRegExp: false, + promoteBuffers: false, + promoteLongs: true, + promoteValues: true + }; + + expect(() => binMsgInvalidUtf8ErrorMsg.parse(options)).to.not.throw(); + }); - context('when enableUtf8Validation option is not specified', () => { + context('utf8 validation enabled', () => { + const options = { enableUtf8Validation: true }; + it('should not validate the writeErrors key', () => { const binMsgInvalidUtf8ErrorMsg = new BinMsg( Buffer.alloc(0), msgHeader, msgBodyInvalidUtf8WriteErrors ); - const options = {}; - it('does not validate the writeErrors key', () => { - expect(() => binMsgInvalidUtf8ErrorMsg.parse(options)).to.not.throw(); - }); - - it('should validate keys other than the writeErrors key', () => { - const binMsgAnotherKeyWithInvalidUtf8 = new BinMsg( - Buffer.alloc(0), - msgHeader, - msgBodyNKeyWithInvalidUtf8 - ); - expect(() => binMsgAnotherKeyWithInvalidUtf8.parse(options)).to.throw( - BSONError, - 'Invalid UTF-8 string in BSON document' - ); - }); - }); - - context('when validation is disabled', () => { - const binMsgInvalidUtf8ErrorMsg = new BinMsg( - Buffer.alloc(0), - msgHeader, - msgBodyInvalidUtf8WriteErrors + expect(() => binMsgInvalidUtf8ErrorMsg.parse(options)).not.to.throw( + BSONError, + 'Invalid UTF-8 string in BSON document' ); - - const options = { enableUtf8Validation: false }; - it('should not validate the writeErrors key', () => { - expect(() => binMsgInvalidUtf8ErrorMsg.parse(options)).to.not.throw(); - }); - - it('should not validate keys other than the writeErrors key', () => { - const binMsgAnotherKeyWithInvalidUtf8 = new BinMsg( - Buffer.alloc(0), - msgHeader, - msgBodyNKeyWithInvalidUtf8 - ); - expect(() => binMsgAnotherKeyWithInvalidUtf8.parse(options)).to.not.throw( - BSONError, - 'Invalid UTF-8 string in BSON document' - ); - }); }); - it('should by default disable validation for writeErrors if no validation specified', () => { - const binMsgInvalidUtf8ErrorMsg = new BinMsg( + it('should validate keys other than the writeErrors key', () => { + const binMsgAnotherKeyWithInvalidUtf8 = new BinMsg( Buffer.alloc(0), msgHeader, - msgBodyInvalidUtf8WriteErrors + msgBodyNKeyWithInvalidUtf8 + ); + expect(() => binMsgAnotherKeyWithInvalidUtf8.parse(options)).to.throw( + BSONError, + 'Invalid UTF-8 string in BSON document' ); - const options = { - bsonRegExp: false, - promoteBuffers: false, - promoteLongs: true, - promoteValues: true - }; - - expect(() => binMsgInvalidUtf8ErrorMsg.parse(options)).to.not.throw(); - }); - - context('utf8 validation enabled', () => { - const options = { enableUtf8Validation: true }; - it('should not validate the writeErrors key', () => { - const binMsgInvalidUtf8ErrorMsg = new BinMsg( - Buffer.alloc(0), - msgHeader, - msgBodyInvalidUtf8WriteErrors - ); - - expect(() => binMsgInvalidUtf8ErrorMsg.parse(options)).not.to.throw( - BSONError, - 'Invalid UTF-8 string in BSON document' - ); - }); - - it('should validate keys other than the writeErrors key', () => { - const binMsgAnotherKeyWithInvalidUtf8 = new BinMsg( - Buffer.alloc(0), - msgHeader, - msgBodyNKeyWithInvalidUtf8 - ); - expect(() => binMsgAnotherKeyWithInvalidUtf8.parse(options)).to.throw( - BSONError, - 'Invalid UTF-8 string in BSON document' - ); - }); }); }); }); From f4141e1706b79c7568a0a29022d952c56296c36f Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Fri, 13 Jan 2023 14:02:38 -0500 Subject: [PATCH 2/7] tmp fix on import --- src/bson.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/bson.ts b/src/bson.ts index 4f20e636762..e3fbd5b4438 100644 --- a/src/bson.ts +++ b/src/bson.ts @@ -20,7 +20,12 @@ export { serialize, Timestamp } from 'bson'; -export * as BSON from 'bson'; + +// TODO(NODE-4867): fix with bson v5 +// eslint-disable-next-line @typescript-eslint/no-var-requires +const BSON = require('bson'); + +export { BSON }; /** * BSON Serialization options. From 083d42cbd65236572518b94514163184547135df Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Fri, 13 Jan 2023 15:17:05 -0500 Subject: [PATCH 3/7] fix unit --- test/unit/commands.test.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/test/unit/commands.test.ts b/test/unit/commands.test.ts index 111cd4bd1a0..147aafb7888 100644 --- a/test/unit/commands.test.ts +++ b/test/unit/commands.test.ts @@ -3,7 +3,6 @@ import { expect } from 'chai'; import * as BSON from '../mongodb'; import { BinMsg, MessageHeader } from '../mongodb'; -import { isBSONExtImported } from '../tools/utils'; const msgHeader: MessageHeader = { length: 735, @@ -42,13 +41,6 @@ const nKeyWithInvalidUtf8 = const msgBodyNKeyWithInvalidUtf8 = Buffer.from(nKeyWithInvalidUtf8, 'hex'); describe('BinMsg BSON utf8 validation', () => { - beforeEach(function () { - if (isBSONExtImported()) { - if (this.currentTest) this.currentTest.skipReason = 'tests require driver to be using bson'; - this.skip(); - } - }); - it('bson correctly deserializes data with replacement characters for invalid utf8 in writeErrors object', () => { // this is a sanity check to make sure nothing unexpected is happening in the deserialize method itself From b62ad46b648257e41db6d39851665ad2431085dc Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Fri, 13 Jan 2023 15:19:37 -0500 Subject: [PATCH 4/7] fix lint --- src/bson.ts | 1 + src/collection.ts | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bson.ts b/src/bson.ts index e3fbd5b4438..4c3d8657416 100644 --- a/src/bson.ts +++ b/src/bson.ts @@ -22,6 +22,7 @@ export { } from 'bson'; // TODO(NODE-4867): fix with bson v5 +/** @internal */ // eslint-disable-next-line @typescript-eslint/no-var-requires const BSON = require('bson'); diff --git a/src/collection.ts b/src/collection.ts index 5babeaa8edc..75d597aa639 100644 --- a/src/collection.ts +++ b/src/collection.ts @@ -86,7 +86,6 @@ import { Callback, checkCollectionName, DEFAULT_PK_FACTORY, - emitWarningOnce, MongoDBNamespace, normalizeHintField, resolveOptions From b4a25f385329f005f15417a97b906e344e5550c7 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Thu, 19 Jan 2023 10:21:32 -0500 Subject: [PATCH 5/7] Apply suggestions from code review Co-authored-by: Durran Jordan --- test/unit/commands.test.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/unit/commands.test.ts b/test/unit/commands.test.ts index 147aafb7888..0ff4f0c5ff1 100644 --- a/test/unit/commands.test.ts +++ b/test/unit/commands.test.ts @@ -41,7 +41,7 @@ const nKeyWithInvalidUtf8 = const msgBodyNKeyWithInvalidUtf8 = Buffer.from(nKeyWithInvalidUtf8, 'hex'); describe('BinMsg BSON utf8 validation', () => { - it('bson correctly deserializes data with replacement characters for invalid utf8 in writeErrors object', () => { + it('correctly deserializes data with replacement characters for invalid utf8 in writeErrors object', () => { // this is a sanity check to make sure nothing unexpected is happening in the deserialize method itself const options = { validation: { utf8: { writeErrors: false } as const } }; @@ -61,7 +61,7 @@ describe('BinMsg BSON utf8 validation', () => { expect(() => binMsgInvalidUtf8ErrorMsg.parse(options)).to.not.throw(); }); - it('should validate keys other than the writeErrors key', () => { + it('validates keys other than the writeErrors key', () => { const binMsgAnotherKeyWithInvalidUtf8 = new BinMsg( Buffer.alloc(0), msgHeader, @@ -86,7 +86,7 @@ describe('BinMsg BSON utf8 validation', () => { expect(() => binMsgInvalidUtf8ErrorMsg.parse(options)).to.not.throw(); }); - it('should not validate keys other than the writeErrors key', () => { + it('does not validate keys other than the writeErrors key', () => { const binMsgAnotherKeyWithInvalidUtf8 = new BinMsg( Buffer.alloc(0), msgHeader, @@ -99,7 +99,7 @@ describe('BinMsg BSON utf8 validation', () => { }); }); - it('should by default disable validation for writeErrors if no validation specified', () => { + it('disables validation by default for writeErrors if no validation specified', () => { const binMsgInvalidUtf8ErrorMsg = new BinMsg( Buffer.alloc(0), msgHeader, @@ -117,7 +117,7 @@ describe('BinMsg BSON utf8 validation', () => { context('utf8 validation enabled', () => { const options = { enableUtf8Validation: true }; - it('should not validate the writeErrors key', () => { + it('does not validate the writeErrors key', () => { const binMsgInvalidUtf8ErrorMsg = new BinMsg( Buffer.alloc(0), msgHeader, @@ -130,7 +130,7 @@ describe('BinMsg BSON utf8 validation', () => { ); }); - it('should validate keys other than the writeErrors key', () => { + it('validates keys other than the writeErrors key', () => { const binMsgAnotherKeyWithInvalidUtf8 = new BinMsg( Buffer.alloc(0), msgHeader, From 627f867eaeaf9b7a4b8e417633f398b5cd2c96d6 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Thu, 19 Jan 2023 10:21:56 -0500 Subject: [PATCH 6/7] rm function --- test/unit/bson.test.js | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/test/unit/bson.test.js b/test/unit/bson.test.js index dbdbd1f27fb..8267c6fa198 100644 --- a/test/unit/bson.test.js +++ b/test/unit/bson.test.js @@ -26,27 +26,23 @@ describe('When importing BSON', function () { bsonRegExp: true }; - function testTypes() { - for (const [type, ctorArg] of types) { - it(`should correctly round trip ${type}`, function () { - const typeCtor = BSON[type]; - expect(typeCtor).to.be.a('function'); - const doc = { key: new typeCtor(ctorArg) }; - const outputDoc = BSON.deserialize(BSON.serialize(doc), options); - expect(outputDoc).to.have.property('key').that.is.instanceOf(typeCtor); - expect(outputDoc).to.deep.equal(doc); - }); - } - - it('should correctly round trip Map', function () { - expect(BSON.Map).to.be.a('function'); - const doc = { key: new BSON.Map([['2', 2]]) }; - const outputDoc = BSON.deserialize(BSON.serialize(doc)); - expect(outputDoc).to.have.nested.property('key.2', 2); + for (const [type, ctorArg] of types) { + it(`should correctly round trip ${type}`, function () { + const typeCtor = BSON[type]; + expect(typeCtor).to.be.a('function'); + const doc = { key: new typeCtor(ctorArg) }; + const outputDoc = BSON.deserialize(BSON.serialize(doc), options); + expect(outputDoc).to.have.property('key').that.is.instanceOf(typeCtor); + expect(outputDoc).to.deep.equal(doc); }); } - testTypes(); + it('should correctly round trip Map', function () { + expect(BSON.Map).to.be.a('function'); + const doc = { key: new BSON.Map([['2', 2]]) }; + const outputDoc = BSON.deserialize(BSON.serialize(doc)); + expect(outputDoc).to.have.nested.property('key.2', 2); + }); }); describe('MongoDB export', () => { From c2faebab166f0c53db0b60bc4448876e147b8421 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Thu, 19 Jan 2023 14:13:37 -0500 Subject: [PATCH 7/7] Update extensions section --- README.md | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 9b5d63d59f9..ea175a50e7d 100644 --- a/README.md +++ b/README.md @@ -71,17 +71,24 @@ If you are a Typescript user, you will need the Node.js type definitions to use npm install -D @types/node ``` -## Troubleshooting +## Driver Extensions The MongoDB driver can optionally be enhanced by the following feature packages: -- [Zstd network compression](https://github.com/mongodb-js/zstd) -- [Snappy network compression](https://github.com/Brooooooklyn/snappy) -- [GSSAPI / SSPI / Kerberos authentication](https://github.com/mongodb-js/kerberos) -- [AWS authentication](https://github.com/aws/aws-sdk-js-v3/tree/main/packages/credential-providers) -- [MongoDB field level and queryable encryption](https://github.com/mongodb/libmongocrypt#readme) +Maintained by MongoDB: + +- Zstd network compression - [@mongodb-js/zstd](https://github.com/mongodb-js/zstd) +- MongoDB field level and queryable encryption - [mongodb-client-encryption](https://github.com/mongodb/libmongocrypt#readme) +- GSSAPI / SSPI / Kerberos authentication - [kerberos](https://github.com/mongodb-js/kerberos) + +Some of these packages include native C++ extensions. +Consult the [trouble shooting guide here](https://github.com/mongodb/node-mongodb-native/blob/HEAD/etc/notes/native-extensions.md) if you run into compilation issues. + +Third party: + +- Snappy network compression - [snappy](https://github.com/Brooooooklyn/snappy) +- AWS authentication - [@aws-sdk/credential-providers](https://github.com/aws/aws-sdk-js-v3/tree/main/packages/credential-providers) -Some of these packages include native C++ extensions. Consult the [trouble shooting guide here](https://github.com/mongodb/node-mongodb-native/blob/HEAD/etc/notes/native-extensions.md) if you run into issues. ## Quick Start