Skip to content

DRIVERS-3213 add text search explicit encryption API and tests #1824

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

mdb-ad
Copy link
Contributor

@mdb-ad mdb-ad commented Aug 6, 2025

Summary

  • Add explicit encryption API of Queryable Encryption (QE) text indexes added in SPM-4158.
  • Add prose tests.

Background & Motivation

libmongocrypt

Driver bindings to libmongocrypt will need to pass explicit options through the new helper added in 1.15.0: mongocrypt_ctx_setopt_algorithm_text.

TextOpts

The structure of TextOpts resembles the placeholder created by query analysis (mongocryptd/crypt_shared): FLE2TextSearchInsertSpec. The repeated parameters (e.g. suffix.strMaxQueryLength and prefix.strMaxQueryLength) are to support a field with both prefix and suffix queries with different values.


Please complete the following before merging:

  • Update changelog.
  • Test changes in at least one language driver.
  • Test these changes against all server versions and topologies (including standalone, replica set, and sharded
    clusters).

C driver implementation: https://spruce.mongodb.com/version/6894132fba56770007851f12

@mdb-ad mdb-ad changed the title Text search explicit encryption prose tests DRIVERS-3227 Text search explicit encryption prose tests Aug 7, 2025
@mdb-ad mdb-ad marked this pull request as ready for review August 7, 2025 03:31
@mdb-ad mdb-ad requested a review from a team as a code owner August 7, 2025 03:31
@mdb-ad mdb-ad requested review from katcharov and removed request for a team August 7, 2025 03:31
@kevinAlbs kevinAlbs requested review from kevinAlbs and removed request for katcharov August 7, 2025 11:48
@kevinAlbs kevinAlbs changed the title DRIVERS-3227 Text search explicit encryption prose tests DRIVERS-3213 add text search explicit encryption API and tests Aug 7, 2025
"subType": "04"
}
},
"path": "encrypted-textPreview",
Copy link
Contributor

Choose a reason for hiding this comment

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

The tests seem to be using the field encryptedText not encrypted-textPreview - should this be encryptedText?

textOpts: TextOpts {
caseSensitive: true,
diacriticSensitive: true,
prefix: <PrefixOpts>,
Copy link
Contributor

Choose a reason for hiding this comment

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

suggest: moving PrefixOpts and SuffixOpts to this section


#### Case 2: can find a document by suffix

Use `clientEncryption.encrypt()` to encrypt the string `"foo"`. Store the resulting payload in `findPayload`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Use `clientEncryption.encrypt()` to encrypt the string `"foo"`. Store the resulting payload in `findPayload`.
Use `clientEncryption.encrypt()` to encrypt the string `"baz"`. Store the resulting payload in `findPayload`.

Use `encryptedClient` to run a "find" operation on the `db.prefix-suffix` collection with the following filter:

```javascript
{ "$expr": { "$encStrStartsWith": {"input": "$encryptedText", "prefix": <findPayload>}, } }
Copy link
Contributor

Choose a reason for hiding this comment

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

=

Suggested change
{ "$expr": { "$encStrStartsWith": {"input": "$encryptedText", "prefix": <findPayload>}, } }
{ $expr: { $encStrEndsWith: { input: '$encryptedText', suffix: <findPayload> } } }


#### Case 3: assert no document found by prefix

Use `clientEncryption.encrypt()` to encrypt the string `"foo"`. Store the resulting payload in `findPayload`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't this test find foobarbaz? Should we be encrypting a different value here?

Comment on lines +3974 to +3979
Use `clientEncryption.encrypt()` to encrypt the string `"foo"`. Store the resulting payload in `findPayload`.

Use `encryptedClient` to run a "find" operation on the `db.substring` collection with the following filter:

```javascript
{ "$expr": { "$encStrStartsWith": {"input": "$encryptedText", "prefix": <findPayload>}, } }
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be changed to test substring

Comment on lines +3993 to +3996

```javascript
{ "$expr": { "$encStrStartsWith": {"input": "$encryptedText", "prefix": <findPayload>}, } }
```
Copy link
Contributor

Choose a reason for hiding this comment

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

same with this predicate

"subType": "04"
}
},
"path": "encrypted-textPreview",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"path": "encrypted-textPreview",
"path": "encryptedText",

@kevinAlbs kevinAlbs requested review from rozza and removed request for rozza August 8, 2025 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants