From ec63738f1111752fc7c68fe0bad08da7b408bc17 Mon Sep 17 00:00:00 2001 From: Jeffrey 'Alex' Clark Date: Mon, 15 Jun 2026 15:08:26 -0400 Subject: [PATCH 1/3] PYTHON-5882 Latest is now enforcing server-side QE --- test/asynchronous/test_encryption.py | 7 +++++++ test/test_encryption.py | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/test/asynchronous/test_encryption.py b/test/asynchronous/test_encryption.py index 455b1940c4..8e42cb2567 100644 --- a/test/asynchronous/test_encryption.py +++ b/test/asynchronous/test_encryption.py @@ -2207,6 +2207,13 @@ async def test_01_insert_encrypted_indexed_and_find(self): self.assertEqual(docs[0]["encryptedIndexed"], val) async def test_02_insert_encrypted_indexed_and_find_contention(self): + # setUp creates the collection with contention=0 (from encryptedFields.json). + # This test uses contention_factor=10, so recreate the collection with contention=10. + await self.db.drop_collection("explicit_encryption", encryptedFields=self.encrypted_fields) + encrypted_fields = copy.deepcopy(self.encrypted_fields) + encrypted_fields["fields"][0]["queries"]["contention"] = 10 + await self.db.command("create", "explicit_encryption", encryptedFields=encrypted_fields) + val = "encrypted indexed value" contention = 10 for _ in range(contention): diff --git a/test/test_encryption.py b/test/test_encryption.py index 7df9e7ac38..afcf809c0e 100644 --- a/test/test_encryption.py +++ b/test/test_encryption.py @@ -2195,6 +2195,13 @@ def test_01_insert_encrypted_indexed_and_find(self): self.assertEqual(docs[0]["encryptedIndexed"], val) def test_02_insert_encrypted_indexed_and_find_contention(self): + # setUp creates the collection with contention=0 (from encryptedFields.json). + # This test uses contention_factor=10, so recreate the collection with contention=10. + self.db.drop_collection("explicit_encryption", encryptedFields=self.encrypted_fields) + encrypted_fields = copy.deepcopy(self.encrypted_fields) + encrypted_fields["fields"][0]["queries"]["contention"] = 10 + self.db.command("create", "explicit_encryption", encryptedFields=encrypted_fields) + val = "encrypted indexed value" contention = 10 for _ in range(contention): From 64838e6a0bd775af6422677238ab35a1d19a9416 Mon Sep 17 00:00:00 2001 From: Jeffrey 'Alex' Clark Date: Mon, 15 Jun 2026 15:18:07 -0400 Subject: [PATCH 2/3] encryptedFields -> encrypted_fields --- test/asynchronous/test_encryption.py | 2 +- test/test_encryption.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/asynchronous/test_encryption.py b/test/asynchronous/test_encryption.py index 8e42cb2567..c6799d1ffe 100644 --- a/test/asynchronous/test_encryption.py +++ b/test/asynchronous/test_encryption.py @@ -2209,7 +2209,7 @@ async def test_01_insert_encrypted_indexed_and_find(self): async def test_02_insert_encrypted_indexed_and_find_contention(self): # setUp creates the collection with contention=0 (from encryptedFields.json). # This test uses contention_factor=10, so recreate the collection with contention=10. - await self.db.drop_collection("explicit_encryption", encryptedFields=self.encrypted_fields) + await self.db.drop_collection("explicit_encryption", encrypted_fields=self.encrypted_fields) encrypted_fields = copy.deepcopy(self.encrypted_fields) encrypted_fields["fields"][0]["queries"]["contention"] = 10 await self.db.command("create", "explicit_encryption", encryptedFields=encrypted_fields) diff --git a/test/test_encryption.py b/test/test_encryption.py index afcf809c0e..48ac8d8850 100644 --- a/test/test_encryption.py +++ b/test/test_encryption.py @@ -2197,7 +2197,7 @@ def test_01_insert_encrypted_indexed_and_find(self): def test_02_insert_encrypted_indexed_and_find_contention(self): # setUp creates the collection with contention=0 (from encryptedFields.json). # This test uses contention_factor=10, so recreate the collection with contention=10. - self.db.drop_collection("explicit_encryption", encryptedFields=self.encrypted_fields) + self.db.drop_collection("explicit_encryption", encrypted_fields=self.encrypted_fields) encrypted_fields = copy.deepcopy(self.encrypted_fields) encrypted_fields["fields"][0]["queries"]["contention"] = 10 self.db.command("create", "explicit_encryption", encryptedFields=encrypted_fields) From ccc0741e6be848ed08c2c6d19b206cc3329e9311 Mon Sep 17 00:00:00 2001 From: Jeffrey 'Alex' Clark Date: Mon, 15 Jun 2026 15:46:06 -0400 Subject: [PATCH 3/3] Remove probabilistic recall testing Using a lower contention factor in a find to return fewer results is no longer testable with the server enforcing strict matching. --- test/asynchronous/test_encryption.py | 15 +-------------- test/test_encryption.py | 15 +-------------- 2 files changed, 2 insertions(+), 28 deletions(-) diff --git a/test/asynchronous/test_encryption.py b/test/asynchronous/test_encryption.py index c6799d1ffe..c48f7efb1b 100644 --- a/test/asynchronous/test_encryption.py +++ b/test/asynchronous/test_encryption.py @@ -2224,20 +2224,7 @@ async def test_02_insert_encrypted_indexed_and_find_contention(self): {"encryptedIndexed": insert_payload} ) - find_payload = await self.client_encryption.encrypt( - val, Algorithm.INDEXED, self.key1_id, query_type=QueryType.EQUALITY, contention_factor=0 - ) - docs = ( - await self.encrypted_client[self.db.name] - .explicit_encryption.find({"encryptedIndexed": find_payload}) - .to_list() - ) - - self.assertLessEqual(len(docs), 10) - for doc in docs: - self.assertEqual(doc["encryptedIndexed"], val) - - # Find with contention_factor will return all 10 documents. + # Find with matching contention_factor returns all 10 documents. find_payload = await self.client_encryption.encrypt( val, Algorithm.INDEXED, diff --git a/test/test_encryption.py b/test/test_encryption.py index 48ac8d8850..56648d3e00 100644 --- a/test/test_encryption.py +++ b/test/test_encryption.py @@ -2212,20 +2212,7 @@ def test_02_insert_encrypted_indexed_and_find_contention(self): {"encryptedIndexed": insert_payload} ) - find_payload = self.client_encryption.encrypt( - val, Algorithm.INDEXED, self.key1_id, query_type=QueryType.EQUALITY, contention_factor=0 - ) - docs = ( - self.encrypted_client[self.db.name] - .explicit_encryption.find({"encryptedIndexed": find_payload}) - .to_list() - ) - - self.assertLessEqual(len(docs), 10) - for doc in docs: - self.assertEqual(doc["encryptedIndexed"], val) - - # Find with contention_factor will return all 10 documents. + # Find with matching contention_factor returns all 10 documents. find_payload = self.client_encryption.encrypt( val, Algorithm.INDEXED,