Skip to content

Commit 571b7cb

Browse files
committed
Test invalid keyMaterial option for ClientEncryption::createDataKey()
1 parent 8428734 commit 571b7cb

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--TEST--
2+
MongoDB\Driver\ClientEncryption::createDataKey() with invalid keyMaterial option
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_not_libmongocrypt(); ?>
6+
<?php skip_if_not_live(); ?>
7+
--FILE--
8+
<?php
9+
10+
require_once __DIR__ . "/../utils/basic.inc";
11+
12+
$tests = [
13+
['keyMaterial' => 0],
14+
['keyMaterial' => new stdClass],
15+
];
16+
17+
$manager = create_test_manager();
18+
$clientEncryption = $manager->createClientEncryption([
19+
'keyVaultNamespace' => CSFLE_KEY_VAULT_NS,
20+
'kmsProviders' => ['local' => ['key' => new MongoDB\BSON\Binary(CSFLE_LOCAL_KEY, 0)]],
21+
]);
22+
23+
foreach ($tests as $opts) {
24+
echo throws(function () use ($clientEncryption, $opts) {
25+
$clientEncryption->createDataKey('local', $opts);
26+
}, MongoDB\Driver\Exception\InvalidArgumentException::class), "\n";
27+
}
28+
29+
?>
30+
===DONE===
31+
<?php exit(0); ?>
32+
--EXPECT--
33+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
34+
Expected "keyMaterial" option to be MongoDB\BSON\Binary, int given
35+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
36+
Expected "keyMaterial" option to be MongoDB\BSON\Binary, stdClass given
37+
===DONE===

0 commit comments

Comments
 (0)