This repository has been archived by the owner on Feb 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(wireprotocol): only send bypassDocumentValidation if true
The bypassDocumentValidation key will only be set if it explicitly receives a true, otherwise it remains undefined. Fixes NODE-1492
- Loading branch information
Sophie Saskin
authored
Jun 14, 2018
1 parent
6fec2ce
commit a81678b
Showing
4 changed files
with
50 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
); | ||
} | ||
} | ||
}); |