Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/Model/IndexInfoFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function testIs2dSphere()
/**
* @group matrix-testing-exclude-server-5.0-driver-4.0
* @group matrix-testing-exclude-server-5.0-driver-4.2
* @group matrix-testing-exclude-server-5.0-driver-4.4
*/
public function testIsGeoHaystack()
{
Expand Down
46 changes: 27 additions & 19 deletions tests/SpecTests/ClientSideEncryptionSpecTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,12 @@ public function provideTests()
*/
public function testDataKeyAndDoubleEncryption(Closure $test)
{
$client = new Client(static::getUri());
$this->setContext(Context::fromClientSideEncryption((object) [], 'db', 'coll'));
$client = $this->getContext()->getClient();

$client->selectCollection('keyvault', 'datakeys')->drop();
// This empty call ensures that the key vault is dropped with a majority
// write concern
$this->insertKeyVaultData([]);
$client->selectCollection('db', 'coll')->drop();

$encryptionOpts = [
Expand Down Expand Up @@ -312,13 +315,17 @@ function ($command) use (&$commands) {
*/
public function testExternalKeyVault($withExternalKeyVault)
{
$client = new Client(static::getUri());

$client->selectCollection('keyvault', 'datakeys')->drop();
$this->setContext(Context::fromClientSideEncryption((object) [], 'db', 'coll'));
$client = $this->getContext()->getClient();
$client->selectCollection('db', 'coll')->drop();

$keyId = $client
->selectCollection('keyvault', 'datakeys')
$keyVaultCollection = $client->selectCollection(
'keyvault',
'datakeys',
['writeConcern' => new WriteConcern(WriteConcern::MAJORITY)] + $this->getContext()->defaultWriteOptions
);
$keyVaultCollection->drop();
$keyId = $keyVaultCollection
->insertOne($this->decodeJson(file_get_contents(__DIR__ . '/client-side-encryption/external/external-key.json')))
->getInsertedId();

Expand Down Expand Up @@ -370,13 +377,15 @@ public function testExternalKeyVault($withExternalKeyVault)
*/
public function testBSONSizeLimitsAndBatchSplitting()
{
$client = new Client(static::getUri());
$this->setContext(Context::fromClientSideEncryption((object) [], 'db', 'coll'));
$client = $this->getContext()->getClient();

$client->selectCollection('keyvault', 'datakeys')->drop();
$client->selectCollection('db', 'coll')->drop();

$client->selectDatabase('db')->createCollection('coll', ['validator' => ['$jsonSchema' => $this->decodeJson(file_get_contents(__DIR__ . '/client-side-encryption/limits/limits-schema.json'))]]);
$client->selectCollection('keyvault', 'datakeys')->insertOne($this->decodeJson(file_get_contents(__DIR__ . '/client-side-encryption/limits/limits-key.json')));

$this->insertKeyVaultData([
$this->decodeJson(file_get_contents(__DIR__ . '/client-side-encryption/limits/limits-key.json')),
]);

$autoEncryptionOpts = [
'keyVaultNamespace' => 'keyvault.datakeys',
Expand Down Expand Up @@ -491,7 +500,8 @@ public function testViewsAreProhibited()
*/
public function testCorpus($schemaMap = true)
{
$client = new Client(static::getUri());
$this->setContext(Context::fromClientSideEncryption((object) [], 'db', 'coll'));
$client = $this->getContext()->getClient();

$client->selectDatabase('db')->dropCollection('coll');

Expand All @@ -503,8 +513,7 @@ public function testCorpus($schemaMap = true)
->createCollection('coll', ['validator' => ['$jsonSchema' => $schema]]);
}

$client->selectDatabase('keyvault')->dropCollection('datakeys');
$client->selectCollection('keyvault', 'datakeys')->insertMany([
$this->insertKeyVaultData([
$this->decodeJson(file_get_contents(__DIR__ . '/client-side-encryption/corpus/corpus-key-local.json')),
$this->decodeJson(file_get_contents(__DIR__ . '/client-side-encryption/corpus/corpus-key-aws.json')),
]);
Expand Down Expand Up @@ -738,16 +747,15 @@ private function encryptCorpusValue(stdClass $data, ClientEncryption $clientEncr

private function insertKeyVaultData(array $keyVaultData = null)
{
$context = $this->getContext();
$collection = $context->selectCollection('keyvault', 'datakeys', ['writeConcern' => new WriteConcern(WriteConcern::MAJORITY)] + $context->defaultWriteOptions);
$collection->drop();

if (empty($keyVaultData)) {
return;
}

$context = $this->getContext();
$collection = $context->selectCollection('keyvault', 'datakeys', ['writeConcern' => new WriteConcern(WriteConcern::MAJORITY)] + $context->defaultWriteOptions);
$collection->drop();
$collection->insertMany($keyVaultData);

return;
}

private function prepareCorpusData(stdClass $data, ClientEncryption $clientEncryption)
Expand Down