@@ -115,7 +115,7 @@ public function testClientSideEncryption(stdClass $test, ?array $runOn, array $d
115
115
116
116
$ this ->setContext ($ context );
117
117
118
- $ this -> insertKeyVaultData ( $ keyVaultData );
118
+ self :: insertKeyVaultData ( $ context -> getClient (), $ keyVaultData );
119
119
$ this ->dropTestAndOutcomeCollections ();
120
120
$ this ->createTestCollection ($ jsonSchema );
121
121
$ this ->insertDataFixtures ($ data );
@@ -127,7 +127,7 @@ public function testClientSideEncryption(stdClass $test, ?array $runOn, array $d
127
127
$ context ->enableEncryption ();
128
128
129
129
if (isset ($ test ->expectations )) {
130
- $ commandExpectations = CommandExpectations::fromClientSideEncryption ($ test ->expectations );
130
+ $ commandExpectations = CommandExpectations::fromClientSideEncryption ($ context -> getClient (), $ test ->expectations );
131
131
$ commandExpectations ->startMonitoring ();
132
132
}
133
133
@@ -192,14 +192,12 @@ public function provideTests()
192
192
*/
193
193
public function testDataKeyAndDoubleEncryption (string $ providerName , $ masterKey ): void
194
194
{
195
- $ this ->setContext (Context::fromClientSideEncryption ((object ) [], 'db ' , 'coll ' ));
196
- $ client = $ this ->getContext ()->getClient ();
197
-
198
- // This empty call ensures that the key vault is dropped with a majority
199
- // write concern
200
- $ this ->insertKeyVaultData ([]);
195
+ $ client = static ::createTestClient ();
201
196
$ client ->selectCollection ('db ' , 'coll ' )->drop ();
202
197
198
+ // Ensure that the key vault is dropped with a majority write concern
199
+ self ::insertKeyVaultData ($ client , []);
200
+
203
201
$ encryptionOpts = [
204
202
'keyVaultNamespace ' => 'keyvault.datakeys ' ,
205
203
'kmsProviders ' => [
@@ -332,19 +330,12 @@ public static function dataKeyProvider()
332
330
*/
333
331
public function testExternalKeyVault ($ withExternalKeyVault ): void
334
332
{
335
- $ this ->setContext (Context::fromClientSideEncryption ((object ) [], 'db ' , 'coll ' ));
336
- $ client = $ this ->getContext ()->getClient ();
333
+ $ client = static ::createTestClient ();
337
334
$ client ->selectCollection ('db ' , 'coll ' )->drop ();
338
335
339
- $ keyVaultCollection = $ client ->selectCollection (
340
- 'keyvault ' ,
341
- 'datakeys ' ,
342
- ['writeConcern ' => new WriteConcern (WriteConcern::MAJORITY )] + $ this ->getContext ()->defaultWriteOptions
343
- );
344
- $ keyVaultCollection ->drop ();
345
- $ keyId = $ keyVaultCollection
346
- ->insertOne ($ this ->decodeJson (file_get_contents (__DIR__ . '/client-side-encryption/external/external-key.json ' )))
347
- ->getInsertedId ();
336
+ self ::insertKeyVaultData ($ client , [
337
+ $ this ->decodeJson (file_get_contents (__DIR__ . '/client-side-encryption/external/external-key.json ' )),
338
+ ]);
348
339
349
340
$ encryptionOpts = [
350
341
'keyVaultNamespace ' => 'keyvault.datakeys ' ,
@@ -386,7 +377,10 @@ public function testExternalKeyVault($withExternalKeyVault): void
386
377
$ this ->expectException (AuthenticationException::class);
387
378
}
388
379
389
- $ clientEncryption ->encrypt ('test ' , ['algorithm ' => ClientEncryption::AEAD_AES_256_CBC_HMAC_SHA_512_DETERMINISTIC , 'keyId ' => $ keyId ]);
380
+ $ clientEncryption ->encrypt ('test ' , [
381
+ 'algorithm ' => ClientEncryption::AEAD_AES_256_CBC_HMAC_SHA_512_DETERMINISTIC ,
382
+ 'keyId ' => new Binary (base64_decode ('LOCALAAAAAAAAAAAAAAAAA== ' ), Binary::TYPE_UUID ),
383
+ ]);
390
384
}
391
385
392
386
public static function provideBSONSizeLimitsAndBatchSplittingTests ()
@@ -483,13 +477,12 @@ static function (self $test, Collection $collection, array $document): void {
483
477
*/
484
478
public function testBSONSizeLimitsAndBatchSplitting (Closure $ test ): void
485
479
{
486
- $ this ->setContext (Context::fromClientSideEncryption ((object ) [], 'db ' , 'coll ' ));
487
- $ client = $ this ->getContext ()->getClient ();
480
+ $ client = static ::createTestClient ();
488
481
489
482
$ client ->selectCollection ('db ' , 'coll ' )->drop ();
490
483
$ client ->selectDatabase ('db ' )->createCollection ('coll ' , ['validator ' => ['$jsonSchema ' => $ this ->decodeJson (file_get_contents (__DIR__ . '/client-side-encryption/limits/limits-schema.json ' ))]]);
491
484
492
- $ this -> insertKeyVaultData ([
485
+ self :: insertKeyVaultData ($ client , [
493
486
$ this ->decodeJson (file_get_contents (__DIR__ . '/client-side-encryption/limits/limits-key.json ' )),
494
487
]);
495
488
@@ -551,20 +544,16 @@ public function testViewsAreProhibited(): void
551
544
*/
552
545
public function testCorpus ($ schemaMap = true ): void
553
546
{
554
- $ this ->setContext (Context::fromClientSideEncryption ((object ) [], 'db ' , 'coll ' ));
555
- $ client = $ this ->getContext ()->getClient ();
556
-
547
+ $ client = static ::createTestClient ();
557
548
$ client ->selectDatabase ('db ' )->dropCollection ('coll ' );
558
549
559
550
$ schema = $ this ->decodeJson (file_get_contents (__DIR__ . '/client-side-encryption/corpus/corpus-schema.json ' ));
560
551
561
552
if (! $ schemaMap ) {
562
- $ client
563
- ->selectDatabase ('db ' )
564
- ->createCollection ('coll ' , ['validator ' => ['$jsonSchema ' => $ schema ]]);
553
+ $ client ->selectDatabase ('db ' )->createCollection ('coll ' , ['validator ' => ['$jsonSchema ' => $ schema ]]);
565
554
}
566
555
567
- $ this -> insertKeyVaultData ([
556
+ self :: insertKeyVaultData ($ client , [
568
557
$ this ->decodeJson (file_get_contents (__DIR__ . '/client-side-encryption/corpus/corpus-key-local.json ' )),
569
558
$ this ->decodeJson (file_get_contents (__DIR__ . '/client-side-encryption/corpus/corpus-key-aws.json ' )),
570
559
$ this ->decodeJson (file_get_contents (__DIR__ . '/client-side-encryption/corpus/corpus-key-azure.json ' )),
@@ -1432,10 +1421,9 @@ private static function getEnv(string $name): string
1432
1421
return $ value ;
1433
1422
}
1434
1423
1435
- private function insertKeyVaultData (?array $ keyVaultData = null ): void
1424
+ private static function insertKeyVaultData (Client $ client , ?array $ keyVaultData = null ): void
1436
1425
{
1437
- $ context = $ this ->getContext ();
1438
- $ collection = $ context ->selectCollection ('keyvault ' , 'datakeys ' , ['writeConcern ' => new WriteConcern (WriteConcern::MAJORITY )] + $ context ->defaultWriteOptions );
1426
+ $ collection = $ client ->selectCollection ('keyvault ' , 'datakeys ' , ['writeConcern ' => new WriteConcern (WriteConcern::MAJORITY )]);
1439
1427
$ collection ->drop ();
1440
1428
1441
1429
if (empty ($ keyVaultData )) {
0 commit comments