Skip to content

Commit cdbefae

Browse files
committed
ClientEncryption::rewrapManyDataKey method
1 parent 3482065 commit cdbefae

File tree

3 files changed

+110
-2
lines changed

3 files changed

+110
-2
lines changed

src/MongoDB/ClientEncryption.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,10 @@ static PHP_METHOD(MongoDB_Driver_ClientEncryption, rewrapManyDataKey)
393393
zend_bool free_provider = false;
394394
bson_t* masterkey = NULL;
395395
bson_error_t error = { 0 };
396+
bson_t reply = BSON_INITIALIZER;
396397

397398
mongoc_client_encryption_rewrap_many_datakey_result_t* result = NULL;
399+
const bson_t* bulk_write_result;
398400

399401
PHONGO_PARSE_PARAMETERS_START(1, 2)
400402
Z_PARAM_ARRAY_OR_OBJECT(zfilter)
@@ -431,9 +433,15 @@ static PHP_METHOD(MongoDB_Driver_ClientEncryption, rewrapManyDataKey)
431433
goto cleanup;
432434
}
433435

434-
RETVAL_NULL();
436+
bulk_write_result = mongoc_client_encryption_rewrap_many_datakey_result_get_bulk_write_result(result);
435437

436-
/* TODO: mongoc_client_encryption_rewrap_many_datakey_result_t return value */
438+
if (bson_empty0(bulk_write_result)) {
439+
BSON_APPEND_NULL(&reply, "bulkWriteResult");
440+
} else {
441+
BSON_APPEND_DOCUMENT(&reply, "bulkWriteResult", bulk_write_result);
442+
}
443+
444+
RETVAL_BSON_T(reply);
437445

438446
cleanup:
439447
if (free_provider) {
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
--TEST--
2+
MongoDB\Driver\ClientEncryption::rewrapManyDataKey()
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+
$keyId = $clientEncryption->createDataKey('local');
21+
22+
$orignalKey = $clientEncryption->getKey($keyId);
23+
24+
var_dump($clientEncryption->rewrapManyDataKey([], ['provider' => 'local']));
25+
26+
$modifiedKey = $clientEncryption->getKey($keyId);
27+
28+
var_dump($orignalKey->creationDate == $modifiedKey->creationDate);
29+
var_dump($orignalKey->updateDate < $modifiedKey->updateDate);
30+
var_dump($orignalKey->keyMaterial != $modifiedKey->keyMaterial);
31+
32+
?>
33+
===DONE===
34+
<?php exit(0); ?>
35+
--EXPECTF--
36+
object(stdClass)#%d (%d) {
37+
["bulkWriteResult"]=>
38+
object(stdClass)#%d (%d) {
39+
["nInserted"]=>
40+
int(0)
41+
["nMatched"]=>
42+
int(1)
43+
["nModified"]=>
44+
int(1)
45+
["nRemoved"]=>
46+
int(0)
47+
["nUpserted"]=>
48+
int(0)
49+
["writeErrors"]=>
50+
array(0) {
51+
}
52+
}
53+
}
54+
bool(true)
55+
bool(true)
56+
bool(true)
57+
===DONE===
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
--TEST--
2+
MongoDB\Driver\ClientEncryption::rewrapManyDataKey() when filter matches no keys
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+
$keyId = $clientEncryption->createDataKey('local');
21+
22+
$orignalKey = $clientEncryption->getKey($keyId);
23+
24+
var_dump($clientEncryption->rewrapManyDataKey(['_id' => 'no-matching-key']));
25+
26+
$modifiedKey = $clientEncryption->getKey($keyId);
27+
28+
var_dump($orignalKey->creationDate == $modifiedKey->creationDate);
29+
var_dump($orignalKey->updateDate == $modifiedKey->updateDate);
30+
var_dump($orignalKey->keyMaterial == $modifiedKey->keyMaterial);
31+
32+
?>
33+
===DONE===
34+
<?php exit(0); ?>
35+
--EXPECTF--
36+
object(stdClass)#%d (%d) {
37+
["bulkWriteResult"]=>
38+
NULL
39+
}
40+
bool(true)
41+
bool(true)
42+
bool(true)
43+
===DONE===

0 commit comments

Comments
 (0)