mirror of
https://github.com/macintoshplus/mongo-php-driver.git
synced 2026-03-24 17:02:15 +01:00
* PHPC-2219: Prohibit serializing PackedArray as root documents This adds logic to php_phongo_zval_to_bson_internal() to prohibit serializing PackedArray instances as a root document. Since this function is also used in specific cases to encode a BSON array, a PHONGO_BSON_ALLOW_ROOT_ARRAY flag is introduced to relax the restriction. * Check if existing field_path element must be freed before overwriting * Remove function name from Javascript code strings
72 lines
2.5 KiB
PHP
72 lines
2.5 KiB
PHP
--TEST--
|
|
MongoDB\Driver\ClientEncryption::__construct() with invalid option types
|
|
--SKIPIF--
|
|
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
|
|
<?php skip_if_not_libmongocrypt(); ?>
|
|
--FILE--
|
|
<?php
|
|
|
|
require_once __DIR__ . '/../utils/basic.inc';
|
|
|
|
/* phongo_clientencryption_opts_from_zval always requires a keyVaultClient
|
|
* option when constructing ClientEncryption directly, so this will be used to
|
|
* test other options. */
|
|
$baseOptions = ['keyVaultClient' => create_test_manager()];
|
|
|
|
$tests = [
|
|
[],
|
|
['keyVaultClient' => 'not_an_array_or_object'],
|
|
[
|
|
'keyVaultNamespace' => 'not_a_namespace',
|
|
// keyVaultNamespace requires a valid kmsProviders option
|
|
'kmsProviders' => ['local' => ['key' => new MongoDB\BSON\Binary(CSFLE_LOCAL_KEY, 0)]],
|
|
] + $baseOptions,
|
|
['kmsProviders' => 'not_an_array_or_object'] + $baseOptions,
|
|
['tlsOptions' => 'not_an_array_or_object'] + $baseOptions,
|
|
];
|
|
|
|
foreach ($tests as $test) {
|
|
echo throws(function () use ($test) {
|
|
new MongoDB\Driver\ClientEncryption($test);
|
|
}, MongoDB\Driver\Exception\InvalidArgumentException::class), "\n\n";
|
|
}
|
|
|
|
// PackedArray cannot be serialized as a root document
|
|
$tests = [
|
|
['kmsProviders' => MongoDB\BSON\PackedArray::fromPHP([])] + $baseOptions,
|
|
['tlsOptions' => MongoDB\BSON\PackedArray::fromPHP([])] + $baseOptions,
|
|
];
|
|
|
|
foreach ($tests as $test) {
|
|
echo throws(function () use ($test) {
|
|
new MongoDB\Driver\ClientEncryption($test);
|
|
}, MongoDB\Driver\Exception\UnexpectedValueException::class), "\n\n";
|
|
}
|
|
|
|
?>
|
|
===DONE===
|
|
<?php exit(0); ?>
|
|
--EXPECT--
|
|
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
|
|
The "keyVaultClient" option is required when constructing a ClientEncryption object directly
|
|
|
|
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
|
|
Expected "keyVaultClient" option to be MongoDB\Driver\Manager, string given
|
|
|
|
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
|
|
Expected "keyVaultNamespace" option to contain a full collection namespace
|
|
|
|
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
|
|
Expected "kmsProviders" option to be an array or object, string given
|
|
|
|
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
|
|
Expected "tlsOptions" option to be an array or object, string given
|
|
|
|
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
|
|
MongoDB\BSON\PackedArray cannot be serialized as a root document
|
|
|
|
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
|
|
MongoDB\BSON\PackedArray cannot be serialized as a root document
|
|
|
|
===DONE===
|