Skip to content

Commit 6150a8d

Browse files
committed
test(NODE-3719): reorganize spec tests for visibility
1 parent 8305bdf commit 6150a8d

File tree

3 files changed

+41
-34
lines changed

3 files changed

+41
-34
lines changed

test/node/bson_corpus.prose.test.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use strict';
2+
3+
const BSON = require('../register-bson');
4+
const BSONRegExp = BSON.BSONRegExp;
5+
6+
describe('BSON Corpus Prose Tests', function () {
7+
/**
8+
* The BSON spec uses null-terminated strings to represent document field names and
9+
* regex components (i.e. pattern and flags/options). Drivers MUST assert that null
10+
* bytes are prohibited in the following contexts when encoding BSON (i.e. creating
11+
* raw BSON bytes or constructing BSON-specific type classes):
12+
* - Field name within a root document
13+
* - Field name within a sub-document
14+
* - Pattern for a regular expression
15+
* - Flags/options for a regular expression
16+
* Depending on how drivers implement BSON encoding, they MAY expect an error when
17+
* constructing a type class (e.g. BSON Document or Regex class) or when encoding a
18+
* language representation to BSON (e.g. converting a dictionary, which might allow
19+
* null bytes in its keys, to raw BSON bytes).
20+
*/
21+
describe('1. Prohibit null bytes in null-terminated strings when encoding BSON', () => {
22+
it('Field name within a root document', () => {
23+
expect(() => BSON.serialize({ 'a\x00b': 1 })).to.throw(/null bytes/);
24+
});
25+
26+
it('Field name within a sub-document', () => {
27+
expect(() => BSON.serialize({ a: { 'a\x00b': 1 } })).to.throw(/null bytes/);
28+
});
29+
30+
it('Pattern for a regular expression', () => {
31+
// eslint-disable-next-line no-control-regex
32+
expect(() => BSON.serialize({ a: new RegExp('a\x00b') })).to.throw(/null bytes/);
33+
expect(() => BSON.serialize({ a: new BSONRegExp('a\x00b') })).to.throw(/null bytes/);
34+
});
35+
36+
it('Flags/options for a regular expression', () => {
37+
expect(() => BSON.serialize({ a: new BSONRegExp('a', 'i\x00m') })).to.throw(/null bytes/);
38+
// TODO: should we test RegExp, too?
39+
});
40+
});
41+
});
File renamed without changes.

test/node/bson_test.js

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,38 +1986,4 @@ describe('BSON', function () {
19861986
expect(inspect(timestamp)).to.equal('new Timestamp({ t: 100, i: 1 })');
19871987
});
19881988
});
1989-
1990-
/**
1991-
* The BSON spec uses null-terminated strings to represent document field names and
1992-
* regex components (i.e. pattern and flags/options). Drivers MUST assert that null
1993-
* bytes are prohibited in the following contexts when encoding BSON (i.e. creating
1994-
* raw BSON bytes or constructing BSON-specific type classes):
1995-
* - Field name within a root document
1996-
* - Field name within a sub-document
1997-
* - Pattern for a regular expression
1998-
* - Flags/options for a regular expression
1999-
* Depending on how drivers implement BSON encoding, they MAY expect an error when
2000-
* constructing a type class (e.g. BSON Document or Regex class) or when encoding a
2001-
* language representation to BSON (e.g. converting a dictionary, which might allow
2002-
* null bytes in its keys, to raw BSON bytes).
2003-
*/
2004-
describe('null byte handling during serializing', () => {
2005-
it('should throw when null byte in BSON Field name within a root document', () => {
2006-
expect(() => BSON.serialize({ 'a\x00b': 1 })).to.throw(/null bytes/);
2007-
});
2008-
2009-
it('should throw when null byte in BSON Field name within a sub-document', () => {
2010-
expect(() => BSON.serialize({ a: { 'a\x00b': 1 } })).to.throw(/null bytes/);
2011-
});
2012-
2013-
it('should throw when null byte in Pattern for a regular expression', () => {
2014-
// eslint-disable-next-line no-control-regex
2015-
expect(() => BSON.serialize({ a: new RegExp('a\x00b') })).to.throw(/null bytes/);
2016-
expect(() => BSON.serialize({ a: new BSONRegExp('a\x00b') })).to.throw(/null bytes/);
2017-
});
2018-
2019-
it('should throw when null byte in Flags/options for a regular expression', () => {
2020-
expect(() => BSON.serialize({ a: new BSONRegExp('a', 'i\x00m') })).to.throw(/null bytes/);
2021-
});
2022-
});
20231989
});

0 commit comments

Comments
 (0)