Skip to content

Commit 2871e7e

Browse files
committed
ClientEncryption operations
1 parent f866a64 commit 2871e7e

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

tests/UnifiedSpecTests/Operation.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use MongoDB\Client;
99
use MongoDB\Collection;
1010
use MongoDB\Database;
11+
use MongoDB\Driver\ClientEncryption;
1112
use MongoDB\Driver\Cursor;
1213
use MongoDB\Driver\Server;
1314
use MongoDB\Driver\Session;
@@ -186,6 +187,9 @@ private function execute()
186187
case Client::class:
187188
$result = $this->executeForClient($object);
188189
break;
190+
case ClientEncryption::class:
191+
$result = $this->executeForClientEncryption($object);
192+
break;
189193
case Database::class:
190194
$result = $this->executeForDatabase($object);
191195
break;
@@ -275,6 +279,61 @@ function (DatabaseInfo $info) {
275279
}
276280
}
277281

282+
private function executeForClientEncryption(ClientEncryption $clientEncryption)
283+
{
284+
$args = $this->prepareArguments();
285+
Util::assertArgumentsBySchema(ClientEncryption::class, $this->name, $args);
286+
287+
switch ($this->name) {
288+
case 'addKeyAltName':
289+
assertArrayHasKey('id', $args);
290+
assertArrayHasKey('keyAltName', $args);
291+
292+
return $clientEncryption->addKeyAltName($args['id'], $args['keyAltName']);
293+
294+
case 'createDataKey':
295+
assertArrayHasKey('kmsProvider', $args);
296+
// CSFLE spec tests nest options under an "opts" key (see: DRIVERS-2414)
297+
$options = array_key_exists('opts', $args) ? (array) $args['opts'] : [];
298+
299+
return $clientEncryption->createDataKey($args['kmsProvider'], $options);
300+
301+
case 'deleteKey':
302+
assertArrayHasKey('id', $args);
303+
304+
return $clientEncryption->deleteKey($args['id']);
305+
306+
case 'getKey':
307+
assertArrayHasKey('id', $args);
308+
309+
return $clientEncryption->getKey($args['id']);
310+
311+
case 'getKeyByAltName':
312+
assertArrayHasKey('keyAltName', $args);
313+
314+
return $clientEncryption->getKeyByAltName($args['keyAltName']);
315+
316+
case 'getKeys':
317+
return iterator_to_array($clientEncryption->getKeys());
318+
319+
case 'removeKeyAltName':
320+
assertArrayHasKey('id', $args);
321+
assertArrayHasKey('keyAltName', $args);
322+
323+
return $clientEncryption->removeKeyAltName($args['id'], $args['keyAltName']);
324+
325+
case 'rewrapManyDataKey':
326+
assertArrayHasKey('filter', $args);
327+
// CSFLE spec tests nest options under an "opts" key (see: DRIVERS-2414)
328+
$options = array_key_exists('opts', $args) ? (array) $args['opts'] : [];
329+
330+
return $clientEncryption->rewrapManyDataKey($args['filter'], $options);
331+
332+
default:
333+
Assert::fail('Unsupported clientEncryption operation: ' . $this->name);
334+
}
335+
}
336+
278337
private function executeForCollection(Collection $collection)
279338
{
280339
$args = $this->prepareArguments();

tests/UnifiedSpecTests/Util.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use MongoDB\Client;
77
use MongoDB\Collection;
88
use MongoDB\Database;
9+
use MongoDB\Driver\ClientEncryption;
910
use MongoDB\Driver\Cursor;
1011
use MongoDB\Driver\ReadConcern;
1112
use MongoDB\Driver\ReadPreference;
@@ -59,6 +60,16 @@ final class Util
5960
'listDatabaseNames' => ['authorizedDatabases', 'filter', 'maxTimeMS', 'session'],
6061
'listDatabases' => ['authorizedDatabases', 'filter', 'maxTimeMS', 'session'],
6162
],
63+
ClientEncryption::class => [
64+
'addKeyAltName' => ['id', 'keyAltName'],
65+
'createDataKey' => ['kmsProvider', 'opts'],
66+
'deleteKey' => ['id'],
67+
'getKey' => ['id'],
68+
'getKeyByAltName' => ['keyAltName'],
69+
'getKeys' => [],
70+
'removeKeyAltName' => ['id', 'keyAltName'],
71+
'rewrapManyDataKey' => ['filter', 'opts'],
72+
],
6273
Database::class => [
6374
'aggregate' => ['pipeline', 'session', 'useCursor', 'allowDiskUse', 'batchSize', 'bypassDocumentValidation', 'collation', 'comment', 'explain', 'hint', 'let', 'maxAwaitTimeMS', 'maxTimeMS'],
6475
'createChangeStream' => ['pipeline', 'session', 'fullDocument', 'resumeAfter', 'startAfter', 'startAtOperationTime', 'batchSize', 'collation', 'maxAwaitTimeMS', 'showExpandedEvents'],

0 commit comments

Comments
 (0)