From 42fbc0b3a2433656ae3812f4e7b6ac381caddafa Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Wed, 3 Sep 2025 22:28:40 +0200 Subject: [PATCH 1/3] chore: bump various deps to latest --- package.json | 18 ++++++++---------- test/index.ts | 16 ++++++++++++---- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 7acfe5f..41837e6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mongodb-wp-proxy", - "version": "1.0.1", + "version": "1.0.2", "description": "A logging mongodb wire protocol proxy", "keywords": [ "mongodb", @@ -33,9 +33,7 @@ ], "scripts": { "lint": "eslint {src,test}/**/*.ts", - "pretestonly": "mongodb-runner start --port=27018", - "posttestonly": "mongodb-runner stop --port=27018", - "testonly": "nyc mocha --colors -r ts-node/register test/*.ts", + "testonly": "mongodb-runner exec -t standalone -- nyc mocha --colors -r ts-node/register test/*.ts", "test": "npm run lint && npm run build && npm run testonly", "build": "npm run compile-ts && gen-esm-wrapper . ./.esm-wrapper.mjs", "prepack": "npm run build", @@ -43,11 +41,11 @@ }, "license": "Apache-2.0", "dependencies": { - "bson": "^4.4.1" + "bson": "^6.10.4" }, "devDependencies": { "@types/mocha": "^8.0.3", - "@types/node": "^16.4.10", + "@types/node": "^24.3.0", "@typescript-eslint/eslint-plugin": "^5.30.7", "@typescript-eslint/parser": "^5.30.7", "eslint": "^7.9.0", @@ -59,10 +57,10 @@ "eslint-plugin-standard": "^4.0.1", "gen-esm-wrapper": "^1.1.0", "mocha": "^8.1.3", - "mongodb": "^4.0.1", - "mongodb-runner": "^4.8.3", + "mongodb": "^6.19.0", + "mongodb-runner": "^5.9.2", "nyc": "^15.1.0", - "ts-node": "^10.9.1", - "typescript": "^4.7.4" + "ts-node": "^10.9.2", + "typescript": "^5.9.2" } } diff --git a/test/index.ts b/test/index.ts index 03f5d5c..0c7e0fb 100644 --- a/test/index.ts +++ b/test/index.ts @@ -6,6 +6,14 @@ import { EJSON } from 'bson'; import path from 'path'; import { once } from 'events'; +let hostport: string; +before(() => { + if (!process.env.MONGODB_HOSTPORT) { + throw new Error('MONGODB_HOSTPORT not set'); + } + hostport = process.env.MONGODB_HOSTPORT; +}); + describe('Proxy', function() { this.timeout(10_000); @@ -16,9 +24,9 @@ describe('Proxy', function() { beforeEach(async() => { events = []; - proxy = new Proxy({ host: 'localhost', port: 27018 }); + proxy = new Proxy({ host: hostport.split(':')[0], port: +hostport.split(':')[1] }); proxy.on('newConnection', (conn: any) => { - conn.on('connectionEnded', (source: string) => events.push({ ev: 'connecionEnded', source })); + conn.on('connectionEnded', (source: string) => events.push({ ev: 'connectionEnded', source })); conn.on('connectionError', (source: string, err: Error) => events.push({ ev: 'connectionError', source, err })); conn.on('message', (source: string, msg: any) => events.push({ ev: 'message', source, msg })); conn.on('parseError', (source: string, err: Error) => events.push({ ev: 'parseError', source, err })); @@ -62,7 +70,7 @@ describe('bin', function() { proc = childProcess.spawn('ts-node', [ '-P', path.join(__dirname, '..', 'tsconfig.json'), path.join(__dirname, '..', 'src', 'cli.ts'), - 'localhost:27018', 'localhost:0' + hostport, 'localhost:0' ], { stdio: 'pipe' }); port = 0; await new Promise((resolve) => { @@ -107,7 +115,7 @@ describe('bin', function() { '-P', path.join(__dirname, '..', 'tsconfig.json'), path.join(__dirname, '..', 'src', 'cli.ts'), '--ndjson', - 'localhost:27018', 'localhost:0' + hostport, 'localhost:0' ], { stdio: 'pipe' }); port = 0; await new Promise((resolve) => { From 6b310fecb9a1ce97ca3d47ca547f5764380a7134 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Wed, 3 Sep 2025 22:28:56 +0200 Subject: [PATCH 2/3] feat: add sasl payload decoding support --- src/parse.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/parse.ts b/src/parse.ts index 8154bd0..34fc9b6 100644 --- a/src/parse.ts +++ b/src/parse.ts @@ -1,6 +1,6 @@ import zlib from 'zlib'; import { promisify, TextDecoder } from 'util'; -import { deserialize } from 'bson'; +import { type Binary, deserialize } from 'bson'; class MessageHeader { messageLength: number; @@ -54,9 +54,24 @@ type OpContents = OpMsg | OpReply | OpUpdate | OpInsert | OpQuery | OpGetMore | class BSONBuffer { data: any; + decodedPayload?: any; constructor(buf: Uint8Array) { this.data = deserialize(buf); + let payload: undefined | Binary; + if ((this.data.saslStart || this.data.saslContinue || this.data.conversationId) && + this.data.payload?._bsontype === 'Binary') { + payload = this.data.payload; + } + if (this.data.speculativeAuthenticate?.payload?._bsontype === 'Binary') { + payload = this.data.speculativeAuthenticate.payload; + } + try { + if (payload) { + this.decodedPayload = deserialize(payload.value()); + } + } catch (err) { + } } } From 100218197f3e5d050f835bf24158555cd9eaeacd Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Wed, 3 Sep 2025 22:30:09 +0200 Subject: [PATCH 3/3] feat: bump GHA Node.js versions --- .github/workflows/nodejs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 3201787..3724b7b 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -9,7 +9,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - node-version: [12.x, 14.x, 16.x] + node-version: [16.x, 20.x, 24.x] runs-on: ${{matrix.os}} steps: - uses: actions/checkout@v2