Skip to content
This repository was archived by the owner on Feb 4, 2022. It is now read-only.

fix(wireprotocol): only send bypassDocumentValidation if true #317

Merged
merged 3 commits into from
Jun 14, 2018
Merged
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 lib/wireprotocol/2_6_support.js
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ var executeWrite = function(pool, bson, type, opsField, ns, ops, options, callba
}

// Do we have bypassDocumentValidation set, then enable it on the write command
if (typeof options.bypassDocumentValidation === 'boolean') {
if (options.bypassDocumentValidation === true) {
writeCommand.bypassDocumentValidation = options.bypassDocumentValidation;
}

2 changes: 1 addition & 1 deletion lib/wireprotocol/3_2_support.js
Original file line number Diff line number Diff line change
@@ -101,7 +101,7 @@ var executeWrite = function(pool, bson, type, opsField, ns, ops, options, callba
}

// Do we have bypassDocumentValidation set, then enable it on the write command
if (typeof options.bypassDocumentValidation === 'boolean') {
if (options.bypassDocumentValidation === true) {
writeCommand.bypassDocumentValidation = options.bypassDocumentValidation;
}

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@
"mongodb-mock-server": "^1.0.0",
"mongodb-test-runner": "^1.1.18",
"prettier": "~1.12.0",
"sinon": "^6.0.0",
"snappy": "^6.0.1"
},
"peerOptionalDependencies": {
47 changes: 47 additions & 0 deletions test/tests/unit/wire_protocol_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use strict';

const chai = require('chai');
const expect = chai.expect;
const bson = require('bson');
const sinon = require('sinon');
const Pool = require('../../../lib/connection/pool.js');
const wireProtocol2_6 = require('../../../lib/wireprotocol/2_6_support.js');
const wireProtocol3_2 = require('../../../lib/wireprotocol/3_2_support.js');

describe('WireProtocol', function() {
it('2.6 should only set bypassDocumentValidation to true if explicitly set by user to true', function() {
testPoolWrite(true, new wireProtocol2_6(), true);
});

it('2.6 should not set bypassDocumentValidation to anything if not explicitly set by user to true', function() {
testPoolWrite(false, new wireProtocol2_6(), undefined);
});

it('3.2 should only set bypassDocumentValidation to true if explicitly set by user to true', function() {
testPoolWrite(true, new wireProtocol3_2(), true);
});

it('3.2 should not set bypassDocumentValidation to anything if not explicitly set by user to true', function() {
testPoolWrite(false, new wireProtocol3_2(), undefined);
});

function testPoolWrite(bypassDocumentValidation, wireProtocol, expected) {
const pool = sinon.createStubInstance(Pool);
const isMaster = {};
const ns = 'fake.namespace';
const ops = [{ a: 1 }, { b: 2 }];
const options = { bypassDocumentValidation: bypassDocumentValidation };

wireProtocol.insert(pool, isMaster, ns, bson, ops, options, () => {});

if (expected) {
expect(pool.write.lastCall.args[0])
.to.have.nested.property('query.bypassDocumentValidation')
.that.equals(expected);
} else {
expect(pool.write.lastCall.args[0]).to.not.have.nested.property(
'query.bypassDocumentValidation'
);
}
}
});