Skip to content

PHPC-1765 and PHPC-1821: DBRef and dot/dollar validation tests #1225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 22, 2021
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 src/LIBMONGOC_VERSION_CURRENT
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.18.0-20210622+gitebe90917f2
1.18.0-20210622+gitd2617271b8
2 changes: 1 addition & 1 deletion tests/bson-corpus/binary-parseError-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ DO NOT EDIT THIS FILE
--FILE--
<?php

require_once __DIR__ . '/../utils/tools.php';
require_once __DIR__ . '/../utils/basic.inc';

throws(function() {
fromJSON('{"x" : { "$uuid" : { "data" : "73ffd264-44b3-4c69-90e8-e7d1dfc035d4"}}}');
Expand Down
2 changes: 1 addition & 1 deletion tests/bson-corpus/binary-parseError-002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ DO NOT EDIT THIS FILE
--FILE--
<?php

require_once __DIR__ . '/../utils/tools.php';
require_once __DIR__ . '/../utils/basic.inc';

throws(function() {
fromJSON('{"x" : { "$uuid" : "73ffd264-44b3-90e8-e7d1dfc035d4"}}');
Expand Down
2 changes: 1 addition & 1 deletion tests/bson-corpus/binary-parseError-003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ DO NOT EDIT THIS FILE
--FILE--
<?php

require_once __DIR__ . '/../utils/tools.php';
require_once __DIR__ . '/../utils/basic.inc';

throws(function() {
fromJSON('{"x" : { "$uuid" : "73ffd264-44b3-4c69-90e8-e7d1dfc035d4-789e4"}}');
Expand Down
2 changes: 1 addition & 1 deletion tests/bson-corpus/binary-parseError-004.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ DO NOT EDIT THIS FILE
--FILE--
<?php

require_once __DIR__ . '/../utils/tools.php';
require_once __DIR__ . '/../utils/basic.inc';

throws(function() {
fromJSON('{"x" : { "$uuid" : "73ff-d26444b-34c6-990e8e-7d1dfc035d4"}}');
Expand Down
2 changes: 1 addition & 1 deletion tests/bson-corpus/binary-parseError-005.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ DO NOT EDIT THIS FILE
--FILE--
<?php

require_once __DIR__ . '/../utils/tools.php';
require_once __DIR__ . '/../utils/basic.inc';

throws(function() {
fromJSON('{"x" : { "$uuid" : "----d264-44b3-4--9-90e8-e7d1dfc0----"}}');
Expand Down
2 changes: 1 addition & 1 deletion tests/bson-corpus/binary-valid-012.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ DO NOT EDIT THIS FILE
--FILE--
<?php

require_once __DIR__ . '/../utils/tools.php';
require_once __DIR__ . '/../utils/basic.inc';

$canonicalBson = hex2bin('180000000378001000000010247479706500020000000000');
$canonicalExtJson = '{"x" : { "$type" : {"$numberInt": "2"}}}';
Expand Down
2 changes: 1 addition & 1 deletion tests/bson-corpus/dbref-valid-001.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
DBRef: DBRef
Document type (DBRef sub-documents): DBRef
--DESCRIPTION--
Generated by scripts/convert-bson-corpus-tests.php

Expand Down
2 changes: 1 addition & 1 deletion tests/bson-corpus/dbref-valid-002.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
DBRef: DBRef with database
Document type (DBRef sub-documents): DBRef with database
--DESCRIPTION--
Generated by scripts/convert-bson-corpus-tests.php

Expand Down
2 changes: 1 addition & 1 deletion tests/bson-corpus/dbref-valid-003.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
DBRef: DBRef with database and additional fields
Document type (DBRef sub-documents): DBRef with database and additional fields
--DESCRIPTION--
Generated by scripts/convert-bson-corpus-tests.php

Expand Down
2 changes: 1 addition & 1 deletion tests/bson-corpus/dbref-valid-004.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
DBRef: DBRef with additional fields
Document type (DBRef sub-documents): DBRef with additional fields
--DESCRIPTION--
Generated by scripts/convert-bson-corpus-tests.php

Expand Down
2 changes: 1 addition & 1 deletion tests/bson-corpus/dbref-valid-005.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
DBRef: Document with key names similar to those of a DBRef
Document type (DBRef sub-documents): Document with key names similar to those of a DBRef
--DESCRIPTION--
Generated by scripts/convert-bson-corpus-tests.php

Expand Down
31 changes: 31 additions & 0 deletions tests/bson-corpus/dbref-valid-006.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
--TEST--
Document type (DBRef sub-documents): DBRef with additional dollar-prefixed and dotted fields
--DESCRIPTION--
Generated by scripts/convert-bson-corpus-tests.php

DO NOT EDIT THIS FILE
--FILE--
<?php

require_once __DIR__ . '/../utils/basic.inc';

$canonicalBson = hex2bin('48000000036462726566003c0000000224726566000b000000636f6c6c656374696f6e00072469640058921b3e6e32ab156a22b59e10612e62000100000010246300010000000000');
$canonicalExtJson = '{"dbref": {"$ref": "collection", "$id": {"$oid": "58921b3e6e32ab156a22b59e"}, "a.b": {"$numberInt": "1"}, "$c": {"$numberInt": "1"}}}';

// Canonical BSON -> Native -> Canonical BSON
echo bin2hex(fromPHP(toPHP($canonicalBson))), "\n";

// Canonical BSON -> Canonical extJSON
echo json_canonicalize(toCanonicalExtendedJSON($canonicalBson)), "\n";

// Canonical extJSON -> Canonical BSON
echo bin2hex(fromJSON($canonicalExtJson)), "\n";

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
48000000036462726566003c0000000224726566000b000000636f6c6c656374696f6e00072469640058921b3e6e32ab156a22b59e10612e62000100000010246300010000000000
{"dbref":{"$ref":"collection","$id":{"$oid":"58921b3e6e32ab156a22b59e"},"a.b":{"$numberInt":"1"},"$c":{"$numberInt":"1"}}}
48000000036462726566003c0000000224726566000b000000636f6c6c656374696f6e00072469640058921b3e6e32ab156a22b59e10612e62000100000010246300010000000000
===DONE===
31 changes: 31 additions & 0 deletions tests/bson-corpus/dbref-valid-007.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
--TEST--
Document type (DBRef sub-documents): Sub-document resembles DBRef but $id is missing
--DESCRIPTION--
Generated by scripts/convert-bson-corpus-tests.php

DO NOT EDIT THIS FILE
--FILE--
<?php

require_once __DIR__ . '/../utils/basic.inc';

$canonicalBson = hex2bin('26000000036462726566001a0000000224726566000b000000636f6c6c656374696f6e000000');
$canonicalExtJson = '{"dbref": {"$ref": "collection"}}';

// Canonical BSON -> Native -> Canonical BSON
echo bin2hex(fromPHP(toPHP($canonicalBson))), "\n";

// Canonical BSON -> Canonical extJSON
echo json_canonicalize(toCanonicalExtendedJSON($canonicalBson)), "\n";

// Canonical extJSON -> Canonical BSON
echo bin2hex(fromJSON($canonicalExtJson)), "\n";

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
26000000036462726566001a0000000224726566000b000000636f6c6c656374696f6e000000
{"dbref":{"$ref":"collection"}}
26000000036462726566001a0000000224726566000b000000636f6c6c656374696f6e000000
===DONE===
31 changes: 31 additions & 0 deletions tests/bson-corpus/dbref-valid-008.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
--TEST--
Document type (DBRef sub-documents): Sub-document resembles DBRef but $ref is not a string
--DESCRIPTION--
Generated by scripts/convert-bson-corpus-tests.php

DO NOT EDIT THIS FILE
--FILE--
<?php

require_once __DIR__ . '/../utils/basic.inc';

$canonicalBson = hex2bin('2c000000036462726566002000000010247265660001000000072469640058921b3e6e32ab156a22b59e0000');
$canonicalExtJson = '{"dbref": {"$ref": {"$numberInt": "1"}, "$id": {"$oid": "58921b3e6e32ab156a22b59e"}}}';

// Canonical BSON -> Native -> Canonical BSON
echo bin2hex(fromPHP(toPHP($canonicalBson))), "\n";

// Canonical BSON -> Canonical extJSON
echo json_canonicalize(toCanonicalExtendedJSON($canonicalBson)), "\n";

// Canonical extJSON -> Canonical BSON
echo bin2hex(fromJSON($canonicalExtJson)), "\n";

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
2c000000036462726566002000000010247265660001000000072469640058921b3e6e32ab156a22b59e0000
{"dbref":{"$ref":{"$numberInt":"1"},"$id":{"$oid":"58921b3e6e32ab156a22b59e"}}}
2c000000036462726566002000000010247265660001000000072469640058921b3e6e32ab156a22b59e0000
===DONE===
31 changes: 31 additions & 0 deletions tests/bson-corpus/dbref-valid-009.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
--TEST--
Document type (DBRef sub-documents): Sub-document resembles DBRef but $db is not a string
--DESCRIPTION--
Generated by scripts/convert-bson-corpus-tests.php

DO NOT EDIT THIS FILE
--FILE--
<?php

require_once __DIR__ . '/../utils/basic.inc';

$canonicalBson = hex2bin('4000000003646272656600340000000224726566000b000000636f6c6c656374696f6e00072469640058921b3e6e32ab156a22b59e1024646200010000000000');
$canonicalExtJson = '{"dbref": {"$ref": "collection", "$id": {"$oid": "58921b3e6e32ab156a22b59e"}, "$db": {"$numberInt": "1"}}}';

// Canonical BSON -> Native -> Canonical BSON
echo bin2hex(fromPHP(toPHP($canonicalBson))), "\n";

// Canonical BSON -> Canonical extJSON
echo json_canonicalize(toCanonicalExtendedJSON($canonicalBson)), "\n";

// Canonical extJSON -> Canonical BSON
echo bin2hex(fromJSON($canonicalExtJson)), "\n";

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
4000000003646272656600340000000224726566000b000000636f6c6c656374696f6e00072469640058921b3e6e32ab156a22b59e1024646200010000000000
{"dbref":{"$ref":"collection","$id":{"$oid":"58921b3e6e32ab156a22b59e"},"$db":{"$numberInt":"1"}}}
4000000003646272656600340000000224726566000b000000636f6c6c656374696f6e00072469640058921b3e6e32ab156a22b59e1024646200010000000000
===DONE===
31 changes: 31 additions & 0 deletions tests/bson-corpus/document-valid-004.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
--TEST--
Document type (sub-documents): Dollar-prefixed key in sub-document
--DESCRIPTION--
Generated by scripts/convert-bson-corpus-tests.php

DO NOT EDIT THIS FILE
--FILE--
<?php

require_once __DIR__ . '/../utils/basic.inc';

$canonicalBson = hex2bin('170000000378000F000000022461000200000062000000');
$canonicalExtJson = '{"x" : {"$a" : "b"}}';

// Canonical BSON -> Native -> Canonical BSON
echo bin2hex(fromPHP(toPHP($canonicalBson))), "\n";

// Canonical BSON -> Canonical extJSON
echo json_canonicalize(toCanonicalExtendedJSON($canonicalBson)), "\n";

// Canonical extJSON -> Canonical BSON
echo bin2hex(fromJSON($canonicalExtJson)), "\n";

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
170000000378000f000000022461000200000062000000
{"x":{"$a":"b"}}
170000000378000f000000022461000200000062000000
===DONE===
31 changes: 31 additions & 0 deletions tests/bson-corpus/document-valid-005.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
--TEST--
Document type (sub-documents): Dollar as key in sub-document
--DESCRIPTION--
Generated by scripts/convert-bson-corpus-tests.php

DO NOT EDIT THIS FILE
--FILE--
<?php

require_once __DIR__ . '/../utils/basic.inc';

$canonicalBson = hex2bin('160000000378000E0000000224000200000061000000');
$canonicalExtJson = '{"x" : {"$" : "a"}}';

// Canonical BSON -> Native -> Canonical BSON
echo bin2hex(fromPHP(toPHP($canonicalBson))), "\n";

// Canonical BSON -> Canonical extJSON
echo json_canonicalize(toCanonicalExtendedJSON($canonicalBson)), "\n";

// Canonical extJSON -> Canonical BSON
echo bin2hex(fromJSON($canonicalExtJson)), "\n";

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
160000000378000e0000000224000200000061000000
{"x":{"$":"a"}}
160000000378000e0000000224000200000061000000
===DONE===
31 changes: 31 additions & 0 deletions tests/bson-corpus/document-valid-006.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
--TEST--
Document type (sub-documents): Dotted key in sub-document
--DESCRIPTION--
Generated by scripts/convert-bson-corpus-tests.php

DO NOT EDIT THIS FILE
--FILE--
<?php

require_once __DIR__ . '/../utils/basic.inc';

$canonicalBson = hex2bin('180000000378001000000002612E62000200000063000000');
$canonicalExtJson = '{"x" : {"a.b" : "c"}}';

// Canonical BSON -> Native -> Canonical BSON
echo bin2hex(fromPHP(toPHP($canonicalBson))), "\n";

// Canonical BSON -> Canonical extJSON
echo json_canonicalize(toCanonicalExtendedJSON($canonicalBson)), "\n";

// Canonical extJSON -> Canonical BSON
echo bin2hex(fromJSON($canonicalExtJson)), "\n";

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
180000000378001000000002612e62000200000063000000
{"x":{"a.b":"c"}}
180000000378001000000002612e62000200000063000000
===DONE===
31 changes: 31 additions & 0 deletions tests/bson-corpus/document-valid-007.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
--TEST--
Document type (sub-documents): Dot as key in sub-document
--DESCRIPTION--
Generated by scripts/convert-bson-corpus-tests.php

DO NOT EDIT THIS FILE
--FILE--
<?php

require_once __DIR__ . '/../utils/basic.inc';

$canonicalBson = hex2bin('160000000378000E000000022E000200000061000000');
$canonicalExtJson = '{"x" : {"." : "a"}}';

// Canonical BSON -> Native -> Canonical BSON
echo bin2hex(fromPHP(toPHP($canonicalBson))), "\n";

// Canonical BSON -> Canonical extJSON
echo json_canonicalize(toCanonicalExtendedJSON($canonicalBson)), "\n";

// Canonical extJSON -> Canonical BSON
echo bin2hex(fromJSON($canonicalExtJson)), "\n";

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
160000000378000e000000022e000200000061000000
{"x":{".":"a"}}
160000000378000e000000022e000200000061000000
===DONE===
4 changes: 2 additions & 2 deletions tests/bson-corpus/top-parseError-034.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
Top-level document validity: Bad DBRef (ref is number, not string)
Top-level document validity: Bad $minKey (boolean, not integer)
--DESCRIPTION--
Generated by scripts/convert-bson-corpus-tests.php

Expand All @@ -10,7 +10,7 @@ DO NOT EDIT THIS FILE
require_once __DIR__ . '/../utils/basic.inc';

throws(function() {
fromJSON('{"x" : {"$ref" : 42, "$id" : "abc"}}');
fromJSON('{"a" : {"$minKey" : true}}');
}, 'MongoDB\Driver\Exception\UnexpectedValueException');

?>
Expand Down
4 changes: 2 additions & 2 deletions tests/bson-corpus/top-parseError-035.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
Top-level document validity: Bad DBRef (db is number, not string)
Top-level document validity: Bad $minKey (wrong integer)
--DESCRIPTION--
Generated by scripts/convert-bson-corpus-tests.php

Expand All @@ -10,7 +10,7 @@ DO NOT EDIT THIS FILE
require_once __DIR__ . '/../utils/basic.inc';

throws(function() {
fromJSON('{"x" : {"$ref" : "a", "$id" : "abc", "$db" : 42}}');
fromJSON('{"a" : {"$minKey" : 0}}');
}, 'MongoDB\Driver\Exception\UnexpectedValueException');

?>
Expand Down
Loading