Skip to content
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 .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 8 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -33,21 +33,19 @@
],
"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",
"compile-ts": "tsc -p tsconfig.json"
},
"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",
Expand All @@ -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"
}
}
17 changes: 16 additions & 1 deletion src/parse.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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) {
}
}
}

Expand Down
16 changes: 12 additions & 4 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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 }));
Expand Down Expand Up @@ -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<void>((resolve) => {
Expand Down Expand Up @@ -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<void>((resolve) => {
Expand Down