Skip to content

Commit 411a022

Browse files
committed
PHPC-2148: Prohibit masterKey without provider for rewrapManyDataKey
1 parent d060b94 commit 411a022

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/MongoDB/ClientEncryption.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,11 @@ static PHP_METHOD(MongoDB_Driver_ClientEncryption, rewrapManyDataKey)
414414
goto cleanup;
415415
}
416416

417+
if (!provider) {
418+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "The \"masterKey\" option should not be specified without \"provider\"");
419+
goto cleanup;
420+
}
421+
417422
masterkey = bson_new();
418423
php_phongo_zval_to_bson(zmasterkey, PHONGO_BSON_NONE, masterkey, NULL);
419424

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
MongoDB\Driver\ClientEncryption::rewrapManyDataKey() masterKey option requires provider
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_not_libmongocrypt(); ?>
6+
<?php skip_if_not_live(); ?>
7+
<?php skip_if_not_clean(CSFLE_KEY_VAULT_DATABASE_NAME, CSFLE_KEY_VAULT_COLLECTION_NAME);
8+
--FILE--
9+
<?php
10+
11+
require_once __DIR__ . "/../utils/basic.inc";
12+
13+
$manager = create_test_manager();
14+
15+
$clientEncryption = $manager->createClientEncryption([
16+
'keyVaultNamespace' => CSFLE_KEY_VAULT_NS,
17+
'kmsProviders' => ['local' => ['key' => new MongoDB\BSON\Binary(CSFLE_LOCAL_KEY, 0)]],
18+
]);
19+
20+
echo throws(function () use ($clientEncryption) {
21+
$clientEncryption->rewrapManyDataKey([], ['masterKey' => []]);
22+
}, MongoDB\Driver\Exception\InvalidArgumentException::class), "\n";
23+
24+
?>
25+
===DONE===
26+
<?php exit(0); ?>
27+
--EXPECT--
28+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
29+
The "masterKey" option should not be specified without "provider"
30+
===DONE===

0 commit comments

Comments
 (0)