@@ -168,9 +168,12 @@ public function provideTests()
168
168
*/
169
169
public function testDataKeyAndDoubleEncryption (Closure $ test )
170
170
{
171
- $ client = new Client (static ::getUri ());
171
+ $ this ->setContext (Context::fromClientSideEncryption ((object ) [], 'db ' , 'coll ' ));
172
+ $ client = $ this ->getContext ()->getClient ();
172
173
173
- $ client ->selectCollection ('keyvault ' , 'datakeys ' )->drop ();
174
+ // This empty call ensures that the key vault is dropped with a majority
175
+ // write concern
176
+ $ this ->insertKeyVaultData ([]);
174
177
$ client ->selectCollection ('db ' , 'coll ' )->drop ();
175
178
176
179
$ encryptionOpts = [
@@ -312,13 +315,17 @@ function ($command) use (&$commands) {
312
315
*/
313
316
public function testExternalKeyVault ($ withExternalKeyVault )
314
317
{
315
- $ client = new Client (static ::getUri ());
316
-
317
- $ client ->selectCollection ('keyvault ' , 'datakeys ' )->drop ();
318
+ $ this ->setContext (Context::fromClientSideEncryption ((object ) [], 'db ' , 'coll ' ));
319
+ $ client = $ this ->getContext ()->getClient ();
318
320
$ client ->selectCollection ('db ' , 'coll ' )->drop ();
319
321
320
- $ keyId = $ client
321
- ->selectCollection ('keyvault ' , 'datakeys ' )
322
+ $ keyVaultCollection = $ client ->selectCollection (
323
+ 'keyvault ' ,
324
+ 'datakeys ' ,
325
+ ['writeConcern ' => new WriteConcern (WriteConcern::MAJORITY )] + $ this ->getContext ()->defaultWriteOptions
326
+ );
327
+ $ keyVaultCollection ->drop ();
328
+ $ keyId = $ keyVaultCollection
322
329
->insertOne ($ this ->decodeJson (file_get_contents (__DIR__ . '/client-side-encryption/external/external-key.json ' )))
323
330
->getInsertedId ();
324
331
@@ -370,13 +377,15 @@ public function testExternalKeyVault($withExternalKeyVault)
370
377
*/
371
378
public function testBSONSizeLimitsAndBatchSplitting ()
372
379
{
373
- $ client = new Client (static ::getUri ());
380
+ $ this ->setContext (Context::fromClientSideEncryption ((object ) [], 'db ' , 'coll ' ));
381
+ $ client = $ this ->getContext ()->getClient ();
374
382
375
- $ client ->selectCollection ('keyvault ' , 'datakeys ' )->drop ();
376
383
$ client ->selectCollection ('db ' , 'coll ' )->drop ();
377
-
378
384
$ client ->selectDatabase ('db ' )->createCollection ('coll ' , ['validator ' => ['$jsonSchema ' => $ this ->decodeJson (file_get_contents (__DIR__ . '/client-side-encryption/limits/limits-schema.json ' ))]]);
379
- $ client ->selectCollection ('keyvault ' , 'datakeys ' )->insertOne ($ this ->decodeJson (file_get_contents (__DIR__ . '/client-side-encryption/limits/limits-key.json ' )));
385
+
386
+ $ this ->insertKeyVaultData ([
387
+ $ this ->decodeJson (file_get_contents (__DIR__ . '/client-side-encryption/limits/limits-key.json ' )),
388
+ ]);
380
389
381
390
$ autoEncryptionOpts = [
382
391
'keyVaultNamespace ' => 'keyvault.datakeys ' ,
@@ -491,7 +500,8 @@ public function testViewsAreProhibited()
491
500
*/
492
501
public function testCorpus ($ schemaMap = true )
493
502
{
494
- $ client = new Client (static ::getUri ());
503
+ $ this ->setContext (Context::fromClientSideEncryption ((object ) [], 'db ' , 'coll ' ));
504
+ $ client = $ this ->getContext ()->getClient ();
495
505
496
506
$ client ->selectDatabase ('db ' )->dropCollection ('coll ' );
497
507
@@ -503,8 +513,7 @@ public function testCorpus($schemaMap = true)
503
513
->createCollection ('coll ' , ['validator ' => ['$jsonSchema ' => $ schema ]]);
504
514
}
505
515
506
- $ client ->selectDatabase ('keyvault ' )->dropCollection ('datakeys ' );
507
- $ client ->selectCollection ('keyvault ' , 'datakeys ' )->insertMany ([
516
+ $ this ->insertKeyVaultData ([
508
517
$ this ->decodeJson (file_get_contents (__DIR__ . '/client-side-encryption/corpus/corpus-key-local.json ' )),
509
518
$ this ->decodeJson (file_get_contents (__DIR__ . '/client-side-encryption/corpus/corpus-key-aws.json ' )),
510
519
]);
@@ -738,16 +747,15 @@ private function encryptCorpusValue(stdClass $data, ClientEncryption $clientEncr
738
747
739
748
private function insertKeyVaultData (array $ keyVaultData = null )
740
749
{
750
+ $ context = $ this ->getContext ();
751
+ $ collection = $ context ->selectCollection ('keyvault ' , 'datakeys ' , ['writeConcern ' => new WriteConcern (WriteConcern::MAJORITY )] + $ context ->defaultWriteOptions );
752
+ $ collection ->drop ();
753
+
741
754
if (empty ($ keyVaultData )) {
742
755
return ;
743
756
}
744
757
745
- $ context = $ this ->getContext ();
746
- $ collection = $ context ->selectCollection ('keyvault ' , 'datakeys ' , ['writeConcern ' => new WriteConcern (WriteConcern::MAJORITY )] + $ context ->defaultWriteOptions );
747
- $ collection ->drop ();
748
758
$ collection ->insertMany ($ keyVaultData );
749
-
750
- return ;
751
759
}
752
760
753
761
private function prepareCorpusData (stdClass $ data , ClientEncryption $ clientEncryption )
0 commit comments