Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bindings/python/test/data/fle2-text-search/textopts.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"caseSensitive": true,
"diacriticSensitive": true,
"caseSensitive": false,
"diacriticSensitive": false,
"prefix": {
"strMaxQueryLength": 10,
"strMinQueryLength": 2
Expand Down
6 changes: 4 additions & 2 deletions src/mc-textopts.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,14 @@ static bool TextOpts_to_FLE2TextSearchInsertSpec(const mc_TextOpts_t *txo,
CLIENT_ERR(ERROR_PREFIX "Error appending to BSON");
return false;
}
if (!bson_append_bool(&child, "casef", -1, txo->caseSensitive)) {
// "casef" means "case folding". Case sensitive => not folded. Case insensitive => folded.
if (!bson_append_bool(&child, "casef", -1, !txo->caseSensitive)) {
CLIENT_ERR(ERROR_PREFIX "Error appending to BSON");
return false;
}

if (!bson_append_bool(&child, "diacf", -1, txo->diacriticSensitive)) {
// "diacf" means "diacritic folding". Diacritic sensitive => not folded. Diacritic insensitive => folded.
if (!bson_append_bool(&child, "diacf", -1, !txo->diacriticSensitive)) {
CLIENT_ERR(ERROR_PREFIX "Error appending to BSON");
return false;
}
Expand Down
30 changes: 15 additions & 15 deletions test/test-mc-textopts.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,35 +157,35 @@ static void test_mc_TextOpts_to_FLE2TextSearchInsertSpec(_mongocrypt_tester_t *t
testcase tests[] = {
{.desc = "Works with substring",
.in = RAW_STRING({
"caseSensitive" : true,
"diacriticSensitive" : false,
"caseSensitive" : false,
"diacriticSensitive" : true,
"substring" : {"strMaxLength" : 10, "strMinQueryLength" : 3, "strMaxQueryLength" : 8}
}),
.v = RAW_STRING({"v" : "test"}),
.expect = RAW_STRING(
{"v" : {"v" : "test", "casef" : true, "diacf" : false, "substr" : {"mlen" : 10, "ub" : 8, "lb" : 3}}})},
{.desc = "Works with prefix",
.in = RAW_STRING({
"caseSensitive" : true,
"diacriticSensitive" : false,
"caseSensitive" : false,
"diacriticSensitive" : true,
"prefix" : {"strMinQueryLength" : 3, "strMaxQueryLength" : 8}
}),
.v = RAW_STRING({"v" : "test"}),
.expect =
RAW_STRING({"v" : {"v" : "test", "casef" : true, "diacf" : false, "prefix" : {"ub" : 8, "lb" : 3}}})},
{.desc = "Works with suffix",
.in = RAW_STRING({
"caseSensitive" : true,
"diacriticSensitive" : false,
"caseSensitive" : false,
"diacriticSensitive" : true,
"suffix" : {"strMinQueryLength" : 3, "strMaxQueryLength" : 8}
}),
.v = RAW_STRING({"v" : "test"}),
.expect =
RAW_STRING({"v" : {"v" : "test", "casef" : true, "diacf" : false, "suffix" : {"ub" : 8, "lb" : 3}}})},
{.desc = "Works with prefix + suffix",
.in = RAW_STRING({
"caseSensitive" : true,
"diacriticSensitive" : false,
"caseSensitive" : false,
"diacriticSensitive" : true,
"prefix" : {"strMinQueryLength" : 4, "strMaxQueryLength" : 9},
"suffix" : {"strMinQueryLength" : 3, "strMaxQueryLength" : 8}
}),
Expand All @@ -201,8 +201,8 @@ static void test_mc_TextOpts_to_FLE2TextSearchInsertSpec(_mongocrypt_tester_t *t
})},
{.desc = "Errors with missing v",
.in = RAW_STRING({
"caseSensitive" : true,
"diacriticSensitive" : false,
"caseSensitive" : false,
"diacriticSensitive" : true,
"prefix" : {"strMinQueryLength" : 3, "strMaxQueryLength" : 8}
}),
.v = RAW_STRING({"foo" : "bar"}),
Expand Down Expand Up @@ -247,7 +247,7 @@ static void test_mc_TextOpts_to_FLE2TextSearchInsertSpec_for_query(_mongocrypt_t
.v = RAW_STRING({"v" : "test"}),
.qt = MONGOCRYPT_QUERY_TYPE_SUBSTRINGPREVIEW,
.expect = RAW_STRING(
{"v" : {"v" : "test", "casef" : true, "diacf" : false, "substr" : {"mlen" : 10, "ub" : 8, "lb" : 3}}})},
{"v" : {"v" : "test", "casef" : false, "diacf" : true, "substr" : {"mlen" : 10, "ub" : 8, "lb" : 3}}})},
{.desc = "Works with prefix",
.in = RAW_STRING({
"caseSensitive" : true,
Expand All @@ -257,7 +257,7 @@ static void test_mc_TextOpts_to_FLE2TextSearchInsertSpec_for_query(_mongocrypt_t
.v = RAW_STRING({"v" : "test"}),
.qt = MONGOCRYPT_QUERY_TYPE_PREFIX,
.expect =
RAW_STRING({"v" : {"v" : "test", "casef" : true, "diacf" : false, "prefix" : {"ub" : 8, "lb" : 3}}})},
RAW_STRING({"v" : {"v" : "test", "casef" : false, "diacf" : true, "prefix" : {"ub" : 8, "lb" : 3}}})},
{.desc = "Works with suffix",
.in = RAW_STRING({
"caseSensitive" : true,
Expand All @@ -267,7 +267,7 @@ static void test_mc_TextOpts_to_FLE2TextSearchInsertSpec_for_query(_mongocrypt_t
.v = RAW_STRING({"v" : "test"}),
.qt = MONGOCRYPT_QUERY_TYPE_SUFFIX,
.expect =
RAW_STRING({"v" : {"v" : "test", "casef" : true, "diacf" : false, "suffix" : {"ub" : 8, "lb" : 3}}})},
RAW_STRING({"v" : {"v" : "test", "casef" : false, "diacf" : true, "suffix" : {"ub" : 8, "lb" : 3}}})},
{.desc = "Works with prefix + suffix when querying prefix",
.in = RAW_STRING({
"caseSensitive" : true,
Expand All @@ -278,7 +278,7 @@ static void test_mc_TextOpts_to_FLE2TextSearchInsertSpec_for_query(_mongocrypt_t
.v = RAW_STRING({"v" : "test"}),
.qt = MONGOCRYPT_QUERY_TYPE_PREFIX,
.expect =
RAW_STRING({"v" : {"v" : "test", "casef" : true, "diacf" : false, "prefix" : {"ub" : 9, "lb" : 4}}})},
RAW_STRING({"v" : {"v" : "test", "casef" : false, "diacf" : true, "prefix" : {"ub" : 9, "lb" : 4}}})},
{.desc = "Works with prefix + suffix when querying suffix",
.in = RAW_STRING({
"caseSensitive" : true,
Expand All @@ -289,7 +289,7 @@ static void test_mc_TextOpts_to_FLE2TextSearchInsertSpec_for_query(_mongocrypt_t
.v = RAW_STRING({"v" : "test"}),
.qt = MONGOCRYPT_QUERY_TYPE_SUFFIX,
.expect =
RAW_STRING({"v" : {"v" : "test", "casef" : true, "diacf" : false, "suffix" : {"ub" : 8, "lb" : 3}}})},
RAW_STRING({"v" : {"v" : "test", "casef" : false, "diacf" : true, "suffix" : {"ub" : 8, "lb" : 3}}})},
};

for (size_t i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {
Expand Down
40 changes: 20 additions & 20 deletions test/test-mongocrypt-ctx-encrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -2484,8 +2484,8 @@ static void _test_encrypt_fle2_explicit(_mongocrypt_tester_t *tester) {
tc.user_key_id = &keyABC_id;
tc.keys_to_feed[0] = keyABC;
tc.text_opts = TEST_BSON(RAW_STRING({
"caseSensitive" : false,
"diacriticSensitive" : false,
"caseSensitive" : true,
"diacriticSensitive" : true,
"suffix" : {"strMinQueryLength" : 1, "strMaxQueryLength" : 100}
}));
tc.expect = TEST_FILE("./test/data/fle2-explicit/find-suffix.json");
Expand All @@ -2502,8 +2502,8 @@ static void _test_encrypt_fle2_explicit(_mongocrypt_tester_t *tester) {
tc.user_key_id = &keyABC_id;
tc.keys_to_feed[0] = keyABC;
tc.text_opts = TEST_BSON(RAW_STRING({
"caseSensitive" : false,
"diacriticSensitive" : false,
"caseSensitive" : true,
"diacriticSensitive" : true,
"prefix" : {"strMinQueryLength" : 1, "strMaxQueryLength" : 100}
}));
tc.expect = TEST_FILE("./test/data/fle2-explicit/find-prefix.json");
Expand All @@ -2520,8 +2520,8 @@ static void _test_encrypt_fle2_explicit(_mongocrypt_tester_t *tester) {
tc.user_key_id = &keyABC_id;
tc.keys_to_feed[0] = keyABC;
tc.text_opts = TEST_BSON(RAW_STRING({
"caseSensitive" : false,
"diacriticSensitive" : false,
"caseSensitive" : true,
"diacriticSensitive" : true,
"suffix" : {"strMinQueryLength" : 1, "strMaxQueryLength" : 100}
}));
tc.expect = TEST_FILE("./test/data/fle2-explicit/find-suffix.json");
Expand All @@ -2538,8 +2538,8 @@ static void _test_encrypt_fle2_explicit(_mongocrypt_tester_t *tester) {
tc.user_key_id = &keyABC_id;
tc.keys_to_feed[0] = keyABC;
tc.text_opts = TEST_BSON(RAW_STRING({
"caseSensitive" : false,
"diacriticSensitive" : false,
"caseSensitive" : true,
"diacriticSensitive" : true,
"prefix" : {"strMinQueryLength" : 1, "strMaxQueryLength" : 100}
}));
tc.expect = TEST_FILE("./test/data/fle2-explicit/find-prefix.json");
Expand All @@ -2556,8 +2556,8 @@ static void _test_encrypt_fle2_explicit(_mongocrypt_tester_t *tester) {
tc.user_key_id = &keyABC_id;
tc.keys_to_feed[0] = keyABC;
tc.text_opts = TEST_BSON(RAW_STRING({
"caseSensitive" : false,
"diacriticSensitive" : false,
"caseSensitive" : true,
"diacriticSensitive" : true,
"substring" : {"strMaxLength" : 100, "strMinQueryLength" : 1, "strMaxQueryLength" : 100}
}));
tc.expect = TEST_FILE("./test/data/fle2-explicit/find-substring.json");
Expand All @@ -2576,8 +2576,8 @@ static void _test_encrypt_fle2_explicit(_mongocrypt_tester_t *tester) {
tc.user_key_id = &keyABC_id;
tc.keys_to_feed[0] = keyABC;
tc.text_opts = TEST_BSON(RAW_STRING({
"caseSensitive" : false,
"diacriticSensitive" : false,
"caseSensitive" : true,
"diacriticSensitive" : true,
"suffix" : {"strMinQueryLength" : 1, "strMaxQueryLength" : 100}
}));
tc.expect = TEST_FILE("./test/data/fle2-explicit/insert-suffix.json");
Expand All @@ -2596,8 +2596,8 @@ static void _test_encrypt_fle2_explicit(_mongocrypt_tester_t *tester) {
tc.user_key_id = &keyABC_id;
tc.keys_to_feed[0] = keyABC;
tc.text_opts = TEST_BSON(RAW_STRING({
"caseSensitive" : false,
"diacriticSensitive" : false,
"caseSensitive" : true,
"diacriticSensitive" : true,
"prefix" : {"strMinQueryLength" : 1, "strMaxQueryLength" : 100}
}));
tc.expect = TEST_FILE("./test/data/fle2-explicit/insert-prefix.json");
Expand All @@ -2616,8 +2616,8 @@ static void _test_encrypt_fle2_explicit(_mongocrypt_tester_t *tester) {
tc.user_key_id = &keyABC_id;
tc.keys_to_feed[0] = keyABC;
tc.text_opts = TEST_BSON(RAW_STRING({
"caseSensitive" : false,
"diacriticSensitive" : false,
"caseSensitive" : true,
"diacriticSensitive" : true,
"substring" : {"strMaxLength" : 100, "strMinQueryLength" : 1, "strMaxQueryLength" : 100}
}));
tc.expect = TEST_FILE("./test/data/fle2-explicit/insert-substring.json");
Expand All @@ -2636,8 +2636,8 @@ static void _test_encrypt_fle2_explicit(_mongocrypt_tester_t *tester) {
tc.user_key_id = &keyABC_id;
tc.keys_to_feed[0] = keyABC;
tc.text_opts = TEST_BSON(RAW_STRING({
"caseSensitive" : false,
"diacriticSensitive" : false,
"caseSensitive" : true,
"diacriticSensitive" : true,
"prefix" : {"strMinQueryLength" : 1, "strMaxQueryLength" : 100},
"suffix" : {"strMinQueryLength" : 1, "strMaxQueryLength" : 100}
}));
Expand Down Expand Up @@ -2675,8 +2675,8 @@ static void _test_encrypt_fle2_explicit(_mongocrypt_tester_t *tester) {
tc.keys_to_feed[0] = keyABC;
tc.query_type = MONGOCRYPT_QUERY_TYPE_PREFIXPREVIEW_DEPRECATED_STR;
tc.text_opts = TEST_BSON(RAW_STRING({
"caseSensitive" : false,
"diacriticSensitive" : false,
"caseSensitive" : true,
"diacriticSensitive" : true,
"prefix" : {"strMinQueryLength" : 1, "strMaxQueryLength" : 100},
"suffix" : {"strMinQueryLength" : 1, "strMaxQueryLength" : 100}
}));
Expand Down