Skip to content

Commit d64db0a

Browse files
authored
MONGOCRYPT-903 Case and diacritic sensitivity not honored for explicit encryption (#1158)
1 parent 47405e7 commit d64db0a

4 files changed

Lines changed: 41 additions & 39 deletions

File tree

bindings/python/test/data/fle2-text-search/textopts.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"caseSensitive": true,
3-
"diacriticSensitive": true,
2+
"caseSensitive": false,
3+
"diacriticSensitive": false,
44
"prefix": {
55
"strMaxQueryLength": 10,
66
"strMinQueryLength": 2

src/mc-textopts.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,14 @@ static bool TextOpts_to_FLE2TextSearchInsertSpec(const mc_TextOpts_t *txo,
271271
CLIENT_ERR(ERROR_PREFIX "Error appending to BSON");
272272
return false;
273273
}
274-
if (!bson_append_bool(&child, "casef", -1, txo->caseSensitive)) {
274+
// "casef" means "case folding". Case sensitive => not folded. Case insensitive => folded.
275+
if (!bson_append_bool(&child, "casef", -1, !txo->caseSensitive)) {
275276
CLIENT_ERR(ERROR_PREFIX "Error appending to BSON");
276277
return false;
277278
}
278279

279-
if (!bson_append_bool(&child, "diacf", -1, txo->diacriticSensitive)) {
280+
// "diacf" means "diacritic folding". Diacritic sensitive => not folded. Diacritic insensitive => folded.
281+
if (!bson_append_bool(&child, "diacf", -1, !txo->diacriticSensitive)) {
280282
CLIENT_ERR(ERROR_PREFIX "Error appending to BSON");
281283
return false;
282284
}

test/test-mc-textopts.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -157,35 +157,35 @@ static void test_mc_TextOpts_to_FLE2TextSearchInsertSpec(_mongocrypt_tester_t *t
157157
testcase tests[] = {
158158
{.desc = "Works with substring",
159159
.in = RAW_STRING({
160-
"caseSensitive" : true,
161-
"diacriticSensitive" : false,
160+
"caseSensitive" : false,
161+
"diacriticSensitive" : true,
162162
"substring" : {"strMaxLength" : 10, "strMinQueryLength" : 3, "strMaxQueryLength" : 8}
163163
}),
164164
.v = RAW_STRING({"v" : "test"}),
165165
.expect = RAW_STRING(
166166
{"v" : {"v" : "test", "casef" : true, "diacf" : false, "substr" : {"mlen" : 10, "ub" : 8, "lb" : 3}}})},
167167
{.desc = "Works with prefix",
168168
.in = RAW_STRING({
169-
"caseSensitive" : true,
170-
"diacriticSensitive" : false,
169+
"caseSensitive" : false,
170+
"diacriticSensitive" : true,
171171
"prefix" : {"strMinQueryLength" : 3, "strMaxQueryLength" : 8}
172172
}),
173173
.v = RAW_STRING({"v" : "test"}),
174174
.expect =
175175
RAW_STRING({"v" : {"v" : "test", "casef" : true, "diacf" : false, "prefix" : {"ub" : 8, "lb" : 3}}})},
176176
{.desc = "Works with suffix",
177177
.in = RAW_STRING({
178-
"caseSensitive" : true,
179-
"diacriticSensitive" : false,
178+
"caseSensitive" : false,
179+
"diacriticSensitive" : true,
180180
"suffix" : {"strMinQueryLength" : 3, "strMaxQueryLength" : 8}
181181
}),
182182
.v = RAW_STRING({"v" : "test"}),
183183
.expect =
184184
RAW_STRING({"v" : {"v" : "test", "casef" : true, "diacf" : false, "suffix" : {"ub" : 8, "lb" : 3}}})},
185185
{.desc = "Works with prefix + suffix",
186186
.in = RAW_STRING({
187-
"caseSensitive" : true,
188-
"diacriticSensitive" : false,
187+
"caseSensitive" : false,
188+
"diacriticSensitive" : true,
189189
"prefix" : {"strMinQueryLength" : 4, "strMaxQueryLength" : 9},
190190
"suffix" : {"strMinQueryLength" : 3, "strMaxQueryLength" : 8}
191191
}),
@@ -201,8 +201,8 @@ static void test_mc_TextOpts_to_FLE2TextSearchInsertSpec(_mongocrypt_tester_t *t
201201
})},
202202
{.desc = "Errors with missing v",
203203
.in = RAW_STRING({
204-
"caseSensitive" : true,
205-
"diacriticSensitive" : false,
204+
"caseSensitive" : false,
205+
"diacriticSensitive" : true,
206206
"prefix" : {"strMinQueryLength" : 3, "strMaxQueryLength" : 8}
207207
}),
208208
.v = RAW_STRING({"foo" : "bar"}),
@@ -247,7 +247,7 @@ static void test_mc_TextOpts_to_FLE2TextSearchInsertSpec_for_query(_mongocrypt_t
247247
.v = RAW_STRING({"v" : "test"}),
248248
.qt = MONGOCRYPT_QUERY_TYPE_SUBSTRINGPREVIEW,
249249
.expect = RAW_STRING(
250-
{"v" : {"v" : "test", "casef" : true, "diacf" : false, "substr" : {"mlen" : 10, "ub" : 8, "lb" : 3}}})},
250+
{"v" : {"v" : "test", "casef" : false, "diacf" : true, "substr" : {"mlen" : 10, "ub" : 8, "lb" : 3}}})},
251251
{.desc = "Works with prefix",
252252
.in = RAW_STRING({
253253
"caseSensitive" : true,
@@ -257,7 +257,7 @@ static void test_mc_TextOpts_to_FLE2TextSearchInsertSpec_for_query(_mongocrypt_t
257257
.v = RAW_STRING({"v" : "test"}),
258258
.qt = MONGOCRYPT_QUERY_TYPE_PREFIX,
259259
.expect =
260-
RAW_STRING({"v" : {"v" : "test", "casef" : true, "diacf" : false, "prefix" : {"ub" : 8, "lb" : 3}}})},
260+
RAW_STRING({"v" : {"v" : "test", "casef" : false, "diacf" : true, "prefix" : {"ub" : 8, "lb" : 3}}})},
261261
{.desc = "Works with suffix",
262262
.in = RAW_STRING({
263263
"caseSensitive" : true,
@@ -267,7 +267,7 @@ static void test_mc_TextOpts_to_FLE2TextSearchInsertSpec_for_query(_mongocrypt_t
267267
.v = RAW_STRING({"v" : "test"}),
268268
.qt = MONGOCRYPT_QUERY_TYPE_SUFFIX,
269269
.expect =
270-
RAW_STRING({"v" : {"v" : "test", "casef" : true, "diacf" : false, "suffix" : {"ub" : 8, "lb" : 3}}})},
270+
RAW_STRING({"v" : {"v" : "test", "casef" : false, "diacf" : true, "suffix" : {"ub" : 8, "lb" : 3}}})},
271271
{.desc = "Works with prefix + suffix when querying prefix",
272272
.in = RAW_STRING({
273273
"caseSensitive" : true,
@@ -278,7 +278,7 @@ static void test_mc_TextOpts_to_FLE2TextSearchInsertSpec_for_query(_mongocrypt_t
278278
.v = RAW_STRING({"v" : "test"}),
279279
.qt = MONGOCRYPT_QUERY_TYPE_PREFIX,
280280
.expect =
281-
RAW_STRING({"v" : {"v" : "test", "casef" : true, "diacf" : false, "prefix" : {"ub" : 9, "lb" : 4}}})},
281+
RAW_STRING({"v" : {"v" : "test", "casef" : false, "diacf" : true, "prefix" : {"ub" : 9, "lb" : 4}}})},
282282
{.desc = "Works with prefix + suffix when querying suffix",
283283
.in = RAW_STRING({
284284
"caseSensitive" : true,
@@ -289,7 +289,7 @@ static void test_mc_TextOpts_to_FLE2TextSearchInsertSpec_for_query(_mongocrypt_t
289289
.v = RAW_STRING({"v" : "test"}),
290290
.qt = MONGOCRYPT_QUERY_TYPE_SUFFIX,
291291
.expect =
292-
RAW_STRING({"v" : {"v" : "test", "casef" : true, "diacf" : false, "suffix" : {"ub" : 8, "lb" : 3}}})},
292+
RAW_STRING({"v" : {"v" : "test", "casef" : false, "diacf" : true, "suffix" : {"ub" : 8, "lb" : 3}}})},
293293
};
294294

295295
for (size_t i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {

test/test-mongocrypt-ctx-encrypt.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2484,8 +2484,8 @@ static void _test_encrypt_fle2_explicit(_mongocrypt_tester_t *tester) {
24842484
tc.user_key_id = &keyABC_id;
24852485
tc.keys_to_feed[0] = keyABC;
24862486
tc.text_opts = TEST_BSON(RAW_STRING({
2487-
"caseSensitive" : false,
2488-
"diacriticSensitive" : false,
2487+
"caseSensitive" : true,
2488+
"diacriticSensitive" : true,
24892489
"suffix" : {"strMinQueryLength" : 1, "strMaxQueryLength" : 100}
24902490
}));
24912491
tc.expect = TEST_FILE("./test/data/fle2-explicit/find-suffix.json");
@@ -2502,8 +2502,8 @@ static void _test_encrypt_fle2_explicit(_mongocrypt_tester_t *tester) {
25022502
tc.user_key_id = &keyABC_id;
25032503
tc.keys_to_feed[0] = keyABC;
25042504
tc.text_opts = TEST_BSON(RAW_STRING({
2505-
"caseSensitive" : false,
2506-
"diacriticSensitive" : false,
2505+
"caseSensitive" : true,
2506+
"diacriticSensitive" : true,
25072507
"prefix" : {"strMinQueryLength" : 1, "strMaxQueryLength" : 100}
25082508
}));
25092509
tc.expect = TEST_FILE("./test/data/fle2-explicit/find-prefix.json");
@@ -2520,8 +2520,8 @@ static void _test_encrypt_fle2_explicit(_mongocrypt_tester_t *tester) {
25202520
tc.user_key_id = &keyABC_id;
25212521
tc.keys_to_feed[0] = keyABC;
25222522
tc.text_opts = TEST_BSON(RAW_STRING({
2523-
"caseSensitive" : false,
2524-
"diacriticSensitive" : false,
2523+
"caseSensitive" : true,
2524+
"diacriticSensitive" : true,
25252525
"suffix" : {"strMinQueryLength" : 1, "strMaxQueryLength" : 100}
25262526
}));
25272527
tc.expect = TEST_FILE("./test/data/fle2-explicit/find-suffix.json");
@@ -2538,8 +2538,8 @@ static void _test_encrypt_fle2_explicit(_mongocrypt_tester_t *tester) {
25382538
tc.user_key_id = &keyABC_id;
25392539
tc.keys_to_feed[0] = keyABC;
25402540
tc.text_opts = TEST_BSON(RAW_STRING({
2541-
"caseSensitive" : false,
2542-
"diacriticSensitive" : false,
2541+
"caseSensitive" : true,
2542+
"diacriticSensitive" : true,
25432543
"prefix" : {"strMinQueryLength" : 1, "strMaxQueryLength" : 100}
25442544
}));
25452545
tc.expect = TEST_FILE("./test/data/fle2-explicit/find-prefix.json");
@@ -2556,8 +2556,8 @@ static void _test_encrypt_fle2_explicit(_mongocrypt_tester_t *tester) {
25562556
tc.user_key_id = &keyABC_id;
25572557
tc.keys_to_feed[0] = keyABC;
25582558
tc.text_opts = TEST_BSON(RAW_STRING({
2559-
"caseSensitive" : false,
2560-
"diacriticSensitive" : false,
2559+
"caseSensitive" : true,
2560+
"diacriticSensitive" : true,
25612561
"substring" : {"strMaxLength" : 100, "strMinQueryLength" : 1, "strMaxQueryLength" : 100}
25622562
}));
25632563
tc.expect = TEST_FILE("./test/data/fle2-explicit/find-substring.json");
@@ -2576,8 +2576,8 @@ static void _test_encrypt_fle2_explicit(_mongocrypt_tester_t *tester) {
25762576
tc.user_key_id = &keyABC_id;
25772577
tc.keys_to_feed[0] = keyABC;
25782578
tc.text_opts = TEST_BSON(RAW_STRING({
2579-
"caseSensitive" : false,
2580-
"diacriticSensitive" : false,
2579+
"caseSensitive" : true,
2580+
"diacriticSensitive" : true,
25812581
"suffix" : {"strMinQueryLength" : 1, "strMaxQueryLength" : 100}
25822582
}));
25832583
tc.expect = TEST_FILE("./test/data/fle2-explicit/insert-suffix.json");
@@ -2596,8 +2596,8 @@ static void _test_encrypt_fle2_explicit(_mongocrypt_tester_t *tester) {
25962596
tc.user_key_id = &keyABC_id;
25972597
tc.keys_to_feed[0] = keyABC;
25982598
tc.text_opts = TEST_BSON(RAW_STRING({
2599-
"caseSensitive" : false,
2600-
"diacriticSensitive" : false,
2599+
"caseSensitive" : true,
2600+
"diacriticSensitive" : true,
26012601
"prefix" : {"strMinQueryLength" : 1, "strMaxQueryLength" : 100}
26022602
}));
26032603
tc.expect = TEST_FILE("./test/data/fle2-explicit/insert-prefix.json");
@@ -2616,8 +2616,8 @@ static void _test_encrypt_fle2_explicit(_mongocrypt_tester_t *tester) {
26162616
tc.user_key_id = &keyABC_id;
26172617
tc.keys_to_feed[0] = keyABC;
26182618
tc.text_opts = TEST_BSON(RAW_STRING({
2619-
"caseSensitive" : false,
2620-
"diacriticSensitive" : false,
2619+
"caseSensitive" : true,
2620+
"diacriticSensitive" : true,
26212621
"substring" : {"strMaxLength" : 100, "strMinQueryLength" : 1, "strMaxQueryLength" : 100}
26222622
}));
26232623
tc.expect = TEST_FILE("./test/data/fle2-explicit/insert-substring.json");
@@ -2636,8 +2636,8 @@ static void _test_encrypt_fle2_explicit(_mongocrypt_tester_t *tester) {
26362636
tc.user_key_id = &keyABC_id;
26372637
tc.keys_to_feed[0] = keyABC;
26382638
tc.text_opts = TEST_BSON(RAW_STRING({
2639-
"caseSensitive" : false,
2640-
"diacriticSensitive" : false,
2639+
"caseSensitive" : true,
2640+
"diacriticSensitive" : true,
26412641
"prefix" : {"strMinQueryLength" : 1, "strMaxQueryLength" : 100},
26422642
"suffix" : {"strMinQueryLength" : 1, "strMaxQueryLength" : 100}
26432643
}));
@@ -2675,8 +2675,8 @@ static void _test_encrypt_fle2_explicit(_mongocrypt_tester_t *tester) {
26752675
tc.keys_to_feed[0] = keyABC;
26762676
tc.query_type = MONGOCRYPT_QUERY_TYPE_PREFIXPREVIEW_DEPRECATED_STR;
26772677
tc.text_opts = TEST_BSON(RAW_STRING({
2678-
"caseSensitive" : false,
2679-
"diacriticSensitive" : false,
2678+
"caseSensitive" : true,
2679+
"diacriticSensitive" : true,
26802680
"prefix" : {"strMinQueryLength" : 1, "strMaxQueryLength" : 100},
26812681
"suffix" : {"strMinQueryLength" : 1, "strMaxQueryLength" : 100}
26822682
}));

0 commit comments

Comments
 (0)