Files
mongo-php-driver/tests/clientEncryption/clientEncryption-createDataKey_error-003.phpt
Jeremy Mikola e9098a56e4 PHPC-2219: Prohibit serializing PackedArray as root documents (#1480)
* 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
2023-10-16 13:16:37 -04:00

35 lines
1.2 KiB
PHP

--TEST--
MongoDB\Driver\ClientEncryption::createDataKey() masterKey option invalid type
--SKIPIF--
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
<?php skip_if_not_libmongocrypt(); ?>
<?php skip_if_not_live(); ?>
--FILE--
<?php
require_once __DIR__ . "/../utils/basic.inc";
$manager = create_test_manager();
$clientEncryption = $manager->createClientEncryption([
'keyVaultNamespace' => CSFLE_KEY_VAULT_NS,
'kmsProviders' => ['local' => ['key' => new MongoDB\BSON\Binary(CSFLE_LOCAL_KEY, 0)]],
]);
echo throws(function () use ($clientEncryption) {
$clientEncryption->createDataKey('local', ['masterKey' => 'not-array-or-object']);
}, MongoDB\Driver\Exception\InvalidArgumentException::class), "\n";
echo throws(function () use ($clientEncryption) {
$clientEncryption->createDataKey('local', ['masterKey' => MongoDB\BSON\PackedArray::fromPHP([])]);
}, MongoDB\Driver\Exception\UnexpectedValueException::class), "\n";
?>
===DONE===
<?php exit(0); ?>
--EXPECT--
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
Expected "masterKey" option to be array or object, string given
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
MongoDB\BSON\PackedArray cannot be serialized as a root document
===DONE===