Skip to content

PHPLIB-878: Spec tests for queryable encryption range indexes #1064

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

Merged
merged 6 commits into from
Jun 1, 2023

Conversation

jmikola
Copy link
Member

@jmikola jmikola commented Apr 18, 2023

@jmikola jmikola force-pushed the phplib-878 branch 3 times, most recently from bd4352b to 1cfa754 Compare April 24, 2023 09:16
$encryptedFields = Document::fromJSON(file_get_contents(__DIR__ . '/../client-side-encryption/etc/data/range-encryptedFields-' . $type . '.json'));

$database = $this->encryptedClient->selectDatabase($this->getDatabaseName());
$database->dropCollection('explicit_encryption', ['encryptedFields' => $encryptedFields]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to set the encryptedFields when dropping the collection?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is mentioned in "Test Setup" section of 22. Range Explicit Encryption but it's not explained in detail.

In addition to the main collection, queryable encryption uses additional metadata collections. The driver's createCollection() helper makes those when an encryptedFields option is provided. If an encryptedFields option is passed to the drop helper, it will additionally drop those metadata collections. The notable difference is that encryptedFields is actually an option on the create command, but not drop. The option here is entirely used client-side to tell PHPLIB to clean up additional collections. Drop Collection Helper in the CSFLE spec has more detail on that.

@jmikola
Copy link
Member Author

jmikola commented May 29, 2023

Note: test failures on mongodb-latest are due to PHPLIB-1071 and PHPLIB-1115.

@jmikola jmikola force-pushed the phplib-878 branch 2 times, most recently from 62dec14 to 3469567 Compare May 30, 2023 14:59
@jmikola jmikola marked this pull request as ready for review May 30, 2023 14:59
jmikola added 4 commits May 31, 2023 15:21
Most operations that use ASSERT_SAME_DOCUMENT and ASSERT_SAME_DOCUMENTS should technically use ASSERT_MATCHES_DOCUMENT and ASSERT_DOCUMENTS_MATCH, respectively; however, this is the minimum change needed to satisfy new CSFLE spec tests.

Related to dc1bb17
Decimal tests are skipped until bundled libmongocrypt can link a Decimal128 library.

Long tests are skipped pending a workaround for preserving Int64 types in spec tests.
@jmikola jmikola requested a review from GromNaN May 31, 2023 08:25

public function tearDown(): void
{
$this->collection = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't free the Collection instance in other test cases. Did you hit an issue?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since encryptedClient is created with disableClientPersistence, I originally did this to ensure that libmongoc's mongoc_client_t would be destroyed at the end of the test. This has been done before, but usually for session objects to ensure they are returned to the internal pool.

I just tested this locally and can confirm that without this, the Manager objects and mongoc_client_t instances accumulate and are not freed until the end of the test suite (not just the test case). I opened PHPLIB-1154 to track this.

In the meantime, I've added a comment to explain this and removed the unsetting of key1Id, which wasn't necessary.

@@ -723,7 +723,7 @@ private function getResultAssertionTypeForCollection()
return ResultExpectation::ASSERT_NOTHING;
}

return ResultExpectation::ASSERT_SAME_DOCUMENTS;
return ResultExpectation::ASSERT_DOCUMENTS_MATCH;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, you're making the assertion less strict, what's the reason?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is explained in the commit message for 42bce4e. To quote:

Allow extra fields in aggregate results

Most operations that use ASSERT_SAME_DOCUMENT and ASSERT_SAME_DOCUMENTS should technically use ASSERT_MATCHES_DOCUMENT and ASSERT_DOCUMENTS_MATCH, respectively; however, this is the minimum change needed to satisfy new CSFLE spec tests. Related to dc1bb17.

assertSameDocuments() does not permit extra fields in the actual value, while assertDocumentsMatch() does (see: DocumentsMatchConstraint).

The CSFLE legacy test runner inherits rules from the Transactions legacy test runner, which in turn inherits document matching rules from the CRUD v1 runner -- which is where extra fields are permitted, among other things.

Per the commit message above, more operations should be using the same logic here but I wanted to be conservative and avoid making extra changes to the legacy test runner (looking forward to the day we can just delete this code after porting everything to the unified format). No objections if you'd like to create a ticket to look into this at some point.

@jmikola
Copy link
Member Author

jmikola commented Jun 1, 2023

There is one unrelated task failure. I opened PHPLIb-1155 to track that.

@jmikola jmikola merged commit f75d3a8 into mongodb:master Jun 1, 2023
@jmikola jmikola deleted the phplib-878 branch June 1, 2023 01:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants