-
Notifications
You must be signed in to change notification settings - Fork 266
PHPLIB-1702: Always consult server encryptedFieldsMap when dropping collections with autoEncryption
enabled
#1745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
97284ec
8ef5fe6
878e5cd
bbc1700
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
namespace MongoDB\Tests\Functions; | ||
|
||
use MongoDB\BSON\Binary; | ||
use MongoDB\Collection; | ||
use MongoDB\Database; | ||
use MongoDB\Driver\ClientEncryption; | ||
use MongoDB\Driver\WriteConcern; | ||
use MongoDB\Tests\FunctionalTestCase; | ||
|
||
use function iterator_count; | ||
use function str_repeat; | ||
|
||
class GetEncryptedFieldsFromServerFunctionalTest extends FunctionalTestCase | ||
GromNaN marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
private ClientEncryption $clientEncryption; | ||
private Collection $keyVaultCollection; | ||
private Database $database; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->skipIfClientSideEncryptionIsNotSupported(); | ||
|
||
if ($this->isStandalone()) { | ||
$this->markTestSkipped('Queryable encryption requires replica sets'); | ||
} | ||
|
||
$this->skipIfServerVersion('<', '7.0.0', 'Queryable encryption requires MongoDB 7.0 or later'); | ||
|
||
$client = static::createTestClient(); | ||
|
||
// Ensure the key vault collection is dropped before each test | ||
$this->keyVaultCollection = $client->getCollection('keyvault', 'datakeys', ['writeConcern' => new WriteConcern(WriteConcern::MAJORITY)]); | ||
$this->keyVaultCollection->drop(); | ||
|
||
$this->clientEncryption = $client->createClientEncryption([ | ||
'keyVaultNamespace' => $this->keyVaultCollection->getNamespace(), | ||
'kmsProviders' => ['local' => ['key' => new Binary(str_repeat("\0", 96)) ]], | ||
]); | ||
|
||
$this->database = $client->getDatabase($this->getDatabaseName()); | ||
} | ||
|
||
public function tearDown(): void | ||
{ | ||
$this->keyVaultCollection->drop(); | ||
} | ||
|
||
/** @see https://jira.mongodb.org/browse/PHPLIB-1702 */ | ||
public function testDatabaseDropCollectionConsultsEncryptedFieldsFromServer(): void | ||
{ | ||
$originalNumCollections = iterator_count($this->database->listCollectionNames()); | ||
|
||
$this->database->createEncryptedCollection( | ||
$this->getCollectionName(), | ||
$this->clientEncryption, | ||
'local', | ||
null, | ||
['encryptedFields' => ['fields' => []]], | ||
); | ||
|
||
// createEncryptedCollection should create three collections | ||
$this->assertCount($originalNumCollections + 3, $this->database->listCollectionNames()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the collection already exists before running the test, this assertion fails. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this only a concern when aborting the test locally (or retrying after a failure)? No objections to dropping it before this first assertion. |
||
|
||
$this->database->dropCollection($this->getCollectionName()); | ||
|
||
$this->assertCount($originalNumCollections, $this->database->listCollectionNames()); | ||
} | ||
|
||
/** @see https://jira.mongodb.org/browse/PHPLIB-1702 */ | ||
public function testCollectionDropConsultsEncryptedFieldsFromServer(): void | ||
{ | ||
$originalNumCollections = iterator_count($this->database->listCollectionNames()); | ||
|
||
$this->database->createEncryptedCollection( | ||
$this->getCollectionName(), | ||
$this->clientEncryption, | ||
'local', | ||
null, | ||
['encryptedFields' => ['fields' => []]], | ||
); | ||
|
||
// createEncryptedCollection should create three collections | ||
$this->assertCount($originalNumCollections + 3, $this->database->listCollectionNames()); | ||
|
||
$this->database->getCollection($this->getCollectionName())->drop(); | ||
|
||
$this->assertCount($originalNumCollections, $this->database->listCollectionNames()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, it seems like we'd want the Manager to be able to report whether autoEncryption is enabled.