Skip to content

Commit 33ed617

Browse files
authoredFeb 27, 2025
CDRIVER-5861 support $lookup in CSFLE and QE (#1880)
* update table for test mock servers * remove trailing colons in error message * update libmongocrypt * pass all `listCollections` results to libmongocrypt Accounts for updated protocol in MONGOCRYPT-723. * fail test on error in `get_bson_from_json_file` * add test wire version checks for server 8.1 * use `const` in `ASSERT_EQUAL_BSON` * implement prose tests * apply majority write concern * drop individual collections To match latest revision of prose tests * fix param name
1 parent e93245d commit 33ed617

13 files changed

+660
-15
lines changed
 

Diff for: ‎.evergreen/scripts/compile-libmongocrypt.sh

+8-2
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,20 @@ compile_libmongocrypt() {
1010
# `.evergreen/scripts/kms-divergence-check.sh` to ensure that there is no
1111
# divergence in the copied files.
1212

13-
git clone -q --depth=1 https://github.com/mongodb/libmongocrypt --branch 1.12.0 || return
13+
# Clone libmongocrypt and check-out commit for MONGOCRYPT-723.
14+
# TODO: once libmongocrypt 1.13.0 is released, updated to:
15+
# git clone -q --depth=1 https://github.com/mongodb/libmongocrypt --branch 1.13.0 || return
16+
git clone -q https://github.com/mongodb/libmongocrypt || return
17+
cd libmongocrypt
18+
git checkout 33fdf65cce5a0c0cdd293c64ed40e4a8205c3ce0
19+
cd ..
1420

1521
declare -a crypt_cmake_flags=(
1622
"-DMONGOCRYPT_MONGOC_DIR=${mongoc_dir}"
1723
"-DBUILD_TESTING=OFF"
1824
"-DENABLE_ONLINE_TESTS=OFF"
1925
"-DENABLE_MONGOC=OFF"
20-
"-DBUILD_VERSION=1.12.0"
26+
"-DBUILD_VERSION=1.13.0-pre"
2127
)
2228

2329
. "$(dirname "${BASH_SOURCE[0]}")/find-ccache.sh"

Diff for: ‎CONTRIBUTING.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,9 @@ The set of mock KMS servers running in the background and their corresponding in
289289
| 8999 | ca.pem | server.pem | python -u kms_http_server.py --ca_file ../x509gen/ca.pem --cert_file ../x509gen/server.pem --port 8999
290290
| 9000 | ca.pem | expired.pem | python -u kms_http_server.py --ca_file ../x509gen/ca.pem --cert_file ../x509gen/expired.pem --port 9000
291291
| 9001 | ca.pem | wrong-host.pem | python -u kms_http_server.py --ca_file ../x509gen/ca.pem --cert_file ../x509gen/wrong-host.pem --port 9001
292-
| 9002 | ca.pem | server.pem | python -u kms_http_server.py --ca_file ../x509gen/ca.pem --cert_file ../x509gen/server.pem --port --require_client_cert 9002
292+
| 9002 | ca.pem | server.pem | python -u kms_http_server.py --ca_file ../x509gen/ca.pem --cert_file ../x509gen/server.pem --require_client_cert --port 9002
293293
| 5698 | ca.pem | server.pem | python -u kms_kmip_server.py
294+
| 9003 | ca.pem | server.pem | python kms_failpoint_server.py --port 9003
294295

295296
The path to `ca.pem` and `client.pem` must be passed through the following environment variables:
296297

Diff for: ‎src/libmongoc/src/mongoc/mongoc-crypt.c

+12-5
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ _prefix_mongocryptd_error (bson_error_t *error)
170170
char buf[sizeof (error->message)];
171171

172172
// Truncation is OK.
173-
int req = bson_snprintf (buf, sizeof (buf), "mongocryptd error: %s:", error->message);
173+
int req = bson_snprintf (buf, sizeof (buf), "mongocryptd error: %s", error->message);
174174
BSON_ASSERT (req > 0);
175175
memcpy (error->message, buf, sizeof (buf));
176176
}
@@ -181,7 +181,7 @@ _prefix_keyvault_error (bson_error_t *error)
181181
char buf[sizeof (error->message)];
182182

183183
// Truncation is OK.
184-
int req = bson_snprintf (buf, sizeof (buf), "key vault error: %s:", error->message);
184+
int req = bson_snprintf (buf, sizeof (buf), "key vault error: %s", error->message);
185185
BSON_ASSERT (req > 0);
186186
memcpy (error->message, buf, sizeof (buf));
187187
}
@@ -342,15 +342,18 @@ _state_need_mongo_collinfo (_state_machine_t *state_machine, bson_error_t *error
342342
goto fail;
343343
}
344344

