Skip to content

Commit 7b7cb3b

Browse files
committed
Merge pull request #1089
2 parents 69d6df1 + 3c10a49 commit 7b7cb3b

5 files changed

+94
-4
lines changed

php_phongo.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2795,6 +2795,11 @@ static bool phongo_manager_set_auto_encryption_opts(php_phongo_manager_t* manage
27952795
zval* kms_providers = php_array_fetch(zAutoEncryptionOpts, "kmsProviders");
27962796
bson_t bson_providers = BSON_INITIALIZER;
27972797

2798+
if (Z_TYPE_P(kms_providers) != IS_OBJECT && Z_TYPE_P(kms_providers) != IS_ARRAY) {
2799+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected \"kmsProviders\" encryption option to be an array or object");
2800+
goto cleanup;
2801+
}
2802+
27982803
php_phongo_zval_to_bson(kms_providers, PHONGO_BSON_NONE, &bson_providers, NULL TSRMLS_CC);
27992804
if (EG(exception)) {
28002805
goto cleanup;
@@ -2809,6 +2814,11 @@ static bool phongo_manager_set_auto_encryption_opts(php_phongo_manager_t* manage
28092814
zval* schema_map = php_array_fetch(zAutoEncryptionOpts, "schemaMap");
28102815
bson_t bson_map = BSON_INITIALIZER;
28112816

2817+
if (Z_TYPE_P(schema_map) != IS_OBJECT && Z_TYPE_P(schema_map) != IS_ARRAY) {
2818+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected \"schemaMap\" encryption option to be an array or object");
2819+
goto cleanup;
2820+
}
2821+
28122822
php_phongo_zval_to_bson(schema_map, PHONGO_BSON_NONE, &bson_map, NULL TSRMLS_CC);
28132823
if (EG(exception)) {
28142824
goto cleanup;
@@ -2907,8 +2917,8 @@ static mongoc_client_encryption_opts_t* phongo_clientencryption_opts_from_zval(m
29072917
zval* kms_providers = php_array_fetchc(options, "kmsProviders");
29082918
bson_t bson_providers = BSON_INITIALIZER;
29092919

2910-
if (Z_TYPE_P(kms_providers) != IS_ARRAY) {
2911-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected \"kmsProviders\" encryption option to be an array");
2920+
if (Z_TYPE_P(kms_providers) != IS_ARRAY && Z_TYPE_P(kms_providers) != IS_OBJECT) {
2921+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected \"kmsProviders\" encryption option to be an array or object");
29122922
goto cleanup;
29132923
}
29142924

tests/clientEncryption/clientEncryption-ctor-001.phpt renamed to tests/manager/manager-createClientEncryption-001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
MongoDB\Driver\ClientEncryption::__construct()
2+
MongoDB\Driver\Manager::createClientEncryption()
33
--SKIPIF--
44
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
55
<?php skip_if_not_libmongocrypt(); ?>

tests/clientEncryption/clientEncryption-ctor-error-001.phpt renamed to tests/manager/manager-createClientEncryption-error-001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
MongoDB\Driver\ClientEncryption::__construct() fails if compiled without FLE
2+
MongoDB\Driver\Manager::createClientEncryption() fails if compiled without FLE
33
--SKIPIF--
44
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
55
<?php skip_if_libmongocrypt(); ?>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
MongoDB\Driver\Manager::createClientEncryption() with invalid option types
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_not_libmongocrypt(); ?>
6+
--FILE--
7+
<?php
8+
9+
require_once __DIR__ . '/../utils/tools.php';
10+
11+
$tests = [
12+
['kmsProviders' => 'string'],
13+
[
14+
'kmsProviders' => ['local' => ['key' => new MongoDB\BSON\Binary('', 0)]],
15+
'keyVaultClient' => 'string',
16+
],
17+
];
18+
19+
foreach ($tests as $test) {
20+
echo throws(function () use ($test) {
21+
$manager = new MongoDB\Driver\Manager();
22+
$clientEncryption = $manager->createClientEncryption(['keyVaultNamespace' => 'default.keys'] + $test);
23+
}, MongoDB\Driver\Exception\InvalidArgumentException::class), "\n\n";
24+
}
25+
26+
?>
27+
===DONE===
28+
<?php exit(0); ?>
29+
--EXPECT--
30+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
31+
Expected "kmsProviders" encryption option to be an array or object
32+
33+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
34+
Expected "keyVaultClient" encryption option to be MongoDB\Driver\Manager, string given
35+
36+
===DONE===
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
--TEST--
2+
MongoDB\Driver\Manager::__construct(): invalid option types
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_not_libmongocrypt(); ?>
6+
--FILE--
7+
<?php
8+
9+
require_once __DIR__ . '/../utils/tools.php';
10+
11+
$tests = [
12+
['kmsProviders' => 'string'],
13+
[
14+
'kmsProviders' => ['local' => ['key' => new MongoDB\BSON\Binary('', 0)]],
15+
'schemaMap' => 'string',
16+
],
17+
[
18+
'kmsProviders' => ['local' => ['key' => new MongoDB\BSON\Binary('', 0)]],
19+
'keyVaultClient' => 'string',
20+
],
21+
];
22+
23+
foreach ($tests as $test) {
24+
echo throws(function() use ($test) {
25+
$autoEncryptionOptions = ['keyVaultNamespace' => 'admin.dataKeys'];
26+
27+
$manager = new MongoDB\Driver\Manager(null, [], ['autoEncryption' => $autoEncryptionOptions + $test]);
28+
}, MongoDB\Driver\Exception\InvalidArgumentException::class), "\n\n";
29+
}
30+
31+
?>
32+
===DONE===
33+
<?php exit(0); ?>
34+
--EXPECT--
35+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
36+
Expected "kmsProviders" encryption option to be an array or object
37+
38+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
39+
Expected "schemaMap" encryption option to be an array or object
40+
41+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
42+
Expected "keyVaultClient" encryption option to be MongoDB\Driver\Manager, string given
43+
44+
===DONE===

0 commit comments

Comments
 (0)