Skip to content

Commit 8c45daa

Browse files
committed
address comments
1 parent 8770445 commit 8c45daa

File tree

6 files changed

+100
-130
lines changed

6 files changed

+100
-130
lines changed

doc/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ PyMongo 4.12 brings a number of changes including:
88

99
- Support for configuring DEK cache lifetime via the ``key_expiration_ms`` argument to
1010
:class:`~pymongo.encryption_options.AutoEncryptionOpts`.
11+
- Support for $lookup in CSFLE and QE.pr
1112

1213
Issues Resolved
1314
...............

pymongo/asynchronous/encryption.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -251,17 +251,12 @@ async def collection_info(self, database: str, filter: bytes) -> Optional[list[b
251251
:param database: The database on which to run listCollections.
252252
:param filter: The filter to pass to listCollections.
253253
254-
:return: The first document from the listCollections command response as BSON.
254+
:return: The all documents from the listCollections command response as BSON.
255255
"""
256256
async with await self.client_ref()[database].list_collections(
257257
filter=RawBSONDocument(filter)
258258
) as cursor:
259-
lst = []
260-
async for doc in cursor:
261-
lst.append(_dict_to_bson(doc, False, _DATA_KEY_OPTS))
262-
if len(lst) > 0:
263-
return lst
264-
return None
259+
return [_dict_to_bson(doc, False, _DATA_KEY_OPTS) async for doc in cursor]
265260

266261
def spawn(self) -> None:
267262
"""Spawn mongocryptd.

pymongo/synchronous/encryption.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -250,15 +250,10 @@ def collection_info(self, database: str, filter: bytes) -> Optional[list[bytes]]
250250
:param database: The database on which to run listCollections.
251251
:param filter: The filter to pass to listCollections.
252252
253-
:return: The first document from the listCollections command response as BSON.
253+
:return: The all documents from the listCollections command response as BSON.
254254
"""
255255
with self.client_ref()[database].list_collections(filter=RawBSONDocument(filter)) as cursor:
256-
lst = []
257-
for doc in cursor:
258-
lst.append(_dict_to_bson(doc, False, _DATA_KEY_OPTS))
259-
if len(lst) > 0:
260-
return lst
261-
return None
256+
return [_dict_to_bson(doc, False, _DATA_KEY_OPTS) for doc in cursor]
262257

263258
def spawn(self) -> None:
264259
"""Spawn mongocryptd.

test/asynchronous/test_encryption.py

Lines changed: 47 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2426,73 +2426,62 @@ class TestLookupProse(AsyncEncryptionIntegrationTest):
24262426
@async_client_context.require_version_min(7, 0, -1)
24272427
async def asyncSetUp(self):
24282428
await super().asyncSetUp()
2429-
self.encrypted_client = await self.async_rs_or_single_client(
2429+
encrypted_client = await self.async_rs_or_single_client(
24302430
auto_encryption_opts=AutoEncryptionOpts(
24312431
key_vault_namespace="db.keyvault",
24322432
kms_providers={"local": {"key": LOCAL_MASTER_KEY}},
24332433
)
24342434
)
2435-
await self.encrypted_client.db.drop_collection("keyvault")
2435+
await encrypted_client.drop_database("db")
24362436

24372437
key_doc = json_data("etc", "data", "lookup", "key-doc.json")
2438-
key_vault = await create_key_vault(self.encrypted_client.db.keyvault, key_doc)
2438+
key_vault = await create_key_vault(encrypted_client.db.keyvault, key_doc)
24392439
self.addCleanup(key_vault.drop)
24402440

2441-
await self.encrypted_client.db.drop_collection("csfle")
2442-
await self.encrypted_client.db.create_collection(
2441+
await encrypted_client.db.create_collection(
24432442
"csfle",
24442443
validator={"$jsonSchema": json_data("etc", "data", "lookup", "schema-csfle.json")},
24452444
)
2446-
2447-
await self.encrypted_client.db.drop_collection("csfle2")
2448-
await self.encrypted_client.db.create_collection(
2445+
await encrypted_client.db.create_collection(
24492446
"csfle2",
24502447
validator={"$jsonSchema": json_data("etc", "data", "lookup", "schema-csfle2.json")},
24512448
)
2452-
2453-
await self.encrypted_client.db.drop_collection("qe")
2454-
await self.encrypted_client.db.create_collection(
2449+
await encrypted_client.db.create_collection(
24552450
"qe", encryptedFields=json_data("etc", "data", "lookup", "schema-qe.json")
24562451
)
2457-
2458-
await self.encrypted_client.db.drop_collection("qe2")
2459-
await self.encrypted_client.db.create_collection(
2452+
await encrypted_client.db.create_collection(
24602453
"qe2", encryptedFields=json_data("etc", "data", "lookup", "schema-qe2.json")
24612454
)
2455+
await encrypted_client.db.create_collection("no_schema")
2456+
await encrypted_client.db.create_collection("no_schema2")
24622457

2463-
await self.encrypted_client.db.drop_collection("no_schema")
2464-
await self.encrypted_client.db.create_collection("no_schema")
2458+
unencrypted_client = await self.async_rs_or_single_client()
24652459

2466-
await self.encrypted_client.db.drop_collection("no_schema2")
2467-
await self.encrypted_client.db.create_collection("no_schema2")
2468-
2469-
self.unencrypted_client = await self.async_rs_or_single_client()
2470-
2471-
await self.encrypted_client.db.csfle.insert_one({"csfle": "csfle"})
2472-
doc = await self.unencrypted_client.db.csfle.find_one()
2460+
await encrypted_client.db.csfle.insert_one({"csfle": "csfle"})
2461+
doc = await unencrypted_client.db.csfle.find_one()
24732462
self.assertTrue(isinstance(doc["csfle"], Binary))
2474-
await self.encrypted_client.db.csfle2.insert_one({"csfle2": "csfle2"})
2475-
doc = await self.unencrypted_client.db.csfle2.find_one()
2463+
await encrypted_client.db.csfle2.insert_one({"csfle2": "csfle2"})
2464+
doc = await unencrypted_client.db.csfle2.find_one()
24762465
self.assertTrue(isinstance(doc["csfle2"], Binary))
2477-
await self.encrypted_client.db.qe.insert_one({"qe": "qe"})
2478-
doc = await self.unencrypted_client.db.qe.find_one()
2466+
await encrypted_client.db.qe.insert_one({"qe": "qe"})
2467+
doc = await unencrypted_client.db.qe.find_one()
24792468
self.assertTrue(isinstance(doc["qe"], Binary))
2480-
await self.encrypted_client.db.qe2.insert_one({"qe2": "qe2"})
2481-
doc = await self.unencrypted_client.db.qe2.find_one()
2469+
await encrypted_client.db.qe2.insert_one({"qe2": "qe2"})
2470+
doc = await unencrypted_client.db.qe2.find_one()
24822471
self.assertTrue(isinstance(doc["qe2"], Binary))
2483-
await self.encrypted_client.db.no_schema.insert_one({"no_schema": "no_schema"})
2484-
await self.encrypted_client.db.no_schema2.insert_one({"no_schema2": "no_schema2"})
2472+
await encrypted_client.db.no_schema.insert_one({"no_schema": "no_schema"})
2473+
await encrypted_client.db.no_schema2.insert_one({"no_schema2": "no_schema2"})
24852474

24862475
@async_client_context.require_version_min(8, 1, -1)
2487-
async def test_1(self):
2488-
self.encrypted_client = await self.async_rs_or_single_client(
2476+
async def test_1_csfle_joins_no_schema(self):
2477+
encrypted_client = await self.async_rs_or_single_client(
24892478
auto_encryption_opts=AutoEncryptionOpts(
24902479
key_vault_namespace="db.keyvault",
24912480
kms_providers={"local": {"key": LOCAL_MASTER_KEY}},
24922481
)
24932482
)
24942483
doc = await anext(
2495-
await self.encrypted_client.db.csfle.aggregate(
2484+
await encrypted_client.db.csfle.aggregate(
24962485
[
24972486
{"$match": {"csfle": "csfle"}},
24982487
{
@@ -2512,15 +2501,15 @@ async def test_1(self):
25122501
self.assertEqual(doc, {"csfle": "csfle", "matched": [{"no_schema": "no_schema"}]})
25132502

25142503
@async_client_context.require_version_min(8, 1, -1)
2515-
async def test_2(self):
2516-
self.encrypted_client = await self.async_rs_or_single_client(
2504+
async def test_2_qe_joins_no_schema(self):
2505+
encrypted_client = await self.async_rs_or_single_client(
25172506
auto_encryption_opts=AutoEncryptionOpts(
25182507
key_vault_namespace="db.keyvault",
25192508
kms_providers={"local": {"key": LOCAL_MASTER_KEY}},
25202509
)
25212510
)
25222511
doc = await anext(
2523-
await self.encrypted_client.db.qe.aggregate(
2512+
await encrypted_client.db.qe.aggregate(
25242513
[
25252514
{"$match": {"qe": "qe"}},
25262515
{
@@ -2540,15 +2529,15 @@ async def test_2(self):
25402529
self.assertEqual(doc, {"qe": "qe", "matched": [{"no_schema": "no_schema"}]})
25412530

25422531
@async_client_context.require_version_min(8, 1, -1)
2543-
async def test_3(self):
2544-
self.encrypted_client = await self.async_rs_or_single_client(
2532+
async def test_3_no_schema_joins_csfle(self):
2533+
encrypted_client = await self.async_rs_or_single_client(
25452534
auto_encryption_opts=AutoEncryptionOpts(
25462535
key_vault_namespace="db.keyvault",
25472536
kms_providers={"local": {"key": LOCAL_MASTER_KEY}},
25482537
)
25492538
)
25502539
doc = await anext(
2551-
await self.encrypted_client.db.no_schema.aggregate(
2540+
await encrypted_client.db.no_schema.aggregate(
25522541
[
25532542
{"$match": {"no_schema": "no_schema"}},
25542543
{
@@ -2565,15 +2554,15 @@ async def test_3(self):
25652554
self.assertEqual(doc, {"no_schema": "no_schema", "matched": [{"csfle": "csfle"}]})
25662555

25672556
@async_client_context.require_version_min(8, 1, -1)
2568-
async def test_4(self):
2569-
self.encrypted_client = await self.async_rs_or_single_client(
2557+
async def test_4_no_schema_joins_qe(self):
2558+
encrypted_client = await self.async_rs_or_single_client(
25702559
auto_encryption_opts=AutoEncryptionOpts(
25712560
key_vault_namespace="db.keyvault",
25722561
kms_providers={"local": {"key": LOCAL_MASTER_KEY}},
25732562
)
25742563
)
25752564
doc = await anext(
2576-
await self.encrypted_client.db.no_schema.aggregate(
2565+
await encrypted_client.db.no_schema.aggregate(
25772566
[
25782567
{"$match": {"no_schema": "no_schema"}},
25792568
{
@@ -2593,15 +2582,15 @@ async def test_4(self):
25932582
self.assertEqual(doc, {"no_schema": "no_schema", "matched": [{"qe": "qe"}]})
25942583

25952584
@async_client_context.require_version_min(8, 1, -1)
2596-
async def test_5(self):
2597-
self.encrypted_client = await self.async_rs_or_single_client(
2585+
async def test_5_csfle_joins_csfle2(self):
2586+
encrypted_client = await self.async_rs_or_single_client(
25982587
auto_encryption_opts=AutoEncryptionOpts(
25992588
key_vault_namespace="db.keyvault",
26002589
kms_providers={"local": {"key": LOCAL_MASTER_KEY}},
26012590
)
26022591
)
26032592
doc = await anext(
2604-
await self.encrypted_client.db.csfle.aggregate(
2593+
await encrypted_client.db.csfle.aggregate(
26052594
[
26062595
{"$match": {"csfle": "csfle"}},
26072596
{
@@ -2621,15 +2610,15 @@ async def test_5(self):
26212610
self.assertEqual(doc, {"csfle": "csfle", "matched": [{"csfle2": "csfle2"}]})
26222611

26232612
@async_client_context.require_version_min(8, 1, -1)
2624-
async def test_6(self):
2625-
self.encrypted_client = await self.async_rs_or_single_client(
2613+
async def test_6_qe_joins_qe2(self):
2614+
encrypted_client = await self.async_rs_or_single_client(
26262615
auto_encryption_opts=AutoEncryptionOpts(
26272616
key_vault_namespace="db.keyvault",
26282617
kms_providers={"local": {"key": LOCAL_MASTER_KEY}},
26292618
)
26302619
)
26312620
doc = await anext(
2632-
await self.encrypted_client.db.qe.aggregate(
2621+
await encrypted_client.db.qe.aggregate(
26332622
[
26342623
{"$match": {"qe": "qe"}},
26352624
{
@@ -2649,15 +2638,15 @@ async def test_6(self):
26492638
self.assertEqual(doc, {"qe": "qe", "matched": [{"qe2": "qe2"}]})
26502639

26512640
@async_client_context.require_version_min(8, 1, -1)
2652-
async def test_7(self):
2653-
self.encrypted_client = await self.async_rs_or_single_client(
2641+
async def test_7_no_schema_joins_no_schema2(self):
2642+
encrypted_client = await self.async_rs_or_single_client(
26542643
auto_encryption_opts=AutoEncryptionOpts(
26552644
key_vault_namespace="db.keyvault",
26562645
kms_providers={"local": {"key": LOCAL_MASTER_KEY}},
26572646
)
26582647
)
26592648
doc = await anext(
2660-
await self.encrypted_client.db.no_schema.aggregate(
2649+
await encrypted_client.db.no_schema.aggregate(
26612650
[
26622651
{"$match": {"no_schema": "no_schema"}},
26632652
{
@@ -2677,16 +2666,16 @@ async def test_7(self):
26772666
self.assertEqual(doc, {"no_schema": "no_schema", "matched": [{"no_schema2": "no_schema2"}]})
26782667

26792668
@async_client_context.require_version_min(8, 1, -1)
2680-
async def test_8(self):
2681-
self.encrypted_client = await self.async_rs_or_single_client(
2669+
async def test_8_csfle_joins_qe(self):
2670+
encrypted_client = await self.async_rs_or_single_client(
26822671
auto_encryption_opts=AutoEncryptionOpts(
26832672
key_vault_namespace="db.keyvault",
26842673
kms_providers={"local": {"key": LOCAL_MASTER_KEY}},
26852674
)
26862675
)
26872676
with self.assertRaises(PyMongoError) as exc:
26882677
_ = await anext(
2689-
await self.encrypted_client.db.csfle.aggregate(
2678+
await encrypted_client.db.csfle.aggregate(
26902679
[
26912680
{"$match": {"csfle": "qe"}},
26922681
{
@@ -2703,16 +2692,16 @@ async def test_8(self):
27032692
self.assertTrue("not supported" in str(exc))
27042693

27052694
@async_client_context.require_version_max(8, 1, -1)
2706-
async def test_9(self):
2707-
self.encrypted_client = await self.async_rs_or_single_client(
2695+
async def test_9_error(self):
2696+
encrypted_client = await self.async_rs_or_single_client(
27082697
auto_encryption_opts=AutoEncryptionOpts(
27092698
key_vault_namespace="db.keyvault",
27102699
kms_providers={"local": {"key": LOCAL_MASTER_KEY}},
27112700
)
27122701
)
27132702
with self.assertRaises(PyMongoError) as exc:
27142703
_ = await anext(
2715-
await self.encrypted_client.db.csfle.aggregate(
2704+
await encrypted_client.db.csfle.aggregate(
27162705
[
27172706
{"$match": {"csfle": "csfle"}},
27182707
{

0 commit comments

Comments
 (0)