345-
/* 2. Return the first result (if any) with mongocrypt_ctx_mongo_feed or
345+
/* 2. Return all results (if any) with mongocrypt_ctx_mongo_feed or
346346
* proceed to the next step if nothing was returned. */
347-
if (mongoc_cursor_next (cursor, &collinfo_bson)) {
347+
while (mongoc_cursor_next (cursor, &collinfo_bson)) {
348348
collinfo_bin = mongocrypt_binary_new_from_data ((uint8_t *) bson_get_data (collinfo_bson), collinfo_bson->len);
349349
if (!mongocrypt_ctx_mongo_feed (state_machine->ctx, collinfo_bin)) {
350350
_ctx_check_error (state_machine->ctx, error, true);
351351
goto fail;
352352
}
353-
} else if (mongoc_cursor_error (cursor, error)) {
353+
mongocrypt_binary_destroy (collinfo_bin);
354+
collinfo_bin = NULL;
355+
}
356+
if (mongoc_cursor_error (cursor, error)) {
354357
goto fail;
355358
}
356359

@@ -1397,6 +1400,10 @@ _mongoc_crypt_new (const bson_t *kms_providers,
13971400
crypt->kmsid_to_tlsopts = mcd_mapof_kmsid_to_tlsopts_new ();
13981401
crypt->handle = mongocrypt_new ();
13991402
mongocrypt_setopt_retry_kms (crypt->handle, true);
1403+
if (!mongocrypt_setopt_enable_multiple_collinfo (crypt->handle)) {
1404+
_crypt_check_error (crypt->handle, error, true);
1405+
goto fail;
1406+
}
14001407

14011408
// Stash away a copy of the user's kmsProviders in case we need to lazily
14021409
// load credentials.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"_id": {
3+
"$binary": {
4+
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
5+
"subType": "04"
6+
}
7+
},
8+
"keyMaterial": {
9+
"$binary": {
10+
"base64": "sHe0kz57YW7v8g9VP9sf/+K1ex4JqKc5rf/URX3n3p8XdZ6+15uXPaSayC6adWbNxkFskuMCOifDoTT+rkqMtFkDclOy884RuGGtUysq3X7zkAWYTKi8QAfKkajvVbZl2y23UqgVasdQu3OVBQCrH/xY00nNAs/52e958nVjBuzQkSb1T8pKJAyjZsHJ60+FtnfafDZSTAIBJYn7UWBCwQ==",
11+
"subType": "00"
12+
}
13+
},
14+
"creationDate": {
15+
"$date": {
16+
"$numberLong": "1648914851981"
17+
}
18+
},
19+
"updateDate": {
20+
"$date": {
21+
"$numberLong": "1648914851981"
22+
}
23+
},
24+
"status": {
25+
"$numberInt": "0"
26+
},
27+
"masterKey": {
28+
"provider": "local"
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"properties": {
3+
"csfle": {
4+
"encrypt": {
5+
"keyId": [
6+
{
7+
"$binary": {
8+
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
9+
"subType": "04"
10+
}
11+
}
12+
],
13+
"bsonType": "string",
14+
"algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"
15+
}
16+
}
17+
},
18+
"bsonType": "object"
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"properties": {
3+
"csfle2": {
4+
"encrypt": {
5+
"keyId": [
6+
{
7+
"$binary": {
8+
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
9+
"subType": "04"
10+
}
11+
}
12+
],
13+
"bsonType": "string",
14+
"algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"
15+
}
16+
}
17+
},
18+
"bsonType": "object"
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"escCollection": "enxcol_.qe.esc",
3+
"ecocCollection": "enxcol_.qe.ecoc",
4+
"fields": [
5+
{
6+
"keyId": {
7+
"$binary": {
8+
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
9+
"subType": "04"
10+
}
11+
},
12+
"path": "qe",
13+
"bsonType": "string",
14+
"queries": {
15+
"queryType": "equality",
16+
"contention": 0
17+
}
18+
}
19+
]
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"escCollection": "enxcol_.qe2.esc",
3+
"ecocCollection": "enxcol_.qe2.ecoc",
4+
"fields": [
5+
{
6+
"keyId": {
7+
"$binary": {
8+
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
9+
"subType": "04"
10+
}
11+
},
12+
"path": "qe2",
13+
"bsonType": "string",
14+
"queries": {
15+
"queryType": "equality",
16+
"contention": 0
17+
}
18+
}
19+
]
20+
}

Diff for: ‎src/libmongoc/tests/json-test.c

+3-6
Original file line numberDiff line numberDiff line change
@@ -663,27 +663,24 @@ get_bson_from_json_file (char *filename)
663663

664664
file = fopen (filename, "rb");
665665
if (!file) {
666-
return NULL;
666+
test_error ("Failed to open JSON file: %s", filename);
667667
}
668668

669669
/* get file length */
670670
fseek (file, 0, SEEK_END);
671671
length = ftell (file);
672672
fseek (file, 0, SEEK_SET);
673673
if (length < 1) {
674-
return NULL;
674+
test_error ("Failed to read length of JSON file: %s", filename);
675675
}
676676

677677
/* read entire file into buffer */
678678
buffer = (const char *) bson_malloc0 (length);
679679
if (fread ((void *) buffer, 1, length, file) != length) {
680-
test_error ("Failed to read JSON file into buffer");
680+
test_error ("Failed to read JSON file into buffer: %s", filename);
681681
}
682682

683683
fclose (file);
684-
if (!buffer) {
685-
return NULL;
686-
}
687684

688685
/* convert to bson */
689686
data = bson_new_from_json ((const uint8_t *) buffer, length, &error);

Diff for: ‎src/libmongoc/tests/test-conveniences.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ match_json (const bson_t *doc,
209209

210210
#define ASSERT_EQUAL_BSON(expected, actual) \
211211
do { \
212-
bson_t *_expected_bson = expected, *_actual_bson = actual; \
212+
const bson_t *_expected_bson = expected, *_actual_bson = actual; \
213213
char *_expected_str, *_actual_str; \
214214
_expected_str = bson_as_canonical_extended_json (_expected_bson, NULL); \
215215
_actual_str = bson_as_canonical_extended_json (_actual_bson, NULL); \

Diff for: ‎src/libmongoc/tests/test-libmongoc.c

+2
Original file line numberDiff line numberDiff line change
@@ -2273,6 +2273,8 @@ WIRE_VERSION_CHECKS (23)
22732273
WIRE_VERSION_CHECKS (24)
22742274
/* wire version 25 begins with the 8.0 release. */
22752275
WIRE_VERSION_CHECKS (25)
2276+
/* wire version 26 begins with the 8.1 release. */
2277+
WIRE_VERSION_CHECKS (26)
22762278

22772279
int
22782280
test_framework_skip_if_no_dual_ip_hostname (void)

Diff for: ‎src/libmongoc/tests/test-libmongoc.h

+2
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ WIRE_VERSION_CHECK_DECLS (23)
216216
WIRE_VERSION_CHECK_DECLS (24)
217217
/* wire version 25 begins with the 8.0 release. */
218218
WIRE_VERSION_CHECK_DECLS (25)
219+
/* wire version 26 begins with the 8.1 release. */
220+
WIRE_VERSION_CHECK_DECLS (26)
219221

220222
#undef WIRE_VERSION_CHECK_DECLS
221223

0 commit comments

Comments
 (0)
Please sign in to comment.