diff --git a/src/mc-efc-private.h b/src/mc-efc-private.h index 438e1d982..86a4d3f8d 100644 --- a/src/mc-efc-private.h +++ b/src/mc-efc-private.h @@ -30,8 +30,8 @@ typedef enum _supported_query_type_flags { SUPPORTS_RANGE_PREVIEW_DEPRECATED_QUERIES = 1 << 2, // Text search preview query supported SUPPORTS_SUBSTRING_PREVIEW_QUERIES = 1 << 3, - SUPPORTS_SUFFIX_PREVIEW_QUERIES = 1 << 4, - SUPPORTS_PREFIX_PREVIEW_QUERIES = 1 << 5, + SUPPORTS_SUFFIX_QUERIES = 1 << 4, + SUPPORTS_PREFIX_QUERIES = 1 << 5, } supported_query_type_flags; typedef struct _mc_EncryptedField_t { diff --git a/src/mc-efc.c b/src/mc-efc.c index 11562182d..432615b5d 100644 --- a/src/mc-efc.c +++ b/src/mc-efc.c @@ -35,10 +35,12 @@ static bool _parse_query_type_string(const char *queryType, supported_query_type *out = SUPPORTS_RANGE_PREVIEW_DEPRECATED_QUERIES; } else if (mstr_eq_ignore_case(mstrv_lit(MONGOCRYPT_QUERY_TYPE_SUBSTRINGPREVIEW_STR), qtv)) { *out = SUPPORTS_SUBSTRING_PREVIEW_QUERIES; - } else if (mstr_eq_ignore_case(mstrv_lit(MONGOCRYPT_QUERY_TYPE_SUFFIXPREVIEW_STR), qtv)) { - *out = SUPPORTS_SUFFIX_PREVIEW_QUERIES; - } else if (mstr_eq_ignore_case(mstrv_lit(MONGOCRYPT_QUERY_TYPE_PREFIXPREVIEW_STR), qtv)) { - *out = SUPPORTS_PREFIX_PREVIEW_QUERIES; + } else if (mstr_eq_ignore_case(mstrv_lit(MONGOCRYPT_QUERY_TYPE_SUFFIXPREVIEW_DEPRECATED_STR), qtv) + || mstr_eq_ignore_case(mstrv_lit(MONGOCRYPT_QUERY_TYPE_SUFFIX_STR), qtv)) { + *out = SUPPORTS_SUFFIX_QUERIES; + } else if (mstr_eq_ignore_case(mstrv_lit(MONGOCRYPT_QUERY_TYPE_PREFIXPREVIEW_DEPRECATED_STR), qtv) + || mstr_eq_ignore_case(mstrv_lit(MONGOCRYPT_QUERY_TYPE_PREFIX_STR), qtv)) { + *out = SUPPORTS_PREFIX_QUERIES; } else { return false; } @@ -240,8 +242,7 @@ bool mc_EncryptedFieldConfig_parse(mc_EncryptedFieldConfig_t *efc, if (!bson_iter_init_find(&iter, efc_bson, "strEncodeVersion")) { if (all_supported_queries - & (SUPPORTS_SUBSTRING_PREVIEW_QUERIES | SUPPORTS_SUFFIX_PREVIEW_QUERIES - | SUPPORTS_PREFIX_PREVIEW_QUERIES)) { + & (SUPPORTS_SUBSTRING_PREVIEW_QUERIES | SUPPORTS_SUFFIX_QUERIES | SUPPORTS_PREFIX_QUERIES)) { // Has at least one text search query type, set to latest by default. efc->str_encode_version = LATEST_STR_ENCODE_VERSION; } else { diff --git a/src/mc-textopts.c b/src/mc-textopts.c index 06cdc8a9f..838548bb1 100644 --- a/src/mc-textopts.c +++ b/src/mc-textopts.c @@ -366,11 +366,11 @@ bool mc_TextOpts_to_FLE2TextSearchInsertSpec_for_query(const mc_TextOpts_t *txo, CLIENT_ERR("Unexpected query type: %s\n", _mongocrypt_query_type_to_string(query_type)); return false; } - case MONGOCRYPT_QUERY_TYPE_PREFIXPREVIEW: { + case MONGOCRYPT_QUERY_TYPE_PREFIX: { include_prefix = true; break; } - case MONGOCRYPT_QUERY_TYPE_SUFFIXPREVIEW: { + case MONGOCRYPT_QUERY_TYPE_SUFFIX: { include_suffix = true; break; } diff --git a/src/mongocrypt-ctx-encrypt.c b/src/mongocrypt-ctx-encrypt.c index 29b67e488..bec43a48e 100644 --- a/src/mongocrypt-ctx-encrypt.c +++ b/src/mongocrypt-ctx-encrypt.c @@ -890,8 +890,8 @@ static moe_result must_omit_encryptionInformation(const char *command_name, bool has_fields_requiring_ei = false; for (const mc_EncryptedField_t *ef = efc->fields; ef != NULL; ef = ef->next) { if (ef->supported_queries - & (SUPPORTS_RANGE_QUERIES | SUPPORTS_SUBSTRING_PREVIEW_QUERIES | SUPPORTS_SUFFIX_PREVIEW_QUERIES - | SUPPORTS_PREFIX_PREVIEW_QUERIES)) { + & (SUPPORTS_RANGE_QUERIES | SUPPORTS_SUBSTRING_PREVIEW_QUERIES | SUPPORTS_SUFFIX_QUERIES + | SUPPORTS_PREFIX_QUERIES)) { has_fields_requiring_ei = true; break; } @@ -1011,8 +1011,8 @@ static bool _fle2_append_compactionTokens(mongocrypt_t *crypt, const _mongocrypt_buffer_t *ecoct_buf = mc_ECOCToken_get(ecoct); if (ptr->supported_queries - & (SUPPORTS_RANGE_QUERIES | SUPPORTS_SUBSTRING_PREVIEW_QUERIES | SUPPORTS_SUFFIX_PREVIEW_QUERIES - | SUPPORTS_PREFIX_PREVIEW_QUERIES)) { + & (SUPPORTS_RANGE_QUERIES | SUPPORTS_SUBSTRING_PREVIEW_QUERIES | SUPPORTS_SUFFIX_QUERIES + | SUPPORTS_PREFIX_QUERIES)) { // Append the document {ecoc: , anchorPaddingToken: } esct = mc_ESCToken_new(crypto, cl1t, status); if (!esct) { @@ -1520,8 +1520,8 @@ static bool _fle2_finalize_explicit(mongocrypt_ctx_t *ctx, mongocrypt_binary_t * _mongocrypt_ctx_fail_w_msg(ctx, "Cannot use rangePreview query type with Range V2"); goto fail; // fallthrough - case MONGOCRYPT_QUERY_TYPE_PREFIXPREVIEW: - case MONGOCRYPT_QUERY_TYPE_SUFFIXPREVIEW: + case MONGOCRYPT_QUERY_TYPE_SUFFIX: + case MONGOCRYPT_QUERY_TYPE_PREFIX: case MONGOCRYPT_QUERY_TYPE_SUBSTRINGPREVIEW: case MONGOCRYPT_QUERY_TYPE_RANGE: case MONGOCRYPT_QUERY_TYPE_EQUALITY: marking.u.fle2.type = MONGOCRYPT_FLE2_PLACEHOLDER_TYPE_FIND; break; @@ -2087,14 +2087,14 @@ static bool explicit_encrypt_init(mongocrypt_ctx_t *ctx, mongocrypt_binary_t *ms if (ctx->opts.query_type.set) { const mongocrypt_query_type_t qt = ctx->opts.query_type.value; - if (qt == MONGOCRYPT_QUERY_TYPE_PREFIXPREVIEW) { + if (qt == MONGOCRYPT_QUERY_TYPE_PREFIX) { if (!(ctx->opts.index_type.set && ctx->opts.index_type.value == MONGOCRYPT_INDEX_TYPE_TEXTPREVIEW)) { - return _mongocrypt_ctx_fail_w_msg(ctx, "prefixPreview query type requires textPreview index type"); + return _mongocrypt_ctx_fail_w_msg(ctx, "prefix query type requires textPreview index type"); } } - if (qt == MONGOCRYPT_QUERY_TYPE_SUFFIXPREVIEW) { + if (qt == MONGOCRYPT_QUERY_TYPE_SUFFIX) { if (!(ctx->opts.index_type.set && ctx->opts.index_type.value == MONGOCRYPT_INDEX_TYPE_TEXTPREVIEW)) { - return _mongocrypt_ctx_fail_w_msg(ctx, "suffixPreview query type requires textPreview index type"); + return _mongocrypt_ctx_fail_w_msg(ctx, "suffix query type requires textPreview index type"); } } if (qt == MONGOCRYPT_QUERY_TYPE_SUBSTRINGPREVIEW) { @@ -2180,8 +2180,8 @@ static bool explicit_encrypt_init(mongocrypt_ctx_t *ctx, mongocrypt_binary_t *ms matches = (ctx->opts.index_type.value == MONGOCRYPT_INDEX_TYPE_EQUALITY); break; // fallthrough - case MONGOCRYPT_QUERY_TYPE_PREFIXPREVIEW: - case MONGOCRYPT_QUERY_TYPE_SUFFIXPREVIEW: + case MONGOCRYPT_QUERY_TYPE_PREFIX: + case MONGOCRYPT_QUERY_TYPE_SUFFIX: case MONGOCRYPT_QUERY_TYPE_SUBSTRINGPREVIEW: matches = (ctx->opts.index_type.value == MONGOCRYPT_INDEX_TYPE_TEXTPREVIEW); break; diff --git a/src/mongocrypt-ctx-private.h b/src/mongocrypt-ctx-private.h index 6bf9bb501..8d62765e3 100644 --- a/src/mongocrypt-ctx-private.h +++ b/src/mongocrypt-ctx-private.h @@ -44,8 +44,8 @@ typedef enum _mongocrypt_query_type_t { MONGOCRYPT_QUERY_TYPE_EQUALITY = 1, MONGOCRYPT_QUERY_TYPE_RANGE = 2, MONGOCRYPT_QUERY_TYPE_RANGEPREVIEW_DEPRECATED = 3, - MONGOCRYPT_QUERY_TYPE_PREFIXPREVIEW = 4, - MONGOCRYPT_QUERY_TYPE_SUFFIXPREVIEW = 5, + MONGOCRYPT_QUERY_TYPE_PREFIX = 4, + MONGOCRYPT_QUERY_TYPE_SUFFIX = 5, MONGOCRYPT_QUERY_TYPE_SUBSTRINGPREVIEW = 6, } mongocrypt_query_type_t; diff --git a/src/mongocrypt-ctx.c b/src/mongocrypt-ctx.c index 15f4f372d..1462edecd 100644 --- a/src/mongocrypt-ctx.c +++ b/src/mongocrypt-ctx.c @@ -1021,11 +1021,21 @@ bool mongocrypt_ctx_setopt_query_type(mongocrypt_ctx_t *ctx, const char *query_t } else if (mstr_eq_ignore_case(qt_str, mstrv_lit(MONGOCRYPT_QUERY_TYPE_RANGEPREVIEW_DEPRECATED_STR))) { _mongocrypt_ctx_fail_w_msg(ctx, "Query type 'rangePreview' is deprecated, please use 'range'"); return false; - } else if (mstr_eq_ignore_case(qt_str, mstrv_lit(MONGOCRYPT_QUERY_TYPE_PREFIXPREVIEW_STR))) { - ctx->opts.query_type.value = MONGOCRYPT_QUERY_TYPE_PREFIXPREVIEW; + } else if (mstr_eq_ignore_case(qt_str, mstrv_lit(MONGOCRYPT_QUERY_TYPE_PREFIX_STR))) { + ctx->opts.query_type.value = MONGOCRYPT_QUERY_TYPE_PREFIX; ctx->opts.query_type.set = true; - } else if (mstr_eq_ignore_case(qt_str, mstrv_lit(MONGOCRYPT_QUERY_TYPE_SUFFIXPREVIEW_STR))) { - ctx->opts.query_type.value = MONGOCRYPT_QUERY_TYPE_SUFFIXPREVIEW; + } else if (mstr_eq_ignore_case(qt_str, mstrv_lit(MONGOCRYPT_QUERY_TYPE_SUFFIX_STR))) { + ctx->opts.query_type.value = MONGOCRYPT_QUERY_TYPE_SUFFIX; + ctx->opts.query_type.set = true; + } else if (mstr_eq_ignore_case(qt_str, mstrv_lit(MONGOCRYPT_QUERY_TYPE_PREFIXPREVIEW_DEPRECATED_STR))) { + // TODO: MONGOCRYPT-870 disallow prefixPreview + // _mongocrypt_ctx_fail_w_msg(ctx, "Query type 'prefixPreview' is deprecated, please use 'prefix'"); + ctx->opts.query_type.value = MONGOCRYPT_QUERY_TYPE_PREFIX; + ctx->opts.query_type.set = true; + } else if (mstr_eq_ignore_case(qt_str, mstrv_lit(MONGOCRYPT_QUERY_TYPE_SUFFIXPREVIEW_DEPRECATED_STR))) { + // TODO: MONGOCRYPT-870 disallow suffixPreview + // _mongocrypt_ctx_fail_w_msg(ctx, "Query type 'suffixPreview' is deprecated, please use 'suffix'"); + ctx->opts.query_type.value = MONGOCRYPT_QUERY_TYPE_SUFFIX; ctx->opts.query_type.set = true; } else if (mstr_eq_ignore_case(qt_str, mstrv_lit(MONGOCRYPT_QUERY_TYPE_SUBSTRINGPREVIEW_STR))) { ctx->opts.query_type.value = MONGOCRYPT_QUERY_TYPE_SUBSTRINGPREVIEW; @@ -1058,8 +1068,8 @@ const char *_mongocrypt_query_type_to_string(mongocrypt_query_type_t val) { case MONGOCRYPT_QUERY_TYPE_EQUALITY: return "Equality"; case MONGOCRYPT_QUERY_TYPE_RANGEPREVIEW_DEPRECATED: return "RangePreview"; case MONGOCRYPT_QUERY_TYPE_RANGE: return "Range"; - case MONGOCRYPT_QUERY_TYPE_PREFIXPREVIEW: return "PrefixPreview"; - case MONGOCRYPT_QUERY_TYPE_SUFFIXPREVIEW: return "SuffixPreview"; + case MONGOCRYPT_QUERY_TYPE_PREFIX: return "Prefix"; + case MONGOCRYPT_QUERY_TYPE_SUFFIX: return "Suffix"; case MONGOCRYPT_QUERY_TYPE_SUBSTRINGPREVIEW: return "SubstringPreview"; default: return "Unknown"; } diff --git a/src/mongocrypt.h b/src/mongocrypt.h index 9d7c49c41..334d082d7 100644 --- a/src/mongocrypt.h +++ b/src/mongocrypt.h @@ -1599,9 +1599,11 @@ bool mongocrypt_setopt_key_expiration(mongocrypt_t *crypt, uint64_t cache_expira #define MONGOCRYPT_QUERY_TYPE_RANGE_STR "range" /// NOTE: "substringPreview" is experimental and may be removed in a future non-major release. #define MONGOCRYPT_QUERY_TYPE_SUBSTRINGPREVIEW_STR "substringPreview" -/// NOTE: "suffixPreview" is experimental and may be removed in a future non-major release. -#define MONGOCRYPT_QUERY_TYPE_SUFFIXPREVIEW_STR "suffixPreview" -/// NOTE: "prefixPreview" is experimental and may be removed in a future non-major release. -#define MONGOCRYPT_QUERY_TYPE_PREFIXPREVIEW_STR "prefixPreview" +/// DEPRECATED: Support for "suffixPreview" has been removed in favor of "suffix" +#define MONGOCRYPT_QUERY_TYPE_SUFFIXPREVIEW_DEPRECATED_STR "suffixPreview" +#define MONGOCRYPT_QUERY_TYPE_SUFFIX_STR "suffix" +/// DEPRECATED: Support for "prefixPreview" has been removed in favor of "suffix" +#define MONGOCRYPT_QUERY_TYPE_PREFIXPREVIEW_DEPRECATED_STR "prefixPreview" +#define MONGOCRYPT_QUERY_TYPE_PREFIX_STR "prefix" #endif /* MONGOCRYPT_H */ diff --git a/test/data/efc/efc-textSearchFields.json b/test/data/efc/efc-textSearchFields.json index f3ea2d80e..8eda94a86 100644 --- a/test/data/efc/efc-textSearchFields.json +++ b/test/data/efc/efc-textSearchFields.json @@ -42,6 +42,30 @@ } } ] + }, + { + "keyId": { + "$binary": { + "base64": "EjRWeBI0mHYSNBI0VqvN7w==", + "subType": "04" + } + }, + "path": "middleName", + "bsonType": "string", + "queries": [ + { + "queryType": "suffix", + "contention": { + "$numberLong": "0" + } + }, + { + "queryType": "prefix", + "contention": { + "$numberLong": "0" + } + } + ] } ] } \ No newline at end of file diff --git a/test/test-mc-efc.c b/test/test-mc-efc.c index bf5b54466..66b28bea2 100644 --- a/test/test-mc-efc.c +++ b/test/test-mc-efc.c @@ -30,9 +30,11 @@ static void _test_efc(_mongocrypt_tester_t *tester) { mongocrypt_status_t *status = mongocrypt_status_new(); _mongocrypt_buffer_t expect_keyId1; _mongocrypt_buffer_t expect_keyId2; + _mongocrypt_buffer_t expect_keyId3; _mongocrypt_buffer_copy_from_hex(&expect_keyId1, "12345678123498761234123456789012"); _mongocrypt_buffer_copy_from_hex(&expect_keyId2, "abcdefab123498761234123456789012"); + _mongocrypt_buffer_copy_from_hex(&expect_keyId3, "12345678123498761234123456abcdef"); { _load_test_file(tester, "./test/data/efc/efc-oneField.json", &efc_bson); @@ -110,9 +112,14 @@ static void _test_efc(_mongocrypt_tester_t *tester) { ASSERT_CMPUINT8(efc.str_encode_version, ==, LATEST_STR_ENCODE_VERSION); ptr = efc.fields; ASSERT(ptr); + ASSERT_STREQUAL(ptr->path, "middleName"); + ASSERT_CMPBUF(expect_keyId3, ptr->keyId); + ASSERT(ptr->supported_queries == (SUPPORTS_SUFFIX_QUERIES | SUPPORTS_PREFIX_QUERIES)); + ASSERT(ptr->next != NULL); + ptr = ptr->next; ASSERT_STREQUAL(ptr->path, "lastName"); ASSERT_CMPBUF(expect_keyId2, ptr->keyId); - ASSERT(ptr->supported_queries == (SUPPORTS_SUFFIX_PREVIEW_QUERIES | SUPPORTS_PREFIX_PREVIEW_QUERIES)); + ASSERT(ptr->supported_queries == (SUPPORTS_SUFFIX_QUERIES | SUPPORTS_PREFIX_QUERIES)); ASSERT(ptr->next != NULL); ptr = ptr->next; ASSERT_STREQUAL(ptr->path, "firstName"); @@ -130,7 +137,7 @@ static void _test_efc(_mongocrypt_tester_t *tester) { ASSERT(ptr); ASSERT_STREQUAL(ptr->path, "lastName"); ASSERT_CMPBUF(expect_keyId2, ptr->keyId); - ASSERT(ptr->supported_queries == (SUPPORTS_SUFFIX_PREVIEW_QUERIES | SUPPORTS_PREFIX_PREVIEW_QUERIES)); + ASSERT(ptr->supported_queries == (SUPPORTS_SUFFIX_QUERIES | SUPPORTS_PREFIX_QUERIES)); ASSERT(ptr->next != NULL); ptr = ptr->next; ASSERT_STREQUAL(ptr->path, "firstName"); @@ -158,6 +165,7 @@ static void _test_efc(_mongocrypt_tester_t *tester) { _mongocrypt_status_reset(status); } + _mongocrypt_buffer_cleanup(&expect_keyId3); _mongocrypt_buffer_cleanup(&expect_keyId2); _mongocrypt_buffer_cleanup(&expect_keyId1); mongocrypt_status_destroy(status); diff --git a/test/test-mc-textopts.c b/test/test-mc-textopts.c index 4f1a866f2..b56fe7c00 100644 --- a/test/test-mc-textopts.c +++ b/test/test-mc-textopts.c @@ -255,7 +255,7 @@ static void test_mc_TextOpts_to_FLE2TextSearchInsertSpec_for_query(_mongocrypt_t "prefix" : {"strMinQueryLength" : 3, "strMaxQueryLength" : 8} }), .v = RAW_STRING({"v" : "test"}), - .qt = MONGOCRYPT_QUERY_TYPE_PREFIXPREVIEW, + .qt = MONGOCRYPT_QUERY_TYPE_PREFIX, .expect = RAW_STRING({"v" : {"v" : "test", "casef" : true, "diacf" : false, "prefix" : {"ub" : 8, "lb" : 3}}})}, {.desc = "Works with suffix", @@ -265,7 +265,7 @@ static void test_mc_TextOpts_to_FLE2TextSearchInsertSpec_for_query(_mongocrypt_t "suffix" : {"strMinQueryLength" : 3, "strMaxQueryLength" : 8} }), .v = RAW_STRING({"v" : "test"}), - .qt = MONGOCRYPT_QUERY_TYPE_SUFFIXPREVIEW, + .qt = MONGOCRYPT_QUERY_TYPE_SUFFIX, .expect = RAW_STRING({"v" : {"v" : "test", "casef" : true, "diacf" : false, "suffix" : {"ub" : 8, "lb" : 3}}})}, {.desc = "Works with prefix + suffix when querying prefix", @@ -276,7 +276,7 @@ static void test_mc_TextOpts_to_FLE2TextSearchInsertSpec_for_query(_mongocrypt_t "suffix" : {"strMinQueryLength" : 3, "strMaxQueryLength" : 8} }), .v = RAW_STRING({"v" : "test"}), - .qt = MONGOCRYPT_QUERY_TYPE_PREFIXPREVIEW, + .qt = MONGOCRYPT_QUERY_TYPE_PREFIX, .expect = RAW_STRING({"v" : {"v" : "test", "casef" : true, "diacf" : false, "prefix" : {"ub" : 9, "lb" : 4}}})}, {.desc = "Works with prefix + suffix when querying suffix", @@ -287,7 +287,7 @@ static void test_mc_TextOpts_to_FLE2TextSearchInsertSpec_for_query(_mongocrypt_t "suffix" : {"strMinQueryLength" : 3, "strMaxQueryLength" : 8} }), .v = RAW_STRING({"v" : "test"}), - .qt = MONGOCRYPT_QUERY_TYPE_SUFFIXPREVIEW, + .qt = MONGOCRYPT_QUERY_TYPE_SUFFIX, .expect = RAW_STRING({"v" : {"v" : "test", "casef" : true, "diacf" : false, "suffix" : {"ub" : 8, "lb" : 3}}})}, }; diff --git a/test/test-mongocrypt-ctx-encrypt.c b/test/test-mongocrypt-ctx-encrypt.c index 639aa9ff5..5298dcf91 100644 --- a/test/test-mongocrypt-ctx-encrypt.c +++ b/test/test-mongocrypt-ctx-encrypt.c @@ -2478,7 +2478,7 @@ static void _test_encrypt_fle2_explicit(_mongocrypt_tester_t *tester) { ee_testcase tc = {0}; tc.desc = "find suffix"; tc.algorithm = MONGOCRYPT_ALGORITHM_TEXTPREVIEW_STR; - tc.query_type = MONGOCRYPT_QUERY_TYPE_SUFFIXPREVIEW_STR; + tc.query_type = MONGOCRYPT_QUERY_TYPE_SUFFIXPREVIEW_DEPRECATED_STR; tc.contention_factor = OPT_I64(1); tc.msg = TEST_BSON("{'v': 'abc'}"); tc.user_key_id = &keyABC_id; @@ -2496,7 +2496,43 @@ static void _test_encrypt_fle2_explicit(_mongocrypt_tester_t *tester) { ee_testcase tc = {0}; tc.desc = "find prefix"; tc.algorithm = MONGOCRYPT_ALGORITHM_TEXTPREVIEW_STR; - tc.query_type = MONGOCRYPT_QUERY_TYPE_PREFIXPREVIEW_STR; + tc.query_type = MONGOCRYPT_QUERY_TYPE_PREFIXPREVIEW_DEPRECATED_STR; + tc.contention_factor = OPT_I64(1); + tc.msg = TEST_BSON("{'v': 'abc'}"); + tc.user_key_id = &keyABC_id; + tc.keys_to_feed[0] = keyABC; + tc.text_opts = TEST_BSON(RAW_STRING({ + "caseSensitive" : false, + "diacriticSensitive" : false, + "prefix" : {"strMinQueryLength" : 1, "strMaxQueryLength" : 100} + })); + tc.expect = TEST_FILE("./test/data/fle2-explicit/find-prefix.json"); + ee_testcase_run(&tc); + } + + { + ee_testcase tc = {0}; + tc.desc = "find suffix"; + tc.algorithm = MONGOCRYPT_ALGORITHM_TEXTPREVIEW_STR; + tc.query_type = MONGOCRYPT_QUERY_TYPE_SUFFIX_STR; + tc.contention_factor = OPT_I64(1); + tc.msg = TEST_BSON("{'v': 'abc'}"); + tc.user_key_id = &keyABC_id; + tc.keys_to_feed[0] = keyABC; + tc.text_opts = TEST_BSON(RAW_STRING({ + "caseSensitive" : false, + "diacriticSensitive" : false, + "suffix" : {"strMinQueryLength" : 1, "strMaxQueryLength" : 100} + })); + tc.expect = TEST_FILE("./test/data/fle2-explicit/find-suffix.json"); + ee_testcase_run(&tc); + } + + { + ee_testcase tc = {0}; + tc.desc = "find prefix"; + tc.algorithm = MONGOCRYPT_ALGORITHM_TEXTPREVIEW_STR; + tc.query_type = MONGOCRYPT_QUERY_TYPE_PREFIX_STR; tc.contention_factor = OPT_I64(1); tc.msg = TEST_BSON("{'v': 'abc'}"); tc.user_key_id = &keyABC_id; @@ -2637,7 +2673,7 @@ static void _test_encrypt_fle2_explicit(_mongocrypt_tester_t *tester) { tc.msg = TEST_BSON("{'v': 'abc'}"); tc.user_key_id = &keyABC_id; tc.keys_to_feed[0] = keyABC; - tc.query_type = MONGOCRYPT_QUERY_TYPE_PREFIXPREVIEW_STR; + tc.query_type = MONGOCRYPT_QUERY_TYPE_PREFIXPREVIEW_DEPRECATED_STR; tc.text_opts = TEST_BSON(RAW_STRING({ "caseSensitive" : false, "diacriticSensitive" : false, diff --git a/test/test-mongocrypt-ctx-setopt.c b/test/test-mongocrypt-ctx-setopt.c index ae10469df..990147254 100644 --- a/test/test-mongocrypt-ctx-setopt.c +++ b/test/test-mongocrypt-ctx-setopt.c @@ -1013,17 +1013,33 @@ static void _test_setopt_for_explicit_encrypt(_mongocrypt_tester_t *tester) { /* Set key ID to get past the 'either key id or key alt name required' * error */ ASSERT_KEY_ID_OK(uuid); - ASSERT_OK(mongocrypt_ctx_setopt_query_type(ctx, MONGOCRYPT_QUERY_TYPE_PREFIXPREVIEW_STR, -1), ctx); + ASSERT_OK(mongocrypt_ctx_setopt_query_type(ctx, MONGOCRYPT_QUERY_TYPE_PREFIXPREVIEW_DEPRECATED_STR, -1), ctx); ASSERT_OK(mongocrypt_ctx_setopt_algorithm(ctx, MONGOCRYPT_ALGORITHM_INDEXED_STR, -1), ctx); - ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "prefixPreview query type requires textPreview index type"); + ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "prefix query type requires textPreview index type"); REFRESH; /* Set key ID to get past the 'either key id or key alt name required' * error */ ASSERT_KEY_ID_OK(uuid); - ASSERT_OK(mongocrypt_ctx_setopt_query_type(ctx, MONGOCRYPT_QUERY_TYPE_SUFFIXPREVIEW_STR, -1), ctx); + ASSERT_OK(mongocrypt_ctx_setopt_query_type(ctx, MONGOCRYPT_QUERY_TYPE_SUFFIXPREVIEW_DEPRECATED_STR, -1), ctx); ASSERT_OK(mongocrypt_ctx_setopt_algorithm(ctx, MONGOCRYPT_ALGORITHM_RANGE_STR, -1), ctx); - ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "suffixPreview query type requires textPreview index type"); + ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "suffix query type requires textPreview index type"); + + REFRESH; + /* Set key ID to get past the 'either key id or key alt name required' + * error */ + ASSERT_KEY_ID_OK(uuid); + ASSERT_OK(mongocrypt_ctx_setopt_query_type(ctx, MONGOCRYPT_QUERY_TYPE_PREFIX_STR, -1), ctx); + ASSERT_OK(mongocrypt_ctx_setopt_algorithm(ctx, MONGOCRYPT_ALGORITHM_RANGE_STR, -1), ctx); + ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "prefix query type requires textPreview index type"); + + REFRESH; + /* Set key ID to get past the 'either key id or key alt name required' + * error */ + ASSERT_KEY_ID_OK(uuid); + ASSERT_OK(mongocrypt_ctx_setopt_query_type(ctx, MONGOCRYPT_QUERY_TYPE_SUFFIX_STR, -1), ctx); + ASSERT_OK(mongocrypt_ctx_setopt_algorithm(ctx, MONGOCRYPT_ALGORITHM_RANGE_STR, -1), ctx); + ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "suffix query type requires textPreview index type"); } /* It is an error to set a text algorithm without setting text options */