From 6b4fa69de4a821f18a981c857e612939ec0771ad Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Fri, 6 Nov 2026 09:12:47 -0600 Subject: [PATCH 1/4] PYTHON-5959 Drop prefixPreview, suffixPreview, and substringPreview APIs --- .evergreen/generated_configs/tasks.yml | 23 - .evergreen/generated_configs/variants.yml | 6 - .evergreen/scripts/generate_config.py | 31 +- .evergreen/scripts/setup_tests.py | 64 +-- doc/changelog.rst | 5 + pymongo/encryption_shared.py | 34 +- requirements/encryption.txt | 2 +- test/asynchronous/test_encryption.py | 189 +++---- ...encryptedFields-prefix-suffix-preview.json | 44 -- .../encryptedFields-substring-preview.json | 33 -- .../spec/unified/QE-Text-prefixPreview.json | 339 ------------- .../unified/QE-Text-substringPreview.json | 468 ------------------ .../spec/unified/QE-Text-suffixPreview.json | 339 ------------- test/test_encryption.py | 189 +++---- 14 files changed, 172 insertions(+), 1594 deletions(-) delete mode 100644 test/client-side-encryption/etc/data/encryptedFields-prefix-suffix-preview.json delete mode 100644 test/client-side-encryption/etc/data/encryptedFields-substring-preview.json delete mode 100644 test/client-side-encryption/spec/unified/QE-Text-prefixPreview.json delete mode 100644 test/client-side-encryption/spec/unified/QE-Text-substringPreview.json delete mode 100644 test/client-side-encryption/spec/unified/QE-Text-suffixPreview.json diff --git a/.evergreen/generated_configs/tasks.yml b/.evergreen/generated_configs/tasks.yml index 8e2214c680..7af1cb25a4 100644 --- a/.evergreen/generated_configs/tasks.yml +++ b/.evergreen/generated_configs/tasks.yml @@ -4816,29 +4816,6 @@ tasks: - sync - free-threaded - # String query preview tests - - name: test-string-query-preview-v8.2-python3.15-noauth-ssl-replica-set - commands: - - func: run server - vars: - AUTH: noauth - SSL: ssl - TOPOLOGY: replica_set - VERSION: "8.2" - - func: run tests - vars: - AUTH: noauth - SSL: ssl - TOPOLOGY: replica_set - VERSION: "8.2" - UV_PYTHON: "3.15" - tags: - - test-string-query-preview - - server-8.2 - - python-3.15 - - replica_set-noauth-ssl - - noauth - # Test non standard tests - name: test-non-standard-v4.4-python3.12-noauth-ssl-replica-set commands: diff --git a/.evergreen/generated_configs/variants.yml b/.evergreen/generated_configs/variants.yml index 67d069f438..2e5a496a13 100644 --- a/.evergreen/generated_configs/variants.yml +++ b/.evergreen/generated_configs/variants.yml @@ -186,7 +186,6 @@ buildvariants: - name: encryption-rhel8 tasks: - name: .test-non-standard !.python-3.15t - - name: .test-string-query-preview display_name: Encryption RHEL8 run_on: - rhel8.10-small @@ -198,7 +197,6 @@ buildvariants: tasks: - name: .test-non-standard !.cov !.python-3.15t - name: .test-non-standard-no-cov !.python-3.15t - - name: .test-string-query-preview display_name: Encryption macOS run_on: - macos-14 @@ -210,7 +208,6 @@ buildvariants: tasks: - name: .test-non-standard !.cov !.python-3.15t - name: .test-non-standard-no-cov !.python-3.15t - - name: .test-string-query-preview display_name: Encryption Win64 run_on: - windows-2022-latest-small @@ -221,7 +218,6 @@ buildvariants: - name: encryption-crypt_shared-rhel8 tasks: - name: .test-non-standard !.python-3.15t - - name: .test-string-query-preview display_name: Encryption crypt_shared RHEL8 run_on: - rhel8.10-small @@ -234,7 +230,6 @@ buildvariants: tasks: - name: .test-non-standard !.cov !.python-3.15t - name: .test-non-standard-no-cov !.python-3.15t - - name: .test-string-query-preview display_name: Encryption crypt_shared macOS run_on: - macos-14 @@ -247,7 +242,6 @@ buildvariants: tasks: - name: .test-non-standard !.cov !.python-3.15t - name: .test-non-standard-no-cov !.python-3.15t - - name: .test-string-query-preview display_name: Encryption crypt_shared Win64 run_on: - windows-2022-latest-small diff --git a/.evergreen/scripts/generate_config.py b/.evergreen/scripts/generate_config.py index 3589a81c86..c072c32721 100644 --- a/.evergreen/scripts/generate_config.py +++ b/.evergreen/scripts/generate_config.py @@ -151,7 +151,7 @@ def get_encryption_expansions(encryption): ): expansions = get_encryption_expansions(encryption) display_name = get_variant_name(encryption, host, **expansions) - tasks = [".test-non-standard !.python-3.15t", ".test-string-query-preview"] + tasks = [".test-non-standard !.python-3.15t"] if host != "rhel8": # Exclude coverage tasks (encryption suites exceed the 60-min timeout with # coverage overhead on macOS/win64). @@ -160,7 +160,6 @@ def get_encryption_expansions(encryption): tasks = [ ".test-non-standard !.cov !.python-3.15t", ".test-non-standard-no-cov !.python-3.15t", - ".test-string-query-preview", ] variant = create_variant( tasks, @@ -822,34 +821,6 @@ def create_test_non_standard_tasks(): return tasks -def create_string_query_preview_tasks(): - """Tasks for the preview Queryable Encryption string query types. - - The preview query types need a server that is at least 8.2 and older than - 9.0, and ALL_VERSIONS jumps straight from 8.0 to 9.0, so they have nowhere - to run without a dedicated task. setup_tests.py pins the released - pymongocrypt for 8.x, which bundles a libmongocrypt still carrying the - preview types. - """ - python = CPYTHONS[-1] - topology = "replica_set" - auth, ssl = get_standard_auth_ssl(topology) - expansions = dict(AUTH=auth, SSL=ssl, TOPOLOGY=topology, VERSION="8.2") - tags = [ - "test-string-query-preview", - "server-8.2", - f"python-{python}", - f"{topology}-{auth}-{ssl}", - auth, - ] - name = get_task_name("test-string-query-preview", python=python, **expansions) - server_func = FunctionCall(func="run server", vars=expansions) - test_vars = expansions.copy() - test_vars["UV_PYTHON"] = python - test_func = FunctionCall(func="run tests", vars=test_vars) - return [EvgTask(name=name, tags=tags, commands=[server_func, test_func])] - - def create_test_standard_auth_tasks(): """We only use auth on sharded clusters""" tasks = [] diff --git a/.evergreen/scripts/setup_tests.py b/.evergreen/scripts/setup_tests.py index bfa767e342..44d4d77d2a 100644 --- a/.evergreen/scripts/setup_tests.py +++ b/.evergreen/scripts/setup_tests.py @@ -57,8 +57,9 @@ GROUP_MAP = dict(fuzz="fuzz", mockupdb="mockupdb", perf="perf") # The libmongocrypt release used when LIBMONGOCRYPT_URL is not set. Must be at -# least 1.20.0 for the GA "substring" query type. -LIBMONGOCRYPT_VERSION = "1.20.2" +# least 1.21.0; the beta preview string query types were removed in 1.21.0 +# (MONGOCRYPT-938). +LIBMONGOCRYPT_VERSION = "1.21.0" def is_set(var: str) -> bool: @@ -390,44 +391,33 @@ def handle_test_env() -> None: UV_ARGS.append("--extra zstd") if test_name in ["encryption", "kms"]: - # The "String" algorithm and the GA prefix/suffix/substring query types - # need libmongocrypt 1.19.0+, which is only exercised against MongoDB - # 9.0+. Servers before 9.0 test the preview query types instead, which - # need the "textPreview" algorithm, so pin to the released pymongocrypt - # and use the libmongocrypt bundled in its wheel rather than the - # unreleased master build. - # Evergreen exposes the server version as VERSION, not MONGODB_VERSION - # (which is only set inside the separate run_server.py process). - use_pymongocrypt_text_preview = os.environ.get("VERSION", "").startswith("8.") - - if not use_pymongocrypt_text_preview: - # Check for libmongocrypt download. - if not (ROOT / "libmongocrypt").exists(): - setup_libmongocrypt() + # The GA string query types need libmongocrypt 1.19.0+ and the beta + # preview query types were removed in 1.21.0 (PYTHON-5959), so always + # use the master pymongocrypt build against the pinned libmongocrypt + # rather than the lib bundled in the released wheel. + # Check for libmongocrypt download. + if not (ROOT / "libmongocrypt").exists(): + setup_libmongocrypt() if not opts.test_min_deps: - if use_pymongocrypt_text_preview: - UV_ARGS.append("--with pymongocrypt<1.19") - else: - UV_ARGS.append( - "--with pymongocrypt@git+https://github.com/mongodb/libmongocrypt@master#subdirectory=bindings/python" - ) - - if not use_pymongocrypt_text_preview: - # Use the nocrypto build to avoid dependency issues with older windows/python versions. - BASE = get_libmongocrypt_base() - if PLATFORM == "linux": - if (BASE / "lib/libmongocrypt.so").exists(): - PYMONGOCRYPT_LIB = BASE / "lib/libmongocrypt.so" - else: - PYMONGOCRYPT_LIB = BASE / "lib64/libmongocrypt.so" - elif PLATFORM == "darwin": - PYMONGOCRYPT_LIB = BASE / "lib/libmongocrypt.dylib" + UV_ARGS.append( + "--with pymongocrypt@git+https://github.com/mongodb/libmongocrypt@master#subdirectory=bindings/python" + ) + + # Use the nocrypto build to avoid dependency issues with older windows/python versions. + BASE = get_libmongocrypt_base() + if PLATFORM == "linux": + if (BASE / "lib/libmongocrypt.so").exists(): + PYMONGOCRYPT_LIB = BASE / "lib/libmongocrypt.so" else: - PYMONGOCRYPT_LIB = BASE / "bin/mongocrypt.dll" - if not PYMONGOCRYPT_LIB.exists(): - raise RuntimeError("Cannot find libmongocrypt shared object file") - write_env("PYMONGOCRYPT_LIB", PYMONGOCRYPT_LIB.as_posix()) + PYMONGOCRYPT_LIB = BASE / "lib64/libmongocrypt.so" + elif PLATFORM == "darwin": + PYMONGOCRYPT_LIB = BASE / "lib/libmongocrypt.dylib" + else: + PYMONGOCRYPT_LIB = BASE / "bin/mongocrypt.dll" + if not PYMONGOCRYPT_LIB.exists(): + raise RuntimeError("Cannot find libmongocrypt shared object file") + write_env("PYMONGOCRYPT_LIB", PYMONGOCRYPT_LIB.as_posix()) # PATH is updated by configure-env.sh for access to mongocryptd. if test_name == "encryption": diff --git a/doc/changelog.rst b/doc/changelog.rst index dc0e697fdf..eb93a128ef 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -6,6 +6,10 @@ Changes in Version 4.20.0 (2026/XX/XX) - The client handshake metadata now reports a detected coding agent in ``client.env.agent`` (`PYTHON-5929`_). +- Removed the beta ``QueryType.PREFIXPREVIEW``, ``QueryType.SUFFIXPREVIEW``, + and ``QueryType.SUBSTRINGPREVIEW`` query types. Use ``QueryType.PREFIX``, + ``QueryType.SUFFIX``, and ``QueryType.SUBSTRING`` instead (requires MongoDB + 9.0+ and pymongocrypt 1.21.0+) (`PYTHON-5959`_). Bug fixes ......... @@ -36,6 +40,7 @@ Bug fixes Users of Python 3.12 and 3.13 should upgrade to at least those versions (`PYTHON-6182`_). .. _PYTHON-5929: https://jira.mongodb.org/browse/PYTHON-5929 +.. _PYTHON-5959: https://jira.mongodb.org/browse/PYTHON-5959 .. _PYTHON-6172: https://jira.mongodb.org/browse/PYTHON-6172 .. _PYTHON-6149: https://jira.mongodb.org/browse/PYTHON-6149 .. _PYTHON-5873: https://jira.mongodb.org/browse/PYTHON-5873 diff --git a/pymongo/encryption_shared.py b/pymongo/encryption_shared.py index 08c65510d0..96da888c45 100644 --- a/pymongo/encryption_shared.py +++ b/pymongo/encryption_shared.py @@ -107,6 +107,10 @@ class Algorithm(str, enum.Enum): class QueryType(str, enum.Enum): """An enum that defines the supported values for explicit encryption query_type. + .. versionchanged:: 4.20 + Removed the beta query types ``PREFIXPREVIEW``, ``SUFFIXPREVIEW``, + and ``SUBSTRINGPREVIEW``. + .. versionadded:: 4.2 """ @@ -143,36 +147,6 @@ class QueryType(str, enum.Enum): .. versionadded:: 4.18 """ - PREFIXPREVIEW = "prefixPreview" - """**BETA** - Used to encrypt a value for a prefixPreview query. - - .. note:: The preview query types are for experimental workloads only and - are only supported by MongoDB versions before 9.0. Use - :attr:`QueryType.PREFIX` instead. - - .. versionadded:: 4.15 - """ - - SUFFIXPREVIEW = "suffixPreview" - """**BETA** - Used to encrypt a value for a suffixPreview query. - - .. note:: The preview query types are for experimental workloads only and - are only supported by MongoDB versions before 9.0. Use - :attr:`QueryType.SUFFIX` instead. - - .. versionadded:: 4.15 - """ - - SUBSTRINGPREVIEW = "substringPreview" - """**BETA** - Used to encrypt a value for a substringPreview query. - - .. note:: The preview query types are for experimental workloads only and - are only supported by MongoDB versions before 9.0. Use - :attr:`QueryType.SUBSTRING` instead. - - .. versionadded:: 4.15 - """ - def _create_mongocrypt_options(**kwargs: Any) -> MongoCryptOptions: # For compat with pymongocrypt <1.13, avoid setting the default key_expiration_ms. diff --git a/requirements/encryption.txt b/requirements/encryption.txt index 10aa1db198..46bc17225b 100644 --- a/requirements/encryption.txt +++ b/requirements/encryption.txt @@ -1,3 +1,3 @@ pymongo-auth-aws>=1.3.0,<2.0.0 -pymongocrypt>=1.18.1,<2.0.0 +pymongocrypt>=1.21.0,<2.0.0 certifi>=2023.7.22;os.name=='nt' or sys_platform=='darwin' diff --git a/test/asynchronous/test_encryption.py b/test/asynchronous/test_encryption.py index bc7e311843..4983027ebf 100644 --- a/test/asynchronous/test_encryption.py +++ b/test/asynchronous/test_encryption.py @@ -248,9 +248,8 @@ async def test_kwargs(self): def _string_opts_kwargs(**kwargs: Any) -> dict[str, StringOpts]: """Pass StringOpts under the name the installed pymongocrypt accepts. - pymongocrypt renamed ``text_opts`` to ``string_opts`` in 1.19 and takes only - one of the two, and the preview query types still run against pymongocrypt - before 1.19, so both spellings are in play across the matrix. + pymongocrypt renamed ``text_opts`` to ``string_opts`` in 1.19 and accepts + only one of the two names per release, so the tests follow the binding. """ return {encryption._string_opts_kwarg(): StringOpts(**kwargs)} @@ -302,6 +301,16 @@ def test_string_opts_kwarg_matches_binding(self): self.assertIn(encryption._string_opts_kwarg(), params) +class TestPreviewQueryTypesRemoved(AsyncPyMongoTestCase): + def test_preview_query_types_removed(self): + # PYTHON-5959: the beta preview query types were removed in 4.20. + for name in ("PREFIXPREVIEW", "SUFFIXPREVIEW", "SUBSTRINGPREVIEW"): + self.assertFalse(hasattr(QueryType, name), name) + for value in ("prefixPreview", "suffixPreview", "substringPreview"): + with self.assertRaises(ValueError): + QueryType(value) + + class AsyncEncryptionIntegrationTest(AsyncIntegrationTest): """Base class for encryption integration tests.""" @@ -3409,43 +3418,30 @@ def _libmongocrypt_at_least(*version): return Version.from_string(libmongocrypt_version()) >= Version(*version) -# The minimum libmongocrypt version required by each string query type, declared -# in one place so the test gates and the changelog agree. Support landed per -# query type rather than all at once (see the libmongocrypt changelog): -# 1.18.1 - fixes caseSensitive/diacriticSensitive handling for "textPreview". -# 1.19.0 - the "string" algorithm replaces "textPreview"; prefix and suffix go -# stable; prefixPreview and suffixPreview are removed. -# 1.19.1 - prefixPreview and suffixPreview are restored. +# The minimum libmongocrypt version required by each GA string query type, +# declared in one place so the test gates and the changelog agree. Support +# landed per query type rather than all at once (see the libmongocrypt +# changelog): +# 1.19.0 - the "string" algorithm replaces "textPreview"; prefix and suffix +# go stable. # 1.20.0 - substring goes stable. +# 1.21.0 - the beta prefixPreview/suffixPreview/substringPreview query types +# became a runtime error (MONGOCRYPT-938) and were dropped in +# PYTHON-5959. _STRING_QUERY_MIN_LIBMONGOCRYPT = { "prefix": (1, 19, 0), "suffix": (1, 19, 0), "substring": (1, 20, 0), - "prefixPreview": (1, 18, 1), - "suffixPreview": (1, 18, 1), - "substringPreview": (1, 18, 1), } -# prefixPreview and suffixPreview were removed in 1.19.0 and restored in 1.19.1, -# so that one release is a hole rather than a floor. -_PREVIEW_REMOVED_IN = (1, 19, 0) - -# No pymongocrypt release ships libmongocrypt 1.19.0+, so the GA query types can -# only run against a master build; setup_tests.py pins the released binding for -# the 8.x preview tasks alone. Do not collapse that gate: the released binding -# still spells the parameter text_opts, and dropping back to it would silently -# stop exercising the GA path. - # https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.md#27-string-explicit-encryption class TestStringExplicitEncryptionProse(AsyncEncryptionIntegrationTest): - # The GA collections require server 9.0+, the preview collections require - # server pre-9.0. Setup encrypts with the "String" algorithm on 9.0+ and the - # deprecated "textPreview" algorithm on earlier servers, since "String" was - # only introduced in libmongocrypt 1.19.0. + # The GA collections require server 9.0+, where the "String" algorithm and + # the GA query types are supported. @async_client_context.require_no_standalone - @async_client_context.require_version_min(8, 2, -1) - @async_client_context.require_libmongocrypt_min(1, 18, 1) + @async_client_context.require_version_min(9, 0, -1) + @async_client_context.require_libmongocrypt_min(1, 19, 0) @async_client_context.require_pymongocrypt_min(1, 16, 0) async def asyncSetUp(self): await super().asyncSetUp() @@ -3481,39 +3477,18 @@ async def asyncSetUp(self): ) ) - # The GA query types ("prefix", "suffix", "substring") require server - # 9.0+, which in turn dropped the preview query types. - self.is_ga = async_client_context.version.at_least(9, 0, -1) - # The "String" algorithm was added in libmongocrypt 1.19.0. Servers - # before 9.0 are tested against libmongocrypt 1.18.x, where the preview - # query types are only usable via the deprecated "textPreview" - # algorithm, so pick whichever the running combination supports. - self.algorithm = ( - Algorithm.STRING if _libmongocrypt_at_least(1, 19, 0) else Algorithm.TEXTPREVIEW - ) - # The GA query types need the "String" algorithm, so skip before setup - # encrypts anything rather than erroring on an unsupported combination. - if self.is_ga and not _libmongocrypt_at_least(1, 19, 0): - raise unittest.SkipTest("server 9.0+ string queries require libmongocrypt 1.19.0+") # Substring went stable in a later libmongocrypt than prefix and suffix, # so its fixture is only built where the query type exists. Otherwise # setup would fail before the substring cases could skip, taking the # prefix and suffix cases down with it. - self.has_substring = _libmongocrypt_at_least( - *_STRING_QUERY_MIN_LIBMONGOCRYPT["substring" if self.is_ga else "substringPreview"] - ) + self.has_substring = _libmongocrypt_at_least(*_STRING_QUERY_MIN_LIBMONGOCRYPT["substring"]) # Using QE CreateCollection() and Collection.Drop(), drop and create the # collections with majority write concern. db = self.client_encrypted.db - if self.is_ga: - collections = ["prefix-suffix", "prefix-suffix-ci-di"] - if self.has_substring: - collections += ["substring", "substring-ci-di"] - else: - collections = ["prefix-suffix-preview"] - if self.has_substring: - collections += ["substring-preview"] + collections = ["prefix-suffix", "prefix-suffix-ci-di"] + if self.has_substring: + collections += ["substring", "substring-ci-di"] for name in collections: await db.drop_collection(name) await self.client_encryption.create_encrypted_collection( @@ -3527,7 +3502,7 @@ async def asyncSetUp(self): encrypted_value = await self.client_encryption.encrypt( "foobarbaz", key_id=self.key1_id, - algorithm=self.algorithm, + algorithm=Algorithm.STRING, contention_factor=0, **_string_opts_kwargs( case_sensitive=True, @@ -3537,19 +3512,15 @@ async def asyncSetUp(self): ), ) # Use explicitEncryptedClient to insert the following document into - # db.prefix-suffix (if created) and db.prefix-suffix-preview (if created) - # with majority write concern. - await self._insert( - "prefix-suffix" if self.is_ga else "prefix-suffix-preview", - {"_id": 0, "encryptedText": encrypted_value}, - ) + # db.prefix-suffix with majority write concern. + await self._insert("prefix-suffix", {"_id": 0, "encryptedText": encrypted_value}) if self.has_substring: # Use clientEncryption to encrypt the string "foobarbaz" with the following EncryptOpts. encrypted_value = await self.client_encryption.encrypt( "foobarbaz", key_id=self.key1_id, - algorithm=self.algorithm, + algorithm=Algorithm.STRING, contention_factor=0, **_string_opts_kwargs( case_sensitive=True, @@ -3558,12 +3529,8 @@ async def asyncSetUp(self): ), ) # Use explicitEncryptedClient to insert the following document into - # db.substring (if created) and db.substring-preview (if created) with - # majority write concern. - await self._insert( - "substring" if self.is_ga else "substring-preview", - {"_id": 0, "encryptedText": encrypted_value}, - ) + # db.substring with majority write concern. + await self._insert("substring", {"_id": 0, "encryptedText": encrypted_value}) async def _insert(self, collection, document, client=None): """Insert a document with majority write concern.""" @@ -3578,42 +3545,12 @@ def _require_query_type(self, query_type): raise unittest.SkipTest( f"queryType={query_type} requires libmongocrypt {'.'.join(map(str, required))}+" ) - if query_type in ("prefixPreview", "suffixPreview") and ( - _libmongocrypt_at_least(*_PREVIEW_REMOVED_IN) and not _libmongocrypt_at_least(1, 19, 1) - ): - raise unittest.SkipTest(f"queryType={query_type} was removed in libmongocrypt 1.19.0") - - def _params(self, kind): - """Return the (query_type, collection) pair to run a case against. - - Each case runs against the GA query type on server 9.0+ and against the - preview query type on earlier servers, skipping when the installed - libmongocrypt is too old for the applicable variant. - """ - base = "substring" if kind == "substring" else "prefix-suffix" - if self.is_ga: - query_type, collection = kind, base - else: - query_type, collection = f"{kind}Preview", f"{base}-preview" - self._require_query_type(query_type) - return query_type, collection - - def _require_ga(self, *query_types): - """Skip a case that only applies to the GA query types. - - Gates on each query type the case exercises, since substring support - landed in a later libmongocrypt than prefix and suffix. - """ - if not self.is_ga: - raise unittest.SkipTest("requires server 9.0+") - for query_type in query_types: - self._require_query_type(query_type) async def _encrypt(self, value, query_type=None, **string_opts): return await self.client_encryption.encrypt( value, key_id=self.key1_id, - algorithm=self.algorithm, + algorithm=Algorithm.STRING, query_type=query_type, contention_factor=0, **_string_opts_kwargs(**string_opts), @@ -3626,18 +3563,19 @@ async def _find(self, collection, filter): return value async def test_01_can_find_a_document_by_prefix(self): - query_type, collection = self._params("prefix") + # Requires MongoDB server 9.0.0+ and libmongocrypt 1.19.0+. + self._require_query_type("prefix") # Use clientEncryption.encrypt() to encrypt the string "foo". encrypted_value = await self._encrypt( "foo", - query_type=query_type, + query_type=QueryType.PREFIX, case_sensitive=True, diacritic_sensitive=True, prefix=dict(strMaxQueryLength=10, strMinQueryLength=2), ) # Use explicitEncryptedClient to run a "find" operation. value = await self._find( - collection, + "prefix-suffix", { "$expr": { "$encStrStartsWith": {"input": "$encryptedText", "prefix": encrypted_value} @@ -3648,36 +3586,38 @@ async def test_01_can_find_a_document_by_prefix(self): self.assertEqual(value, {"_id": 0, "encryptedText": "foobarbaz"}) async def test_02_can_find_a_document_by_suffix(self): - query_type, collection = self._params("suffix") + # Requires MongoDB server 9.0.0+ and libmongocrypt 1.19.0+. + self._require_query_type("suffix") # Use clientEncryption.encrypt() to encrypt the string "baz". encrypted_value = await self._encrypt( "baz", - query_type=query_type, + query_type=QueryType.SUFFIX, case_sensitive=True, diacritic_sensitive=True, suffix=dict(strMaxQueryLength=10, strMinQueryLength=2), ) # Use explicitEncryptedClient to run a "find" operation. value = await self._find( - collection, + "prefix-suffix", {"$expr": {"$encStrEndsWith": {"input": "$encryptedText", "suffix": encrypted_value}}}, ) # Assert the following document is returned. self.assertEqual(value, {"_id": 0, "encryptedText": "foobarbaz"}) async def test_03_no_document_found_by_prefix(self): - query_type, collection = self._params("prefix") + # Requires MongoDB server 9.0.0+ and libmongocrypt 1.19.0+. + self._require_query_type("prefix") # Use clientEncryption.encrypt() to encrypt the string "baz". encrypted_value = await self._encrypt( "baz", - query_type=query_type, + query_type=QueryType.PREFIX, case_sensitive=True, diacritic_sensitive=True, prefix=dict(strMaxQueryLength=10, strMinQueryLength=2), ) # Use explicitEncryptedClient to run a "find" operation. value = await self._find( - collection, + "prefix-suffix", { "$expr": { "$encStrStartsWith": {"input": "$encryptedText", "prefix": encrypted_value} @@ -3688,36 +3628,38 @@ async def test_03_no_document_found_by_prefix(self): self.assertIsNone(value) async def test_04_no_document_found_by_suffix(self): - query_type, collection = self._params("suffix") + # Requires MongoDB server 9.0.0+ and libmongocrypt 1.19.0+. + self._require_query_type("suffix") # Use clientEncryption.encrypt() to encrypt the string "foo". encrypted_value = await self._encrypt( "foo", - query_type=query_type, + query_type=QueryType.SUFFIX, case_sensitive=True, diacritic_sensitive=True, suffix=dict(strMaxQueryLength=10, strMinQueryLength=2), ) # Use explicitEncryptedClient to run a "find" operation. value = await self._find( - collection, + "prefix-suffix", {"$expr": {"$encStrEndsWith": {"input": "$encryptedText", "suffix": encrypted_value}}}, ) # Assert that no documents are returned. self.assertIsNone(value) async def test_05_can_find_a_document_by_substring(self): - query_type, collection = self._params("substring") + # Requires MongoDB server 9.0.0+ and libmongocrypt 1.20.0+. + self._require_query_type("substring") # Use clientEncryption.encrypt() to encrypt the string "bar". encrypted_value = await self._encrypt( "bar", - query_type=query_type, + query_type=QueryType.SUBSTRING, case_sensitive=True, diacritic_sensitive=True, substring=dict(strMaxLength=10, strMaxQueryLength=6, strMinQueryLength=2), ) # Use explicitEncryptedClient to run a "find" operation. value = await self._find( - collection, + "substring", { "$expr": { "$encStrContains": {"input": "$encryptedText", "substring": encrypted_value} @@ -3728,18 +3670,19 @@ async def test_05_can_find_a_document_by_substring(self): self.assertEqual(value, {"_id": 0, "encryptedText": "foobarbaz"}) async def test_06_no_document_found_by_substring(self): - query_type, collection = self._params("substring") + # Requires MongoDB server 9.0.0+ and libmongocrypt 1.20.0+. + self._require_query_type("substring") # Use clientEncryption.encrypt() to encrypt the string "qux". encrypted_value = await self._encrypt( "qux", - query_type=query_type, + query_type=QueryType.SUBSTRING, case_sensitive=True, diacritic_sensitive=True, substring=dict(strMaxLength=10, strMaxQueryLength=6, strMinQueryLength=2), ) # Use explicitEncryptedClient to run a "find" operation. value = await self._find( - collection, + "substring", { "$expr": { "$encStrContains": {"input": "$encryptedText", "substring": encrypted_value} @@ -3752,7 +3695,7 @@ async def test_06_no_document_found_by_substring(self): async def test_07_contentionFactor_is_required(self): from pymongocrypt.errors import MongoCryptError - self._require_ga("prefix") + self._require_query_type("prefix") # Use clientEncryption.encrypt() to encrypt the string "foo" without contentionFactor. with self.assertRaises(EncryptionError) as ctx: await self.client_encryption.encrypt( @@ -3773,7 +3716,8 @@ async def test_07_contentionFactor_is_required(self): async def test_08_case_insensitive_prefix_and_suffix(self): # This is a regression test for DRIVERS-3470. - self._require_ga("prefix", "suffix") + self._require_query_type("prefix") + self._require_query_type("suffix") # Use autoEncryptedClient to insert the following document. await self._insert( "prefix-suffix-ci-di", {"encryptedText": "BingQiLin"}, self.client_auto_encrypted @@ -3816,7 +3760,8 @@ async def test_08_case_insensitive_prefix_and_suffix(self): async def test_09_diacritic_insensitive_prefix_and_suffix(self): # This is a regression test for DRIVERS-3470. - self._require_ga("prefix", "suffix") + self._require_query_type("prefix") + self._require_query_type("suffix") # Use autoEncryptedClient to insert the following document. await self._insert( "prefix-suffix-ci-di", {"encryptedText": "cafébarbäz"}, self.client_auto_encrypted @@ -3859,7 +3804,7 @@ async def test_09_diacritic_insensitive_prefix_and_suffix(self): async def test_10_case_insensitive_substring(self): # This is a regression test for DRIVERS-3470. - self._require_ga("substring") + self._require_query_type("substring") # Use autoEncryptedClient to insert the following document. await self._insert( "substring-ci-di", {"encryptedText": "FooBarBaz"}, self.client_auto_encrypted @@ -3886,7 +3831,7 @@ async def test_10_case_insensitive_substring(self): async def test_11_diacritic_insensitive_substring(self): # This is a regression test for DRIVERS-3470. - self._require_ga("substring") + self._require_query_type("substring") # Use autoEncryptedClient to insert the following document. await self._insert( "substring-ci-di", {"encryptedText": "foocafébaz"}, self.client_auto_encrypted diff --git a/test/client-side-encryption/etc/data/encryptedFields-prefix-suffix-preview.json b/test/client-side-encryption/etc/data/encryptedFields-prefix-suffix-preview.json deleted file mode 100644 index 047064beb1..0000000000 --- a/test/client-side-encryption/etc/data/encryptedFields-prefix-suffix-preview.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "fields": [ - { - "keyId": { - "$binary": { - "base64": "EjRWeBI0mHYSNBI0VniQEg==", - "subType": "04" - } - }, - "path": "encryptedText", - "bsonType": "string", - "queries": [ - { - "queryType": "prefixPreview", - "strMinQueryLength": { - "$numberInt": "2" - }, - "strMaxQueryLength": { - "$numberInt": "10" - }, - "contention": { - "$numberLong": "0" - }, - "caseSensitive": true, - "diacriticSensitive": true - }, - { - "queryType": "suffixPreview", - "strMinQueryLength": { - "$numberInt": "2" - }, - "strMaxQueryLength": { - "$numberInt": "10" - }, - "contention": { - "$numberLong": "0" - }, - "caseSensitive": true, - "diacriticSensitive": true - } - ] - } - ] -} diff --git a/test/client-side-encryption/etc/data/encryptedFields-substring-preview.json b/test/client-side-encryption/etc/data/encryptedFields-substring-preview.json deleted file mode 100644 index a519edc627..0000000000 --- a/test/client-side-encryption/etc/data/encryptedFields-substring-preview.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "fields": [ - { - "keyId": { - "$binary": { - "base64": "EjRWeBI0mHYSNBI0VniQEg==", - "subType": "04" - } - }, - "path": "encryptedText", - "bsonType": "string", - "queries": [ - { - "queryType": "substringPreview", - "strMaxLength": { - "$numberInt": "10" - }, - "strMinQueryLength": { - "$numberInt": "2" - }, - "strMaxQueryLength": { - "$numberInt": "6" - }, - "contention": { - "$numberLong": "0" - }, - "caseSensitive": true, - "diacriticSensitive": true - } - ] - } - ] -} diff --git a/test/client-side-encryption/spec/unified/QE-Text-prefixPreview.json b/test/client-side-encryption/spec/unified/QE-Text-prefixPreview.json deleted file mode 100644 index 51e72fd3ca..0000000000 --- a/test/client-side-encryption/spec/unified/QE-Text-prefixPreview.json +++ /dev/null @@ -1,339 +0,0 @@ -{ - "description": "QE-Text-prefixPreview", - "schemaVersion": "1.25", - "runOnRequirements": [ - { - "minServerVersion": "8.2.0", - "maxServerVersion": "8.99.99", - "topologies": [ - "replicaset", - "sharded", - "load-balanced" - ], - "csfle": { - "minLibmongocryptVersion": "1.19.1" - } - } - ], - "createEntities": [ - { - "client": { - "id": "client", - "autoEncryptOpts": { - "keyVaultNamespace": "keyvault.datakeys", - "kmsProviders": { - "local": { - "key": "Mng0NCt4ZHVUYUJCa1kxNkVyNUR1QURhZ2h2UzR2d2RrZzh0cFBwM3R6NmdWMDFBMUN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk" - } - } - }, - "observeEvents": [ - "commandStartedEvent" - ] - } - }, - { - "database": { - "id": "db", - "client": "client", - "databaseName": "db" - } - }, - { - "collection": { - "id": "coll", - "database": "db", - "collectionName": "coll" - } - } - ], - "initialData": [ - { - "databaseName": "keyvault", - "collectionName": "datakeys", - "documents": [ - { - "_id": { - "$binary": { - "base64": "q83vqxI0mHYSNBI0VniQEg==", - "subType": "04" - } - }, - "keyMaterial": { - "$binary": { - "base64": "HBk9BWihXExNDvTp1lUxOuxuZK2Pe2ZdVdlsxPEBkiO1bS4mG5NNDsQ7zVxJAH8BtdOYp72Ku4Y3nwc0BUpIKsvAKX4eYXtlhv5zUQxWdeNFhg9qK7qb8nqhnnLeT0f25jFSqzWJoT379hfwDeu0bebJHr35QrJ8myZdPMTEDYF08QYQ48ShRBli0S+QzBHHAQiM2iJNr4svg2WR8JSeWQ==", - "subType": "00" - } - }, - "creationDate": { - "$date": { - "$numberLong": "1648914851981" - } - }, - "updateDate": { - "$date": { - "$numberLong": "1648914851981" - } - }, - "status": { - "$numberInt": "0" - }, - "masterKey": { - "provider": "local" - } - } - ] - }, - { - "databaseName": "db", - "collectionName": "coll", - "documents": [], - "createOptions": { - "encryptedFields": { - "fields": [ - { - "keyId": { - "$binary": { - "base64": "q83vqxI0mHYSNBI0VniQEg==", - "subType": "04" - } - }, - "path": "encryptedText", - "bsonType": "string", - "queries": [ - { - "queryType": "prefixPreview", - "contention": { - "$numberLong": "0" - }, - "strMinQueryLength": { - "$numberLong": "3" - }, - "strMaxQueryLength": { - "$numberLong": "30" - }, - "caseSensitive": true, - "diacriticSensitive": true - } - ] - } - ] - } - } - } - ], - "tests": [ - { - "description": "Insert QE prefixPreview", - "operations": [ - { - "name": "insertOne", - "arguments": { - "document": { - "_id": 1, - "encryptedText": "foobar" - } - }, - "object": "coll" - } - ], - "expectEvents": [ - { - "client": "client", - "events": [ - { - "commandStartedEvent": { - "command": { - "listCollections": 1, - "filter": { - "name": "coll" - } - }, - "commandName": "listCollections" - } - }, - { - "commandStartedEvent": { - "command": { - "find": "datakeys", - "filter": { - "$or": [ - { - "_id": { - "$in": [ - { - "$binary": { - "base64": "q83vqxI0mHYSNBI0VniQEg==", - "subType": "04" - } - } - ] - } - }, - { - "keyAltNames": { - "$in": [] - } - } - ] - }, - "$db": "keyvault", - "readConcern": { - "level": "majority" - } - }, - "commandName": "find" - } - }, - { - "commandStartedEvent": { - "command": { - "insert": "coll", - "documents": [ - { - "_id": 1, - "encryptedText": { - "$$type": "binData" - } - } - ], - "ordered": true - }, - "commandName": "insert" - } - } - ] - } - ] - }, - { - "description": "Query with matching $encStrStartsWith", - "operations": [ - { - "name": "insertOne", - "arguments": { - "document": { - "_id": 1, - "encryptedText": "foobar" - } - }, - "object": "coll" - }, - { - "name": "find", - "arguments": { - "filter": { - "$expr": { - "$encStrStartsWith": { - "input": "$encryptedText", - "prefix": "foo" - } - } - } - }, - "object": "coll", - "expectResult": [ - { - "_id": { - "$numberInt": "1" - }, - "encryptedText": "foobar", - "__safeContent__": [ - { - "$binary": { - "base64": "wpaMBVDjL4bHf9EtSP52PJFzyNn1R19+iNI/hWtvzdk=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "fmUMXTMV/XRiN0IL3VXxSEn6SQG9E6Po30kJKB8JJlQ=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "vZIDMiFDgjmLNYVrrbnq1zT4hg7sGpe/PMtighSsnRc=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "26Z5G+sHTzV3D7F8Y0m08389USZ2afinyFV3ez9UEBQ=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "q/JEq8of7bE0QE5Id0XuOsNQ4qVpANYymcPQDUL2Ywk=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "Uvvv46LkfbgLoPqZ6xTBzpgoYRTM6FUgRdqZ9eaVojI=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "nMxdq2lladuBJA3lv3JC2MumIUtRJBNJVLp3PVE6nQk=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "hS3V0qq5CF/SkTl3ZWWWgXcAJ8G5yGtkY2RwcHNc5Oc=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "McgwYUxfKj5+4D0vskZymy4KA82s71MR25iV/Enutww=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "Ciqdk1b+t+Vrr6oIlFFk0Zdym5BPmwN3glQ0/VcsVdM=", - "subType": "00" - } - } - ] - } - ] - } - ] - }, - { - "description": "Query with non-matching $encStrStartsWith", - "operations": [ - { - "name": "insertOne", - "arguments": { - "document": { - "_id": 1, - "encryptedText": "foobar" - } - }, - "object": "coll" - }, - { - "name": "find", - "arguments": { - "filter": { - "$expr": { - "$encStrStartsWith": { - "input": "$encryptedText", - "prefix": "bar" - } - } - } - }, - "object": "coll", - "expectResult": [] - } - ] - } - ] -} diff --git a/test/client-side-encryption/spec/unified/QE-Text-substringPreview.json b/test/client-side-encryption/spec/unified/QE-Text-substringPreview.json deleted file mode 100644 index 1df3170958..0000000000 --- a/test/client-side-encryption/spec/unified/QE-Text-substringPreview.json +++ /dev/null @@ -1,468 +0,0 @@ -{ - "description": "QE-Text-substringPreview", - "schemaVersion": "1.25", - "runOnRequirements": [ - { - "minServerVersion": "8.2.0", - "maxServerVersion": "8.99.99", - "topologies": [ - "replicaset", - "sharded", - "load-balanced" - ], - "csfle": { - "minLibmongocryptVersion": "1.15.0" - } - } - ], - "createEntities": [ - { - "client": { - "id": "client", - "autoEncryptOpts": { - "keyVaultNamespace": "keyvault.datakeys", - "kmsProviders": { - "local": { - "key": "Mng0NCt4ZHVUYUJCa1kxNkVyNUR1QURhZ2h2UzR2d2RrZzh0cFBwM3R6NmdWMDFBMUN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk" - } - } - }, - "observeEvents": [ - "commandStartedEvent" - ] - } - }, - { - "database": { - "id": "db", - "client": "client", - "databaseName": "db" - } - }, - { - "collection": { - "id": "coll", - "database": "db", - "collectionName": "coll" - } - } - ], - "initialData": [ - { - "databaseName": "keyvault", - "collectionName": "datakeys", - "documents": [ - { - "_id": { - "$binary": { - "base64": "q83vqxI0mHYSNBI0VniQEg==", - "subType": "04" - } - }, - "keyMaterial": { - "$binary": { - "base64": "HBk9BWihXExNDvTp1lUxOuxuZK2Pe2ZdVdlsxPEBkiO1bS4mG5NNDsQ7zVxJAH8BtdOYp72Ku4Y3nwc0BUpIKsvAKX4eYXtlhv5zUQxWdeNFhg9qK7qb8nqhnnLeT0f25jFSqzWJoT379hfwDeu0bebJHr35QrJ8myZdPMTEDYF08QYQ48ShRBli0S+QzBHHAQiM2iJNr4svg2WR8JSeWQ==", - "subType": "00" - } - }, - "creationDate": { - "$date": { - "$numberLong": "1648914851981" - } - }, - "updateDate": { - "$date": { - "$numberLong": "1648914851981" - } - }, - "status": { - "$numberInt": "0" - }, - "masterKey": { - "provider": "local" - } - } - ] - }, - { - "databaseName": "db", - "collectionName": "coll", - "documents": [], - "createOptions": { - "encryptedFields": { - "fields": [ - { - "keyId": { - "$binary": { - "base64": "q83vqxI0mHYSNBI0VniQEg==", - "subType": "04" - } - }, - "path": "encryptedText", - "bsonType": "string", - "queries": [ - { - "queryType": "substringPreview", - "contention": { - "$numberLong": "0" - }, - "strMinQueryLength": { - "$numberLong": "3" - }, - "strMaxQueryLength": { - "$numberLong": "6" - }, - "strMaxLength": { - "$numberLong": "20" - }, - "caseSensitive": true, - "diacriticSensitive": true - } - ] - } - ] - } - } - } - ], - "tests": [ - { - "description": "Insert QE substringPreview", - "operations": [ - { - "name": "insertOne", - "arguments": { - "document": { - "_id": 1, - "encryptedText": "foobar" - } - }, - "object": "coll" - } - ], - "expectEvents": [ - { - "client": "client", - "events": [ - { - "commandStartedEvent": { - "command": { - "listCollections": 1, - "filter": { - "name": "coll" - } - }, - "commandName": "listCollections" - } - }, - { - "commandStartedEvent": { - "command": { - "find": "datakeys", - "filter": { - "$or": [ - { - "_id": { - "$in": [ - { - "$binary": { - "base64": "q83vqxI0mHYSNBI0VniQEg==", - "subType": "04" - } - } - ] - } - }, - { - "keyAltNames": { - "$in": [] - } - } - ] - }, - "$db": "keyvault", - "readConcern": { - "level": "majority" - } - }, - "commandName": "find" - } - }, - { - "commandStartedEvent": { - "command": { - "insert": "coll", - "documents": [ - { - "_id": 1, - "encryptedText": { - "$$type": "binData" - } - } - ], - "ordered": true - }, - "commandName": "insert" - } - } - ] - } - ] - }, - { - "description": "Query with matching $encStrContains", - "operations": [ - { - "name": "insertOne", - "arguments": { - "document": { - "_id": 1, - "encryptedText": "foobar" - } - }, - "object": "coll" - }, - { - "name": "find", - "arguments": { - "filter": { - "$expr": { - "$encStrContains": { - "input": "$encryptedText", - "substring": "oba" - } - } - } - }, - "object": "coll", - "expectResult": [ - { - "_id": { - "$numberInt": "1" - }, - "encryptedText": "foobar", - "__safeContent__": [ - { - "$binary": { - "base64": "wpaMBVDjL4bHf9EtSP52PJFzyNn1R19+iNI/hWtvzdk=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "IpY3x/jjm8j/74jAdUhgxdM5hk68zR0zv/lTKm/72Vg=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "G+ky260C6QiOfIxKz14FmaMbAxvui1BKJO/TnLOHlGk=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "7dv3gAKe9vwJMZmpB40pRCwRTmc7ds9UkGhxH8j084E=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "o0V+Efn6x8XQdE80F1tztNaT3qxHjcsd9DOQ47BtmQk=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "sJvrCjyVot7PIZFsdRehWFANKAj6fmBaj3FLbz/dZLE=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "e98auxFmu02h5MfBIARk29MI7hSmvN3F9DaQ0xjqoEM=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "US83krGNov/ezL6IhsY5eEOCxv1xUPDIEL/nmY0IKi0=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "P2Aq5+OHZPG0CWIdmZvWq9c/18ZKVYW3vbxd+WU/TXU=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "8AdPRPnSzcd5uhq4TZfNvNeF0XjLNVwAsJJMTtktw84=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "9O6u/G51I4ZHFLhL4ZLuudbr0s202A2QnPfThmOXPhI=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "N7AjYVyVlv6+lVSTM+cIxRL3SMgs3G5LgxSs+jrgDkI=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "RbGF7dQbPGYQFd9DDO1hPz1UlLOJ77FAC6NsjGwJeos=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "m7srHMgKm6kZwsNx8rc45pmw0/9Qro6xuQ8lZS3+RYk=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "K75CNU3JyKFqZWPiIsVi4+n7DhYmcPl/nEhQ3d88mVI=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "c7bwGpUZc/7JzEnMS7qQ/TPuXZyrmMihFaAV6zIqbZc=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "rDvEdUgEk8u4Srt3ETokWs2FXcnyJaRGQ+NbkFwi2rQ=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "VcdZj9zfveRBRlpCR2OYWau2+GokOFb73TE3gpElNiU=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "eOa9o2xfA6OgkbYUxd6wQJicaeN6guhy2V66W3ALsaA=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "1xGkJh+um70XiRd8lKLDtyHgDqrf7/59Mg7X0+KZh8k=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "OSvllqHxycbcZN4phR6NDujY3ttA59o7nQJ6V9eJpX0=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "ZTX1pyk8Vdw0BSbJx7GeJNcQf3tGKxbrrNSTqBqUWkg=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "cn7V05zb5iXwYrePGMHztC+GRq+Tj8IMpRDraauPhSE=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "E9bV9KyrZxHJSUmMg0HrDK4gGN+75ruelAnrM6hXQgY=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "WrssTNmdgXoTGpbaF0JLRCGH6cDQuz1XEFNTy98nrb0=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "jZmyOJP35dsxQ/OY5U4ISpVRIYr8iedNfcwZiKt29Qc=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "d2mocORMbX9MX+/itAW8r1kxVw2/uii4vzXtc+2CIRQ=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "JBnJy58eRPhDo3DuZvsHbvQDiHXxdtAx1Eif66k5SfA=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "OjbDulC8s62v0pgweBSsQqtJjJBwH5JinfJpj7nVr+A=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "85i7KT2GP9nSda3Gsil5LKubhq0LDtc22pxBxHpR+nE=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "u9Fvsclwrs9lwIcMPV/fMZD7L3d5anSfJQVjQb9mgLg=", - "subType": "00" - } - } - ] - } - ] - } - ] - }, - { - "description": "Query with non-matching $encStrContains", - "operations": [ - { - "name": "insertOne", - "arguments": { - "document": { - "_id": 1, - "encryptedText": "foobar" - } - }, - "object": "coll" - }, - { - "name": "find", - "arguments": { - "filter": { - "$expr": { - "$encStrContains": { - "input": "$encryptedText", - "substring": "blah" - } - } - } - }, - "object": "coll", - "expectResult": [] - } - ] - } - ] -} diff --git a/test/client-side-encryption/spec/unified/QE-Text-suffixPreview.json b/test/client-side-encryption/spec/unified/QE-Text-suffixPreview.json deleted file mode 100644 index e30d0cfd58..0000000000 --- a/test/client-side-encryption/spec/unified/QE-Text-suffixPreview.json +++ /dev/null @@ -1,339 +0,0 @@ -{ - "description": "QE-Text-suffixPreview", - "schemaVersion": "1.25", - "runOnRequirements": [ - { - "minServerVersion": "8.2.0", - "maxServerVersion": "8.99.99", - "topologies": [ - "replicaset", - "sharded", - "load-balanced" - ], - "csfle": { - "minLibmongocryptVersion": "1.19.1" - } - } - ], - "createEntities": [ - { - "client": { - "id": "client", - "autoEncryptOpts": { - "keyVaultNamespace": "keyvault.datakeys", - "kmsProviders": { - "local": { - "key": "Mng0NCt4ZHVUYUJCa1kxNkVyNUR1QURhZ2h2UzR2d2RrZzh0cFBwM3R6NmdWMDFBMUN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk" - } - } - }, - "observeEvents": [ - "commandStartedEvent" - ] - } - }, - { - "database": { - "id": "db", - "client": "client", - "databaseName": "db" - } - }, - { - "collection": { - "id": "coll", - "database": "db", - "collectionName": "coll" - } - } - ], - "initialData": [ - { - "databaseName": "keyvault", - "collectionName": "datakeys", - "documents": [ - { - "_id": { - "$binary": { - "base64": "q83vqxI0mHYSNBI0VniQEg==", - "subType": "04" - } - }, - "keyMaterial": { - "$binary": { - "base64": "HBk9BWihXExNDvTp1lUxOuxuZK2Pe2ZdVdlsxPEBkiO1bS4mG5NNDsQ7zVxJAH8BtdOYp72Ku4Y3nwc0BUpIKsvAKX4eYXtlhv5zUQxWdeNFhg9qK7qb8nqhnnLeT0f25jFSqzWJoT379hfwDeu0bebJHr35QrJ8myZdPMTEDYF08QYQ48ShRBli0S+QzBHHAQiM2iJNr4svg2WR8JSeWQ==", - "subType": "00" - } - }, - "creationDate": { - "$date": { - "$numberLong": "1648914851981" - } - }, - "updateDate": { - "$date": { - "$numberLong": "1648914851981" - } - }, - "status": { - "$numberInt": "0" - }, - "masterKey": { - "provider": "local" - } - } - ] - }, - { - "databaseName": "db", - "collectionName": "coll", - "documents": [], - "createOptions": { - "encryptedFields": { - "fields": [ - { - "keyId": { - "$binary": { - "base64": "q83vqxI0mHYSNBI0VniQEg==", - "subType": "04" - } - }, - "path": "encryptedText", - "bsonType": "string", - "queries": [ - { - "queryType": "suffixPreview", - "contention": { - "$numberLong": "0" - }, - "strMinQueryLength": { - "$numberLong": "3" - }, - "strMaxQueryLength": { - "$numberLong": "30" - }, - "caseSensitive": true, - "diacriticSensitive": true - } - ] - } - ] - } - } - } - ], - "tests": [ - { - "description": "Insert QE suffixPreview", - "operations": [ - { - "name": "insertOne", - "arguments": { - "document": { - "_id": 1, - "encryptedText": "foobar" - } - }, - "object": "coll" - } - ], - "expectEvents": [ - { - "client": "client", - "events": [ - { - "commandStartedEvent": { - "command": { - "listCollections": 1, - "filter": { - "name": "coll" - } - }, - "commandName": "listCollections" - } - }, - { - "commandStartedEvent": { - "command": { - "find": "datakeys", - "filter": { - "$or": [ - { - "_id": { - "$in": [ - { - "$binary": { - "base64": "q83vqxI0mHYSNBI0VniQEg==", - "subType": "04" - } - } - ] - } - }, - { - "keyAltNames": { - "$in": [] - } - } - ] - }, - "$db": "keyvault", - "readConcern": { - "level": "majority" - } - }, - "commandName": "find" - } - }, - { - "commandStartedEvent": { - "command": { - "insert": "coll", - "documents": [ - { - "_id": 1, - "encryptedText": { - "$$type": "binData" - } - } - ], - "ordered": true - }, - "commandName": "insert" - } - } - ] - } - ] - }, - { - "description": "Query with matching $encStrEndsWith", - "operations": [ - { - "name": "insertOne", - "arguments": { - "document": { - "_id": 1, - "encryptedText": "foobar" - } - }, - "object": "coll" - }, - { - "name": "find", - "arguments": { - "filter": { - "$expr": { - "$encStrEndsWith": { - "input": "$encryptedText", - "suffix": "bar" - } - } - } - }, - "object": "coll", - "expectResult": [ - { - "_id": { - "$numberInt": "1" - }, - "encryptedText": "foobar", - "__safeContent__": [ - { - "$binary": { - "base64": "wpaMBVDjL4bHf9EtSP52PJFzyNn1R19+iNI/hWtvzdk=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "uDCWsucUsJemUP7pmeb+Kd8B9qupVzI8wnLFqX1rkiU=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "W3E1x4bHZ8SEHFz4zwXM0G5Z5WSwBhnxE8x5/qdP6JM=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "6g/TXVDDf6z+ntResIvTKWdmIy4ajQ1rhwdNZIiEG7A=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "hU+u/T3D6dHDpT3d/v5AlgtRoAufCXCAyO2jQlgsnCw=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "vrPnq0AtBIURNgNGA6HJL+5/p5SBWe+qz8505TRo/dE=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "W5pylBxdv2soY2NcBfPiHDVLTS6tx+0ULkI8gysBeFY=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "oWO3xX3x0bYUJGK2S1aPAmlU3Xtfsgb9lTZ6flGAlsg=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "SjZGucTEUbdpd86O8yj1pyMyBOOKxvAQ9C8ngZ9C5UE=", - "subType": "00" - } - }, - { - "$binary": { - "base64": "CEaMZkxVDVbnXr+To0DOyvsva04UQkIYP3KtgYVVwf8=", - "subType": "00" - } - } - ] - } - ] - } - ] - }, - { - "description": "Query with non-matching $encStrEndsWith", - "operations": [ - { - "name": "insertOne", - "arguments": { - "document": { - "_id": 1, - "encryptedText": "foobar" - } - }, - "object": "coll" - }, - { - "name": "find", - "arguments": { - "filter": { - "$expr": { - "$encStrEndsWith": { - "input": "$encryptedText", - "suffix": "foo" - } - } - } - }, - "object": "coll", - "expectResult": [] - } - ] - } - ] -} diff --git a/test/test_encryption.py b/test/test_encryption.py index c0513a3768..834b25b3f8 100644 --- a/test/test_encryption.py +++ b/test/test_encryption.py @@ -248,9 +248,8 @@ def test_kwargs(self): def _string_opts_kwargs(**kwargs: Any) -> dict[str, StringOpts]: """Pass StringOpts under the name the installed pymongocrypt accepts. - pymongocrypt renamed ``text_opts`` to ``string_opts`` in 1.19 and takes only - one of the two, and the preview query types still run against pymongocrypt - before 1.19, so both spellings are in play across the matrix. + pymongocrypt renamed ``text_opts`` to ``string_opts`` in 1.19 and accepts + only one of the two names per release, so the tests follow the binding. """ return {encryption._string_opts_kwarg(): StringOpts(**kwargs)} @@ -302,6 +301,16 @@ def test_string_opts_kwarg_matches_binding(self): self.assertIn(encryption._string_opts_kwarg(), params) +class TestPreviewQueryTypesRemoved(PyMongoTestCase): + def test_preview_query_types_removed(self): + # PYTHON-5959: the beta preview query types were removed in 4.20. + for name in ("PREFIXPREVIEW", "SUFFIXPREVIEW", "SUBSTRINGPREVIEW"): + self.assertFalse(hasattr(QueryType, name), name) + for value in ("prefixPreview", "suffixPreview", "substringPreview"): + with self.assertRaises(ValueError): + QueryType(value) + + class EncryptionIntegrationTest(IntegrationTest): """Base class for encryption integration tests.""" @@ -3391,43 +3400,30 @@ def _libmongocrypt_at_least(*version): return Version.from_string(libmongocrypt_version()) >= Version(*version) -# The minimum libmongocrypt version required by each string query type, declared -# in one place so the test gates and the changelog agree. Support landed per -# query type rather than all at once (see the libmongocrypt changelog): -# 1.18.1 - fixes caseSensitive/diacriticSensitive handling for "textPreview". -# 1.19.0 - the "string" algorithm replaces "textPreview"; prefix and suffix go -# stable; prefixPreview and suffixPreview are removed. -# 1.19.1 - prefixPreview and suffixPreview are restored. +# The minimum libmongocrypt version required by each GA string query type, +# declared in one place so the test gates and the changelog agree. Support +# landed per query type rather than all at once (see the libmongocrypt +# changelog): +# 1.19.0 - the "string" algorithm replaces "textPreview"; prefix and suffix +# go stable. # 1.20.0 - substring goes stable. +# 1.21.0 - the beta prefixPreview/suffixPreview/substringPreview query types +# became a runtime error (MONGOCRYPT-938) and were dropped in +# PYTHON-5959. _STRING_QUERY_MIN_LIBMONGOCRYPT = { "prefix": (1, 19, 0), "suffix": (1, 19, 0), "substring": (1, 20, 0), - "prefixPreview": (1, 18, 1), - "suffixPreview": (1, 18, 1), - "substringPreview": (1, 18, 1), } -# prefixPreview and suffixPreview were removed in 1.19.0 and restored in 1.19.1, -# so that one release is a hole rather than a floor. -_PREVIEW_REMOVED_IN = (1, 19, 0) - -# No pymongocrypt release ships libmongocrypt 1.19.0+, so the GA query types can -# only run against a master build; setup_tests.py pins the released binding for -# the 8.x preview tasks alone. Do not collapse that gate: the released binding -# still spells the parameter text_opts, and dropping back to it would silently -# stop exercising the GA path. - # https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.md#27-string-explicit-encryption class TestStringExplicitEncryptionProse(EncryptionIntegrationTest): - # The GA collections require server 9.0+, the preview collections require - # server pre-9.0. Setup encrypts with the "String" algorithm on 9.0+ and the - # deprecated "textPreview" algorithm on earlier servers, since "String" was - # only introduced in libmongocrypt 1.19.0. + # The GA collections require server 9.0+, where the "String" algorithm and + # the GA query types are supported. @client_context.require_no_standalone - @client_context.require_version_min(8, 2, -1) - @client_context.require_libmongocrypt_min(1, 18, 1) + @client_context.require_version_min(9, 0, -1) + @client_context.require_libmongocrypt_min(1, 19, 0) @client_context.require_pymongocrypt_min(1, 16, 0) def setUp(self): super().setUp() @@ -3463,39 +3459,18 @@ def setUp(self): ) ) - # The GA query types ("prefix", "suffix", "substring") require server - # 9.0+, which in turn dropped the preview query types. - self.is_ga = client_context.version.at_least(9, 0, -1) - # The "String" algorithm was added in libmongocrypt 1.19.0. Servers - # before 9.0 are tested against libmongocrypt 1.18.x, where the preview - # query types are only usable via the deprecated "textPreview" - # algorithm, so pick whichever the running combination supports. - self.algorithm = ( - Algorithm.STRING if _libmongocrypt_at_least(1, 19, 0) else Algorithm.TEXTPREVIEW - ) - # The GA query types need the "String" algorithm, so skip before setup - # encrypts anything rather than erroring on an unsupported combination. - if self.is_ga and not _libmongocrypt_at_least(1, 19, 0): - raise unittest.SkipTest("server 9.0+ string queries require libmongocrypt 1.19.0+") # Substring went stable in a later libmongocrypt than prefix and suffix, # so its fixture is only built where the query type exists. Otherwise # setup would fail before the substring cases could skip, taking the # prefix and suffix cases down with it. - self.has_substring = _libmongocrypt_at_least( - *_STRING_QUERY_MIN_LIBMONGOCRYPT["substring" if self.is_ga else "substringPreview"] - ) + self.has_substring = _libmongocrypt_at_least(*_STRING_QUERY_MIN_LIBMONGOCRYPT["substring"]) # Using QE CreateCollection() and Collection.Drop(), drop and create the # collections with majority write concern. db = self.client_encrypted.db - if self.is_ga: - collections = ["prefix-suffix", "prefix-suffix-ci-di"] - if self.has_substring: - collections += ["substring", "substring-ci-di"] - else: - collections = ["prefix-suffix-preview"] - if self.has_substring: - collections += ["substring-preview"] + collections = ["prefix-suffix", "prefix-suffix-ci-di"] + if self.has_substring: + collections += ["substring", "substring-ci-di"] for name in collections: db.drop_collection(name) self.client_encryption.create_encrypted_collection( @@ -3509,7 +3484,7 @@ def setUp(self): encrypted_value = self.client_encryption.encrypt( "foobarbaz", key_id=self.key1_id, - algorithm=self.algorithm, + algorithm=Algorithm.STRING, contention_factor=0, **_string_opts_kwargs( case_sensitive=True, @@ -3519,19 +3494,15 @@ def setUp(self): ), ) # Use explicitEncryptedClient to insert the following document into - # db.prefix-suffix (if created) and db.prefix-suffix-preview (if created) - # with majority write concern. - self._insert( - "prefix-suffix" if self.is_ga else "prefix-suffix-preview", - {"_id": 0, "encryptedText": encrypted_value}, - ) + # db.prefix-suffix with majority write concern. + self._insert("prefix-suffix", {"_id": 0, "encryptedText": encrypted_value}) if self.has_substring: # Use clientEncryption to encrypt the string "foobarbaz" with the following EncryptOpts. encrypted_value = self.client_encryption.encrypt( "foobarbaz", key_id=self.key1_id, - algorithm=self.algorithm, + algorithm=Algorithm.STRING, contention_factor=0, **_string_opts_kwargs( case_sensitive=True, @@ -3540,12 +3511,8 @@ def setUp(self): ), ) # Use explicitEncryptedClient to insert the following document into - # db.substring (if created) and db.substring-preview (if created) with - # majority write concern. - self._insert( - "substring" if self.is_ga else "substring-preview", - {"_id": 0, "encryptedText": encrypted_value}, - ) + # db.substring with majority write concern. + self._insert("substring", {"_id": 0, "encryptedText": encrypted_value}) def _insert(self, collection, document, client=None): """Insert a document with majority write concern.""" @@ -3560,42 +3527,12 @@ def _require_query_type(self, query_type): raise unittest.SkipTest( f"queryType={query_type} requires libmongocrypt {'.'.join(map(str, required))}+" ) - if query_type in ("prefixPreview", "suffixPreview") and ( - _libmongocrypt_at_least(*_PREVIEW_REMOVED_IN) and not _libmongocrypt_at_least(1, 19, 1) - ): - raise unittest.SkipTest(f"queryType={query_type} was removed in libmongocrypt 1.19.0") - - def _params(self, kind): - """Return the (query_type, collection) pair to run a case against. - - Each case runs against the GA query type on server 9.0+ and against the - preview query type on earlier servers, skipping when the installed - libmongocrypt is too old for the applicable variant. - """ - base = "substring" if kind == "substring" else "prefix-suffix" - if self.is_ga: - query_type, collection = kind, base - else: - query_type, collection = f"{kind}Preview", f"{base}-preview" - self._require_query_type(query_type) - return query_type, collection - - def _require_ga(self, *query_types): - """Skip a case that only applies to the GA query types. - - Gates on each query type the case exercises, since substring support - landed in a later libmongocrypt than prefix and suffix. - """ - if not self.is_ga: - raise unittest.SkipTest("requires server 9.0+") - for query_type in query_types: - self._require_query_type(query_type) def _encrypt(self, value, query_type=None, **string_opts): return self.client_encryption.encrypt( value, key_id=self.key1_id, - algorithm=self.algorithm, + algorithm=Algorithm.STRING, query_type=query_type, contention_factor=0, **_string_opts_kwargs(**string_opts), @@ -3608,18 +3545,19 @@ def _find(self, collection, filter): return value def test_01_can_find_a_document_by_prefix(self): - query_type, collection = self._params("prefix") + # Requires MongoDB server 9.0.0+ and libmongocrypt 1.19.0+. + self._require_query_type("prefix") # Use clientEncryption.encrypt() to encrypt the string "foo". encrypted_value = self._encrypt( "foo", - query_type=query_type, + query_type=QueryType.PREFIX, case_sensitive=True, diacritic_sensitive=True, prefix=dict(strMaxQueryLength=10, strMinQueryLength=2), ) # Use explicitEncryptedClient to run a "find" operation. value = self._find( - collection, + "prefix-suffix", { "$expr": { "$encStrStartsWith": {"input": "$encryptedText", "prefix": encrypted_value} @@ -3630,36 +3568,38 @@ def test_01_can_find_a_document_by_prefix(self): self.assertEqual(value, {"_id": 0, "encryptedText": "foobarbaz"}) def test_02_can_find_a_document_by_suffix(self): - query_type, collection = self._params("suffix") + # Requires MongoDB server 9.0.0+ and libmongocrypt 1.19.0+. + self._require_query_type("suffix") # Use clientEncryption.encrypt() to encrypt the string "baz". encrypted_value = self._encrypt( "baz", - query_type=query_type, + query_type=QueryType.SUFFIX, case_sensitive=True, diacritic_sensitive=True, suffix=dict(strMaxQueryLength=10, strMinQueryLength=2), ) # Use explicitEncryptedClient to run a "find" operation. value = self._find( - collection, + "prefix-suffix", {"$expr": {"$encStrEndsWith": {"input": "$encryptedText", "suffix": encrypted_value}}}, ) # Assert the following document is returned. self.assertEqual(value, {"_id": 0, "encryptedText": "foobarbaz"}) def test_03_no_document_found_by_prefix(self): - query_type, collection = self._params("prefix") + # Requires MongoDB server 9.0.0+ and libmongocrypt 1.19.0+. + self._require_query_type("prefix") # Use clientEncryption.encrypt() to encrypt the string "baz". encrypted_value = self._encrypt( "baz", - query_type=query_type, + query_type=QueryType.PREFIX, case_sensitive=True, diacritic_sensitive=True, prefix=dict(strMaxQueryLength=10, strMinQueryLength=2), ) # Use explicitEncryptedClient to run a "find" operation. value = self._find( - collection, + "prefix-suffix", { "$expr": { "$encStrStartsWith": {"input": "$encryptedText", "prefix": encrypted_value} @@ -3670,36 +3610,38 @@ def test_03_no_document_found_by_prefix(self): self.assertIsNone(value) def test_04_no_document_found_by_suffix(self): - query_type, collection = self._params("suffix") + # Requires MongoDB server 9.0.0+ and libmongocrypt 1.19.0+. + self._require_query_type("suffix") # Use clientEncryption.encrypt() to encrypt the string "foo". encrypted_value = self._encrypt( "foo", - query_type=query_type, + query_type=QueryType.SUFFIX, case_sensitive=True, diacritic_sensitive=True, suffix=dict(strMaxQueryLength=10, strMinQueryLength=2), ) # Use explicitEncryptedClient to run a "find" operation. value = self._find( - collection, + "prefix-suffix", {"$expr": {"$encStrEndsWith": {"input": "$encryptedText", "suffix": encrypted_value}}}, ) # Assert that no documents are returned. self.assertIsNone(value) def test_05_can_find_a_document_by_substring(self): - query_type, collection = self._params("substring") + # Requires MongoDB server 9.0.0+ and libmongocrypt 1.20.0+. + self._require_query_type("substring") # Use clientEncryption.encrypt() to encrypt the string "bar". encrypted_value = self._encrypt( "bar", - query_type=query_type, + query_type=QueryType.SUBSTRING, case_sensitive=True, diacritic_sensitive=True, substring=dict(strMaxLength=10, strMaxQueryLength=6, strMinQueryLength=2), ) # Use explicitEncryptedClient to run a "find" operation. value = self._find( - collection, + "substring", { "$expr": { "$encStrContains": {"input": "$encryptedText", "substring": encrypted_value} @@ -3710,18 +3652,19 @@ def test_05_can_find_a_document_by_substring(self): self.assertEqual(value, {"_id": 0, "encryptedText": "foobarbaz"}) def test_06_no_document_found_by_substring(self): - query_type, collection = self._params("substring") + # Requires MongoDB server 9.0.0+ and libmongocrypt 1.20.0+. + self._require_query_type("substring") # Use clientEncryption.encrypt() to encrypt the string "qux". encrypted_value = self._encrypt( "qux", - query_type=query_type, + query_type=QueryType.SUBSTRING, case_sensitive=True, diacritic_sensitive=True, substring=dict(strMaxLength=10, strMaxQueryLength=6, strMinQueryLength=2), ) # Use explicitEncryptedClient to run a "find" operation. value = self._find( - collection, + "substring", { "$expr": { "$encStrContains": {"input": "$encryptedText", "substring": encrypted_value} @@ -3734,7 +3677,7 @@ def test_06_no_document_found_by_substring(self): def test_07_contentionFactor_is_required(self): from pymongocrypt.errors import MongoCryptError - self._require_ga("prefix") + self._require_query_type("prefix") # Use clientEncryption.encrypt() to encrypt the string "foo" without contentionFactor. with self.assertRaises(EncryptionError) as ctx: self.client_encryption.encrypt( @@ -3755,7 +3698,8 @@ def test_07_contentionFactor_is_required(self): def test_08_case_insensitive_prefix_and_suffix(self): # This is a regression test for DRIVERS-3470. - self._require_ga("prefix", "suffix") + self._require_query_type("prefix") + self._require_query_type("suffix") # Use autoEncryptedClient to insert the following document. self._insert( "prefix-suffix-ci-di", {"encryptedText": "BingQiLin"}, self.client_auto_encrypted @@ -3798,7 +3742,8 @@ def test_08_case_insensitive_prefix_and_suffix(self): def test_09_diacritic_insensitive_prefix_and_suffix(self): # This is a regression test for DRIVERS-3470. - self._require_ga("prefix", "suffix") + self._require_query_type("prefix") + self._require_query_type("suffix") # Use autoEncryptedClient to insert the following document. self._insert( "prefix-suffix-ci-di", {"encryptedText": "cafébarbäz"}, self.client_auto_encrypted @@ -3841,7 +3786,7 @@ def test_09_diacritic_insensitive_prefix_and_suffix(self): def test_10_case_insensitive_substring(self): # This is a regression test for DRIVERS-3470. - self._require_ga("substring") + self._require_query_type("substring") # Use autoEncryptedClient to insert the following document. self._insert("substring-ci-di", {"encryptedText": "FooBarBaz"}, self.client_auto_encrypted) # Use clientEncryption.encrypt() to encrypt the string "bar". @@ -3866,7 +3811,7 @@ def test_10_case_insensitive_substring(self): def test_11_diacritic_insensitive_substring(self): # This is a regression test for DRIVERS-3470. - self._require_ga("substring") + self._require_query_type("substring") # Use autoEncryptedClient to insert the following document. self._insert("substring-ci-di", {"encryptedText": "foocafébaz"}, self.client_auto_encrypted) # Use clientEncryption.encrypt() to encrypt the string "cafe". From 23dbc2997b9b05a259d60ab9f0add7d34d2c9205 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Fri, 6 Nov 2026 13:10:07 -0600 Subject: [PATCH 2/4] PYTHON-5959 Regenerate uv.lock for pymongocrypt>=1.21.0 requirement bump --- uv.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uv.lock b/uv.lock index 0b1489c36f..a6da82d64b 100644 --- a/uv.lock +++ b/uv.lock @@ -1494,7 +1494,7 @@ requires-dist = [ { name = "pykerberos", marker = "os_name != 'nt' and extra == 'gssapi'", specifier = ">=1.2.4" }, { name = "pymongo-auth-aws", marker = "extra == 'aws'", specifier = ">=1.3.0,<2.0.0" }, { name = "pymongo-auth-aws", marker = "extra == 'encryption'", specifier = ">=1.3.0,<2.0.0" }, - { name = "pymongocrypt", marker = "extra == 'encryption'", specifier = ">=1.18.1,<2.0.0" }, + { name = "pymongocrypt", marker = "extra == 'encryption'", specifier = ">=1.21.0,<2.0.0" }, { name = "pyopenssl", marker = "extra == 'ocsp'", specifier = ">=26.2.0" }, { name = "pytest", marker = "extra == 'test'", specifier = ">=8.2" }, { name = "pytest-asyncio", marker = "extra == 'test'", specifier = ">=0.24.0" }, From 4e59cc85bf865259cb8d61527c50c581cbbf6e10 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Mon, 9 Nov 2026 10:11:57 -0600 Subject: [PATCH 3/4] address review --- doc/changelog.rst | 10 ++++- pymongo/asynchronous/encryption.py | 54 +++----------------------- pymongo/encryption_options.py | 6 --- pymongo/synchronous/encryption.py | 54 +++----------------------- test/asynchronous/test_encryption.py | 58 +++++++--------------------- test/test_encryption.py | 58 +++++++--------------------- 6 files changed, 46 insertions(+), 194 deletions(-) diff --git a/doc/changelog.rst b/doc/changelog.rst index eb93a128ef..772c9015fa 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -7,9 +7,15 @@ Changes in Version 4.20.0 (2026/XX/XX) - The client handshake metadata now reports a detected coding agent in ``client.env.agent`` (`PYTHON-5929`_). - Removed the beta ``QueryType.PREFIXPREVIEW``, ``QueryType.SUFFIXPREVIEW``, - and ``QueryType.SUBSTRINGPREVIEW`` query types. Use ``QueryType.PREFIX``, - ``QueryType.SUFFIX``, and ``QueryType.SUBSTRING`` instead (requires MongoDB + and ``QueryType.SUBSTRINGPREVIEW`` query types. Use + :attr:`~pymongo.encryption.QueryType.PREFIX`, + :attr:`~pymongo.encryption.QueryType.SUFFIX`, and + :attr:`~pymongo.encryption.QueryType.SUBSTRING` instead (requires MongoDB 9.0+ and pymongocrypt 1.21.0+) (`PYTHON-5959`_). +- Removed the deprecated ``text_opts`` parameter of + :meth:`~pymongo.encryption.ClientEncryption.encrypt` and + :meth:`~pymongo.asynchronous.encryption.AsyncClientEncryption.encrypt`. + Use ``string_opts`` (`PYTHON-5959`_). Bug fixes ......... diff --git a/pymongo/asynchronous/encryption.py b/pymongo/asynchronous/encryption.py index e4f91294a4..1e4b8849f7 100644 --- a/pymongo/asynchronous/encryption.py +++ b/pymongo/asynchronous/encryption.py @@ -17,7 +17,6 @@ from __future__ import annotations import asyncio -import functools import socket import time as time # noqa: PLC0414 # needed in sync version import uuid @@ -471,47 +470,6 @@ async def close(self) -> None: self._internal_client = None -@functools.lru_cache(maxsize=1) -def _string_opts_kwarg() -> str: - """The name the installed pymongocrypt gives the string index options. - - pymongocrypt renamed ``text_opts`` to ``string_opts`` in 1.19 and accepts - only one name per release. The rename landed on master before any release - carried it, so resolve the name from the installed signature rather than - from a version comparison. Resolved lazily and cached because importing - :mod:`inspect` is too expensive to do on the import path. - """ - import inspect - - params = inspect.signature(AsyncExplicitEncrypter.encrypt).parameters - return "string_opts" if "string_opts" in params else "text_opts" - - -def _resolve_string_opts( - string_opts: Optional[StringOpts], text_opts: Optional[StringOpts] -) -> Optional[StringOpts]: - """Resolve string_opts and its former name, text_opts. - - pymongocrypt accepts only one of the two names per release, so passing the - name the installed pymongocrypt does not support is an error. - """ - if string_opts is not None and text_opts is not None: - raise ConfigurationError("Cannot set both string_opts and text_opts") - if string_opts is None and text_opts is None: - return None - if text_opts is not None and _string_opts_kwarg() == "string_opts": - raise ConfigurationError( - "text_opts is not supported by the installed pymongocrypt " - "(1.19 or later). Use string_opts instead." - ) - if string_opts is not None and _string_opts_kwarg() == "text_opts": - raise ConfigurationError( - "string_opts requires pymongocrypt 1.19 or later. Use text_opts " - "with the installed pymongocrypt, or upgrade pymongocrypt." - ) - return string_opts if string_opts is not None else text_opts - - class AsyncClientEncryption(Generic[_DocumentType]): """Explicit client-side field level encryption.""" @@ -897,7 +855,7 @@ async def _encrypt_helper( contention_factor=contention_factor, range_opts=range_opts_bytes, is_expression=is_expression, - **({_string_opts_kwarg(): string_opts_bytes} if string_opts_bytes else {}), + string_opts=string_opts_bytes, ) return decode(encrypted_doc)["v"] @@ -911,7 +869,6 @@ async def encrypt( contention_factor: Optional[int] = None, range_opts: Optional[RangeOpts] = None, string_opts: Optional[StringOpts] = None, - text_opts: Optional[StringOpts] = None, ) -> Binary: """Encrypt a BSON value with a given key and algorithm. @@ -934,13 +891,12 @@ async def encrypt( :class:`RangeOpts` for some valid options. :param string_opts: Index options for `prefix`, `suffix`, and `substring` queries. See :class:`StringOpts` for some valid options. - :param text_opts: **DEPRECATED** - The former name of `string_opts`, - added in pymongocrypt 1.16 and accepted only through pymongocrypt - 1.18. Passing it to pymongocrypt 1.19 or later, or passing both - names, raises :exc:`~pymongo.errors.ConfigurationError`. :return: The encrypted value, a :class:`~bson.binary.Binary` with subtype 6. + .. versionchanged:: 4.20 + Removed the `text_opts` parameter. + .. versionchanged:: 4.18 Added the `string_opts` parameter, replacing the deprecated `text_opts`. @@ -968,7 +924,7 @@ async def encrypt( contention_factor=contention_factor, range_opts=range_opts, is_expression=False, - string_opts=_resolve_string_opts(string_opts, text_opts), + string_opts=string_opts, ), ) diff --git a/pymongo/encryption_options.py b/pymongo/encryption_options.py index fdabecbbcb..0e5a95cc12 100644 --- a/pymongo/encryption_options.py +++ b/pymongo/encryption_options.py @@ -422,12 +422,6 @@ class TextOpts(StringOpts): """**DEPRECATED** Options to configure encrypted queries using the text algorithm. .. note:: ``TextOpts`` is deprecated. Use :class:`StringOpts` instead. - ``TextOpts`` corresponds to the ``text_opts`` parameter of - :meth:`~pymongo.encryption.ClientEncryption.encrypt`, which pymongocrypt - added in 1.16 and renamed to ``string_opts`` in 1.19. Passing - ``TextOpts`` as ``text_opts`` therefore only works with pymongocrypt - 1.16 through 1.18; with pymongocrypt 1.19 or later, pass - :class:`StringOpts` as ``string_opts``. .. versionadded:: 4.15 diff --git a/pymongo/synchronous/encryption.py b/pymongo/synchronous/encryption.py index 1626c16f58..6c9c7d7950 100644 --- a/pymongo/synchronous/encryption.py +++ b/pymongo/synchronous/encryption.py @@ -16,7 +16,6 @@ from __future__ import annotations -import functools import socket import time as time # noqa: PLC0414 # needed in sync version import uuid @@ -468,47 +467,6 @@ def close(self) -> None: self._internal_client = None -@functools.lru_cache(maxsize=1) -def _string_opts_kwarg() -> str: - """The name the installed pymongocrypt gives the string index options. - - pymongocrypt renamed ``text_opts`` to ``string_opts`` in 1.19 and accepts - only one name per release. The rename landed on master before any release - carried it, so resolve the name from the installed signature rather than - from a version comparison. Resolved lazily and cached because importing - :mod:`inspect` is too expensive to do on the import path. - """ - import inspect - - params = inspect.signature(ExplicitEncrypter.encrypt).parameters - return "string_opts" if "string_opts" in params else "text_opts" - - -def _resolve_string_opts( - string_opts: Optional[StringOpts], text_opts: Optional[StringOpts] -) -> Optional[StringOpts]: - """Resolve string_opts and its former name, text_opts. - - pymongocrypt accepts only one of the two names per release, so passing the - name the installed pymongocrypt does not support is an error. - """ - if string_opts is not None and text_opts is not None: - raise ConfigurationError("Cannot set both string_opts and text_opts") - if string_opts is None and text_opts is None: - return None - if text_opts is not None and _string_opts_kwarg() == "string_opts": - raise ConfigurationError( - "text_opts is not supported by the installed pymongocrypt " - "(1.19 or later). Use string_opts instead." - ) - if string_opts is not None and _string_opts_kwarg() == "text_opts": - raise ConfigurationError( - "string_opts requires pymongocrypt 1.19 or later. Use text_opts " - "with the installed pymongocrypt, or upgrade pymongocrypt." - ) - return string_opts if string_opts is not None else text_opts - - class ClientEncryption(Generic[_DocumentType]): """Explicit client-side field level encryption.""" @@ -890,7 +848,7 @@ def _encrypt_helper( contention_factor=contention_factor, range_opts=range_opts_bytes, is_expression=is_expression, - **({_string_opts_kwarg(): string_opts_bytes} if string_opts_bytes else {}), + string_opts=string_opts_bytes, ) return decode(encrypted_doc)["v"] @@ -904,7 +862,6 @@ def encrypt( contention_factor: Optional[int] = None, range_opts: Optional[RangeOpts] = None, string_opts: Optional[StringOpts] = None, - text_opts: Optional[StringOpts] = None, ) -> Binary: """Encrypt a BSON value with a given key and algorithm. @@ -927,13 +884,12 @@ def encrypt( :class:`RangeOpts` for some valid options. :param string_opts: Index options for `prefix`, `suffix`, and `substring` queries. See :class:`StringOpts` for some valid options. - :param text_opts: **DEPRECATED** - The former name of `string_opts`, - added in pymongocrypt 1.16 and accepted only through pymongocrypt - 1.18. Passing it to pymongocrypt 1.19 or later, or passing both - names, raises :exc:`~pymongo.errors.ConfigurationError`. :return: The encrypted value, a :class:`~bson.binary.Binary` with subtype 6. + .. versionchanged:: 4.20 + Removed the `text_opts` parameter. + .. versionchanged:: 4.18 Added the `string_opts` parameter, replacing the deprecated `text_opts`. @@ -961,7 +917,7 @@ def encrypt( contention_factor=contention_factor, range_opts=range_opts, is_expression=False, - string_opts=_resolve_string_opts(string_opts, text_opts), + string_opts=string_opts, ), ) diff --git a/test/asynchronous/test_encryption.py b/test/asynchronous/test_encryption.py index 4983027ebf..ac6b696a14 100644 --- a/test/asynchronous/test_encryption.py +++ b/test/asynchronous/test_encryption.py @@ -19,7 +19,6 @@ import base64 import copy import http.client -import inspect import json import os import pathlib @@ -245,15 +244,6 @@ async def test_kwargs(self): self.assertEqual(get_client_opts(client).auto_encryption_opts, opts) -def _string_opts_kwargs(**kwargs: Any) -> dict[str, StringOpts]: - """Pass StringOpts under the name the installed pymongocrypt accepts. - - pymongocrypt renamed ``text_opts`` to ``string_opts`` in 1.19 and accepts - only one of the two names per release, so the tests follow the binding. - """ - return {encryption._string_opts_kwarg(): StringOpts(**kwargs)} - - class TestStringOptsDeprecation(AsyncPyMongoTestCase): def test_text_opts_is_still_re_exported(self): # TextOpts is deprecated, not removed, so it must stay importable from @@ -269,36 +259,16 @@ def test_text_opts_is_deprecated(self): opts.document, ) - def test_resolve_string_opts_no_opts(self): - self.assertIsNone(encryption._resolve_string_opts(None, None)) - - def test_resolve_string_opts_rejects_both(self): - string_opts = StringOpts(prefix={"strMinQueryLength": 2, "strMaxQueryLength": 10}) - with self.assertRaises(ConfigurationError): - encryption._resolve_string_opts(string_opts, string_opts) - - @unittest.skipUnless(_HAVE_PYMONGOCRYPT, "pymongocrypt is not installed") - def test_resolve_string_opts_follows_pymongocrypt(self): - # pymongocrypt accepts only one of the two names per release: text_opts - # through 1.18 and string_opts from 1.19. Passing the name the - # installed binding does not support is an error rather than a silent - # alias, so assert against the resolved name. - string_opts = StringOpts(prefix={"strMinQueryLength": 2, "strMaxQueryLength": 10}) - if encryption._string_opts_kwarg() == "string_opts": - supported, unsupported = (string_opts, None), (None, string_opts) - else: - supported, unsupported = (None, string_opts), (string_opts, None) - self.assertIs(encryption._resolve_string_opts(*supported), string_opts) - with self.assertRaises(ConfigurationError): - encryption._resolve_string_opts(*unsupported) - - @unittest.skipUnless(_HAVE_PYMONGOCRYPT, "pymongocrypt is not installed") - def test_string_opts_kwarg_matches_binding(self): - # The resolved name is passed straight through to pymongocrypt, so - # assert it against the installed binding here: a mismatch then fails - # without a server, rather than only in the prose suite. - params = inspect.signature(encryption.AsyncExplicitEncrypter.encrypt).parameters - self.assertIn(encryption._string_opts_kwarg(), params) + def test_text_opts_is_removed(self): + # The text_opts parameter was removed after its 4.18 deprecation. + # Passing it raises TypeError like any unexpected keyword argument. + with self.assertRaises(TypeError): + encryption.AsyncClientEncryption.encrypt( + None, # type: ignore[arg-type] + "value", + "algorithm", + text_opts=None, # type: ignore[call-arg] + ) class TestPreviewQueryTypesRemoved(AsyncPyMongoTestCase): @@ -3504,7 +3474,7 @@ async def asyncSetUp(self): key_id=self.key1_id, algorithm=Algorithm.STRING, contention_factor=0, - **_string_opts_kwargs( + string_opts=StringOpts( case_sensitive=True, diacritic_sensitive=True, prefix=dict(strMaxQueryLength=10, strMinQueryLength=2), @@ -3522,7 +3492,7 @@ async def asyncSetUp(self): key_id=self.key1_id, algorithm=Algorithm.STRING, contention_factor=0, - **_string_opts_kwargs( + string_opts=StringOpts( case_sensitive=True, diacritic_sensitive=True, substring=dict(strMaxLength=10, strMaxQueryLength=6, strMinQueryLength=2), @@ -3553,7 +3523,7 @@ async def _encrypt(self, value, query_type=None, **string_opts): algorithm=Algorithm.STRING, query_type=query_type, contention_factor=0, - **_string_opts_kwargs(**string_opts), + string_opts=StringOpts(**string_opts), ) async def _find(self, collection, filter): @@ -3703,7 +3673,7 @@ async def test_07_contentionFactor_is_required(self): key_id=self.key1_id, algorithm=Algorithm.STRING, query_type=QueryType.PREFIX, - **_string_opts_kwargs( + string_opts=StringOpts( case_sensitive=True, diacritic_sensitive=True, prefix=dict(strMaxQueryLength=10, strMinQueryLength=2), diff --git a/test/test_encryption.py b/test/test_encryption.py index 834b25b3f8..a50471fd6c 100644 --- a/test/test_encryption.py +++ b/test/test_encryption.py @@ -19,7 +19,6 @@ import base64 import copy import http.client -import inspect import json import os import pathlib @@ -245,15 +244,6 @@ def test_kwargs(self): self.assertEqual(get_client_opts(client).auto_encryption_opts, opts) -def _string_opts_kwargs(**kwargs: Any) -> dict[str, StringOpts]: - """Pass StringOpts under the name the installed pymongocrypt accepts. - - pymongocrypt renamed ``text_opts`` to ``string_opts`` in 1.19 and accepts - only one of the two names per release, so the tests follow the binding. - """ - return {encryption._string_opts_kwarg(): StringOpts(**kwargs)} - - class TestStringOptsDeprecation(PyMongoTestCase): def test_text_opts_is_still_re_exported(self): # TextOpts is deprecated, not removed, so it must stay importable from @@ -269,36 +259,16 @@ def test_text_opts_is_deprecated(self): opts.document, ) - def test_resolve_string_opts_no_opts(self): - self.assertIsNone(encryption._resolve_string_opts(None, None)) - - def test_resolve_string_opts_rejects_both(self): - string_opts = StringOpts(prefix={"strMinQueryLength": 2, "strMaxQueryLength": 10}) - with self.assertRaises(ConfigurationError): - encryption._resolve_string_opts(string_opts, string_opts) - - @unittest.skipUnless(_HAVE_PYMONGOCRYPT, "pymongocrypt is not installed") - def test_resolve_string_opts_follows_pymongocrypt(self): - # pymongocrypt accepts only one of the two names per release: text_opts - # through 1.18 and string_opts from 1.19. Passing the name the - # installed binding does not support is an error rather than a silent - # alias, so assert against the resolved name. - string_opts = StringOpts(prefix={"strMinQueryLength": 2, "strMaxQueryLength": 10}) - if encryption._string_opts_kwarg() == "string_opts": - supported, unsupported = (string_opts, None), (None, string_opts) - else: - supported, unsupported = (None, string_opts), (string_opts, None) - self.assertIs(encryption._resolve_string_opts(*supported), string_opts) - with self.assertRaises(ConfigurationError): - encryption._resolve_string_opts(*unsupported) - - @unittest.skipUnless(_HAVE_PYMONGOCRYPT, "pymongocrypt is not installed") - def test_string_opts_kwarg_matches_binding(self): - # The resolved name is passed straight through to pymongocrypt, so - # assert it against the installed binding here: a mismatch then fails - # without a server, rather than only in the prose suite. - params = inspect.signature(encryption.ExplicitEncrypter.encrypt).parameters - self.assertIn(encryption._string_opts_kwarg(), params) + def test_text_opts_is_removed(self): + # The text_opts parameter was removed after its 4.18 deprecation. + # Passing it raises TypeError like any unexpected keyword argument. + with self.assertRaises(TypeError): + encryption.ClientEncryption.encrypt( + None, # type: ignore[arg-type] + "value", + "algorithm", + text_opts=None, # type: ignore[call-arg] + ) class TestPreviewQueryTypesRemoved(PyMongoTestCase): @@ -3486,7 +3456,7 @@ def setUp(self): key_id=self.key1_id, algorithm=Algorithm.STRING, contention_factor=0, - **_string_opts_kwargs( + string_opts=StringOpts( case_sensitive=True, diacritic_sensitive=True, prefix=dict(strMaxQueryLength=10, strMinQueryLength=2), @@ -3504,7 +3474,7 @@ def setUp(self): key_id=self.key1_id, algorithm=Algorithm.STRING, contention_factor=0, - **_string_opts_kwargs( + string_opts=StringOpts( case_sensitive=True, diacritic_sensitive=True, substring=dict(strMaxLength=10, strMaxQueryLength=6, strMinQueryLength=2), @@ -3535,7 +3505,7 @@ def _encrypt(self, value, query_type=None, **string_opts): algorithm=Algorithm.STRING, query_type=query_type, contention_factor=0, - **_string_opts_kwargs(**string_opts), + string_opts=StringOpts(**string_opts), ) def _find(self, collection, filter): @@ -3685,7 +3655,7 @@ def test_07_contentionFactor_is_required(self): key_id=self.key1_id, algorithm=Algorithm.STRING, query_type=QueryType.PREFIX, - **_string_opts_kwargs( + string_opts=StringOpts( case_sensitive=True, diacritic_sensitive=True, prefix=dict(strMaxQueryLength=10, strMinQueryLength=2), From a6ba63eca03c07830bbd69ffdb258350ac8d7249 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Mon, 9 Nov 2026 11:12:54 -0600 Subject: [PATCH 4/4] address review --- doc/changelog.rst | 5 ++-- pymongo/asynchronous/encryption.py | 3 --- pymongo/encryption_options.py | 22 ---------------- pymongo/synchronous/encryption.py | 3 --- test/asynchronous/test_encryption.py | 38 ---------------------------- test/test_encryption.py | 38 ---------------------------- 6 files changed, 3 insertions(+), 106 deletions(-) diff --git a/doc/changelog.rst b/doc/changelog.rst index 772c9015fa..6873840951 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -14,8 +14,9 @@ Changes in Version 4.20.0 (2026/XX/XX) 9.0+ and pymongocrypt 1.21.0+) (`PYTHON-5959`_). - Removed the deprecated ``text_opts`` parameter of :meth:`~pymongo.encryption.ClientEncryption.encrypt` and - :meth:`~pymongo.asynchronous.encryption.AsyncClientEncryption.encrypt`. - Use ``string_opts`` (`PYTHON-5959`_). + :meth:`~pymongo.asynchronous.encryption.AsyncClientEncryption.encrypt`, and + the ``TextOpts`` class. Use ``string_opts`` and + :class:`~pymongo.encryption_options.StringOpts` instead (`PYTHON-5959`_). Bug fixes ......... diff --git a/pymongo/asynchronous/encryption.py b/pymongo/asynchronous/encryption.py index 1e4b8849f7..038295b0a5 100644 --- a/pymongo/asynchronous/encryption.py +++ b/pymongo/asynchronous/encryption.py @@ -63,9 +63,6 @@ AutoEncryptionOpts, RangeOpts, StringOpts, - # Re-exported for backwards compatibility: TextOpts is deprecated but must - # remain importable from this module until it is removed. - TextOpts, # noqa: F401 check_min_pymongocrypt, ) from pymongo.encryption_shared import ( diff --git a/pymongo/encryption_options.py b/pymongo/encryption_options.py index 0e5a95cc12..37616959ba 100644 --- a/pymongo/encryption_options.py +++ b/pymongo/encryption_options.py @@ -19,7 +19,6 @@ from __future__ import annotations -import warnings from collections.abc import Mapping from typing import TYPE_CHECKING, Any, Callable, Optional, TypedDict @@ -357,7 +356,6 @@ def __init__( :param diacritic_sensitive: Whether string indexes for this field are diacritic sensitive. .. versionadded:: 4.18 - ``StringOpts`` replaces ``TextOpts``, which is deprecated. """ self.substring = substring self.prefix = prefix @@ -416,23 +414,3 @@ class SuffixOpts(TypedDict): strMinQueryLength: int # strMaxQueryLength is the maximum allowed query length. Querying with a longer string will error. strMaxQueryLength: int - - -class TextOpts(StringOpts): - """**DEPRECATED** Options to configure encrypted queries using the text algorithm. - - .. note:: ``TextOpts`` is deprecated. Use :class:`StringOpts` instead. - - .. versionadded:: 4.15 - - .. versionchanged:: 4.18 - Deprecated in favor of :class:`StringOpts`. - """ - - def __init__(self, *args: Any, **kwargs: Any) -> None: - warnings.warn( - "TextOpts is deprecated. Use StringOpts instead.", - DeprecationWarning, - stacklevel=2, - ) - super().__init__(*args, **kwargs) diff --git a/pymongo/synchronous/encryption.py b/pymongo/synchronous/encryption.py index 6c9c7d7950..2f73349b88 100644 --- a/pymongo/synchronous/encryption.py +++ b/pymongo/synchronous/encryption.py @@ -57,9 +57,6 @@ AutoEncryptionOpts, RangeOpts, StringOpts, - # Re-exported for backwards compatibility: TextOpts is deprecated but must - # remain importable from this module until it is removed. - TextOpts, # noqa: F401 check_min_pymongocrypt, ) from pymongo.encryption_shared import ( diff --git a/test/asynchronous/test_encryption.py b/test/asynchronous/test_encryption.py index ac6b696a14..7916d63b26 100644 --- a/test/asynchronous/test_encryption.py +++ b/test/asynchronous/test_encryption.py @@ -72,7 +72,6 @@ AutoEncryptionOpts, RangeOpts, StringOpts, - TextOpts, ) from pymongo.errors import ( AutoReconnect, @@ -244,43 +243,6 @@ async def test_kwargs(self): self.assertEqual(get_client_opts(client).auto_encryption_opts, opts) -class TestStringOptsDeprecation(AsyncPyMongoTestCase): - def test_text_opts_is_still_re_exported(self): - # TextOpts is deprecated, not removed, so it must stay importable from - # the encryption module for the deprecation period. - self.assertIs(encryption.TextOpts, TextOpts) - - def test_text_opts_is_deprecated(self): - with self.assertWarns(DeprecationWarning): - opts = TextOpts(prefix={"strMinQueryLength": 2, "strMaxQueryLength": 10}) - self.assertIsInstance(opts, StringOpts) - self.assertEqual( - StringOpts(prefix={"strMinQueryLength": 2, "strMaxQueryLength": 10}).document, - opts.document, - ) - - def test_text_opts_is_removed(self): - # The text_opts parameter was removed after its 4.18 deprecation. - # Passing it raises TypeError like any unexpected keyword argument. - with self.assertRaises(TypeError): - encryption.AsyncClientEncryption.encrypt( - None, # type: ignore[arg-type] - "value", - "algorithm", - text_opts=None, # type: ignore[call-arg] - ) - - -class TestPreviewQueryTypesRemoved(AsyncPyMongoTestCase): - def test_preview_query_types_removed(self): - # PYTHON-5959: the beta preview query types were removed in 4.20. - for name in ("PREFIXPREVIEW", "SUFFIXPREVIEW", "SUBSTRINGPREVIEW"): - self.assertFalse(hasattr(QueryType, name), name) - for value in ("prefixPreview", "suffixPreview", "substringPreview"): - with self.assertRaises(ValueError): - QueryType(value) - - class AsyncEncryptionIntegrationTest(AsyncIntegrationTest): """Base class for encryption integration tests.""" diff --git a/test/test_encryption.py b/test/test_encryption.py index a50471fd6c..cac114e5b3 100644 --- a/test/test_encryption.py +++ b/test/test_encryption.py @@ -64,7 +64,6 @@ AutoEncryptionOpts, RangeOpts, StringOpts, - TextOpts, ) from pymongo.errors import ( AutoReconnect, @@ -244,43 +243,6 @@ def test_kwargs(self): self.assertEqual(get_client_opts(client).auto_encryption_opts, opts) -class TestStringOptsDeprecation(PyMongoTestCase): - def test_text_opts_is_still_re_exported(self): - # TextOpts is deprecated, not removed, so it must stay importable from - # the encryption module for the deprecation period. - self.assertIs(encryption.TextOpts, TextOpts) - - def test_text_opts_is_deprecated(self): - with self.assertWarns(DeprecationWarning): - opts = TextOpts(prefix={"strMinQueryLength": 2, "strMaxQueryLength": 10}) - self.assertIsInstance(opts, StringOpts) - self.assertEqual( - StringOpts(prefix={"strMinQueryLength": 2, "strMaxQueryLength": 10}).document, - opts.document, - ) - - def test_text_opts_is_removed(self): - # The text_opts parameter was removed after its 4.18 deprecation. - # Passing it raises TypeError like any unexpected keyword argument. - with self.assertRaises(TypeError): - encryption.ClientEncryption.encrypt( - None, # type: ignore[arg-type] - "value", - "algorithm", - text_opts=None, # type: ignore[call-arg] - ) - - -class TestPreviewQueryTypesRemoved(PyMongoTestCase): - def test_preview_query_types_removed(self): - # PYTHON-5959: the beta preview query types were removed in 4.20. - for name in ("PREFIXPREVIEW", "SUFFIXPREVIEW", "SUBSTRINGPREVIEW"): - self.assertFalse(hasattr(QueryType, name), name) - for value in ("prefixPreview", "suffixPreview", "substringPreview"): - with self.assertRaises(ValueError): - QueryType(value) - - class EncryptionIntegrationTest(IntegrationTest): """Base class for encryption integration tests."""