Skip to content

Commit

Permalink
asdf
Browse files Browse the repository at this point in the history
  • Loading branch information
baileympearson committed Aug 30, 2024
1 parent e71e98e commit cc1f36c
Showing 1 changed file with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { expect } from 'chai';
import * as net from 'net';
import * as sinon from 'sinon';
import { buffer } from 'stream/consumers';

import {
BSON,
Expand All @@ -9,7 +11,8 @@ import {
MongoDBResponse,
MongoError,
MongoServerError,
OpMsgResponse
OpMsgResponse,
serialize
} from '../../../mongodb';

const EXPECTED_VALIDATION_DISABLED_ARGUMENT = {
Expand Down Expand Up @@ -157,15 +160,36 @@ describe('class MongoDBResponse', () => {
);
});

describe('utf8 validation with cursors', function () {
describe.only('utf8 validation with cursors', function () {
let client: MongoClient;
let collection: Collection;

beforeEach(async function () {
client = this.configuration.newClient();
await client.connect();
const db = client.db('test');
collection = db.collection('invalidutf8');
collection = db.collection('invalidutf');

await collection.deleteMany({});

const stub = sinon.stub(net.Socket.prototype, 'write').callsFake(function (...args) {
if (args[0].toString('hex').includes('c3a9')) {
const buffer = Buffer.from(args[0].toString('hex').replace('c3a9', 'c301'), 'hex');
const result = stub.wrappedMethod.apply(this, [buffer]);
sinon.restore();
return result;
}
const result = stub.wrappedMethod.apply(this, args);
return result;
});

const document = {
field: 'é'
};

await collection.insertOne(document);

sinon.restore();
});

afterEach(async function () {
Expand Down Expand Up @@ -275,7 +299,8 @@ describe('utf8 validation with cursors', function () {
it('a for-await loop throw a BSON error', async function () {
await expectReject(
async () => {
for await (const doc of collection.find({}));
for await (const doc of collection.find({})) {
}
},
{ errorClass: BSONError, regex: /Invalid UTF-8 string in BSON document/ }
);
Expand Down

0 comments on commit cc1f36c

Please sign in to comment.