|
38 | 38 | import unittest.mock |
39 | 39 |
|
40 | 40 | import respx |
| 41 | +from pymongo import MongoClient |
41 | 42 | from pymongo_auth_aws.auth import AwsCredential |
42 | 43 |
|
43 | 44 | from pymongocrypt.asynchronous.auto_encrypter import AsyncAutoEncrypter |
@@ -1013,6 +1014,30 @@ async def test_range_query_int32(self): |
1013 | 1014 | encrypted_val, adjust_range_counter(encrypted_val, expected) |
1014 | 1015 | ) |
1015 | 1016 |
|
| 1017 | + async def test_text_query(self): |
| 1018 | + key_path = "keys/ABCDEFAB123498761234123456789012-local-document.json" |
| 1019 | + key_id = json_data(key_path)["_id"] |
| 1020 | + encrypter = AsyncExplicitEncrypter( |
| 1021 | + MockAsyncCallback( |
| 1022 | + key_docs=[bson_data(key_path)], kms_reply=http_data("kms-reply.txt") |
| 1023 | + ), |
| 1024 | + self.mongo_crypt_opts(), |
| 1025 | + ) |
| 1026 | + self.addCleanup(encrypter.close) |
| 1027 | + |
| 1028 | + text_opts = bson_data("fle2-text-search/textopts.json") |
| 1029 | + expected = bson_data("fle2-text-search/encrypted-payload.json") |
| 1030 | + value = bson.encode({"v": "foo"}) |
| 1031 | + encrypted = await encrypter.encrypt( |
| 1032 | + value, |
| 1033 | + "textPreview", |
| 1034 | + key_id=key_id, |
| 1035 | + query_type="suffixPreview", |
| 1036 | + contention_factor=0, |
| 1037 | + text_opts=text_opts, |
| 1038 | + ) |
| 1039 | + self.assertEqual(encrypted, expected) |
| 1040 | + |
1016 | 1041 |
|
1017 | 1042 | class TestNeedKMSAzureCredentials(unittest.TestCase): |
1018 | 1043 | maxDiff = None |
@@ -1459,6 +1484,30 @@ def test_rangePreview_query_int32(self): |
1459 | 1484 | is_expression=True, |
1460 | 1485 | ) |
1461 | 1486 |
|
| 1487 | + def test_text_query(self): |
| 1488 | + key_path = "keys/ABCDEFAB123498761234123456789012-local-document.json" |
| 1489 | + key_id = json_data(key_path)["_id"] |
| 1490 | + encrypter = ExplicitEncrypter( |
| 1491 | + MockCallback( |
| 1492 | + key_docs=[bson_data(key_path)], kms_reply=http_data("kms-reply.txt") |
| 1493 | + ), |
| 1494 | + self.mongo_crypt_opts(), |
| 1495 | + ) |
| 1496 | + self.addCleanup(encrypter.close) |
| 1497 | + |
| 1498 | + text_opts = bson_data("fle2-text-search/textopts.json") |
| 1499 | + expected = bson_data("fle2-text-search/encrypted-payload.json") |
| 1500 | + value = bson.encode({"v": "foo"}) |
| 1501 | + encrypted = encrypter.encrypt( |
| 1502 | + value, |
| 1503 | + "textPreview", |
| 1504 | + key_id=key_id, |
| 1505 | + query_type="suffixPreview", |
| 1506 | + contention_factor=0, |
| 1507 | + text_opts=text_opts, |
| 1508 | + ) |
| 1509 | + self.assertEqual(encrypted, expected) |
| 1510 | + |
1462 | 1511 |
|
1463 | 1512 | def read(filename, **kwargs): |
1464 | 1513 | with open(os.path.join(DATA_DIR, filename), **kwargs) as fp: |
|
0 commit comments