Skip to content

Commit abf9905

Browse files
authored
CDRIVER-3856 skip CSE listCollections cmds (#741)
1 parent aa35241 commit abf9905

25 files changed

+38
-443
lines changed

src/libmongoc/tests/json-test-monitoring.c

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,8 @@ apm_match_visitor (match_ctx_t *ctx,
406406
}
407407
} else if (strstr (ctx->path, "updates.")) {
408408
/* tests expect "multi: false" and "upsert: false" explicitly;
409-
* we don't send them. fix when path is like "updates.0", "updates.1", ...
410-
*/
409+
* we don't send them. fix when path is like "updates.0", "updates.1", ...
410+
*/
411411

412412
if (!strcmp (key, "multi") && !bson_iter_bool (pattern_iter)) {
413413
return MATCH_ACTION_SKIP;
@@ -442,6 +442,29 @@ _apm_match_error_context (const bson_t *actual, const bson_t *expectations)
442442
bson_free (actual_str);
443443
bson_free (expectations_str);
444444
}
445+
446+
bool
447+
skip_cse_list_collections (const bson_t *doc)
448+
{
449+
/* see CDRIVER-3856: Sharing a MongoClient for metadata lookup can lead to
450+
* deadlock in drivers using automatic encryption. Since the C driver does
451+
* not use a separate 'mongoc_client_t' for listCollections and finds on the
452+
* key vault, we skip these checks. */
453+
const char *val;
454+
455+
if (!bson_has_field (doc, "command_started_event.command.listCollections"))
456+
return false;
457+
458+
if (!bson_has_field (doc, "command_started_event.command.$db"))
459+
return false;
460+
461+
val = bson_lookup_utf8 (doc, "command_started_event.command.$db");
462+
if (0 != strcmp (val, "keyvault"))
463+
return false;
464+
465+
return true;
466+
}
467+
445468
/*
446469
*-----------------------------------------------------------------------
447470
*
@@ -520,16 +543,20 @@ check_json_apm_events (json_test_ctx_t *ctx, const bson_t *expectations)
520543
/* if we allow matching only a subset of actual events, skip
521544
* non-matching ones */
522545
continue;
523-
} else {
524-
_apm_match_error_context (&ctx->events, expectations);
525-
test_error ("could not match APM event\n"
526-
"\texpected: %s\n\n"
527-
"\tactual : %s\n\n"
528-
"\terror : %s\n\n",
529-
bson_as_canonical_extended_json (&expectation, NULL),
530-
bson_as_canonical_extended_json (&actual, NULL),
531-
match_ctx.errmsg);
532546
}
547+
548+
if (skip_cse_list_collections (&actual)) {
549+
continue;
550+
}
551+
552+
_apm_match_error_context (&ctx->events, expectations);
553+
test_error ("could not match APM event\n"
554+
"\texpected: %s\n\n"
555+
"\tactual : %s\n\n"
556+
"\terror : %s\n\n",
557+
bson_as_canonical_extended_json (&expectation, NULL),
558+
bson_as_canonical_extended_json (&actual, NULL),
559+
match_ctx.errmsg);
533560
}
534561

535562
if (!matched) {

src/libmongoc/tests/json/client_side_encryption/aggregate.json

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,6 @@
150150
"command_name": "listCollections"
151151
}
152152
},
153-
{
154-
"command_started_event": {
155-
"command": {
156-
"listCollections": 1,
157-
"filter": {
158-
"name": "datakeys"
159-
},
160-
"$db": "keyvault"
161-
},
162-
"command_name": "listCollections"
163-
}
164-
},
165153
{
166154
"command_started_event": {
167155
"command": {
@@ -273,18 +261,6 @@
273261
"command_name": "aggregate"
274262
}
275263
},
276-
{
277-
"command_started_event": {
278-
"command": {
279-
"listCollections": 1,
280-
"filter": {
281-
"name": "datakeys"
282-
},
283-
"$db": "keyvault"
284-
},
285-
"command_name": "listCollections"
286-
}
287-
},
288264
{
289265
"command_started_event": {
290266
"command": {

src/libmongoc/tests/json/client_side_encryption/azureKMS.json

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,6 @@
139139
"command_name": "listCollections"
140140
}
141141
},
142-
{
143-
"command_started_event": {
144-
"command": {
145-
"listCollections": 1,
146-
"filter": {
147-
"name": "datakeys"
148-
},
149-
"$db": "keyvault"
150-
},
151-
"command_name": "listCollections"
152-
}
153-
},
154142
{
155143
"command_started_event": {
156144
"command": {

src/libmongoc/tests/json/client_side_encryption/basic.json

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -144,18 +144,6 @@
144144
"command_name": "listCollections"
145145
}
146146
},
147-
{
148-
"command_started_event": {
149-
"command": {
150-
"listCollections": 1,
151-
"filter": {
152-
"name": "datakeys"
153-
},
154-
"$db": "keyvault"
155-
},
156-
"command_name": "listCollections"
157-
}
158-
},
159147
{
160148
"command_started_event": {
161149
"command": {
@@ -283,18 +271,6 @@
283271
"command_name": "listCollections"
284272
}
285273
},
286-
{
287-
"command_started_event": {
288-
"command": {
289-
"listCollections": 1,
290-
"filter": {
291-
"name": "datakeys"
292-
},
293-
"$db": "keyvault"
294-
},
295-
"command_name": "listCollections"
296-
}
297-
},
298274
{
299275
"command_started_event": {
300276
"command": {

src/libmongoc/tests/json/client_side_encryption/bulk.json

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -178,18 +178,6 @@
178178
"command_name": "listCollections"
179179
}
180180
},
181-
{
182-
"command_started_event": {
183-
"command": {
184-
"listCollections": 1,
185-
"filter": {
186-
"name": "datakeys"
187-
},
188-
"$db": "keyvault"
189-
},
190-
"command_name": "listCollections"
191-
}
192-
},
193181
{
194182
"command_started_event": {
195183
"command": {

src/libmongoc/tests/json/client_side_encryption/count.json

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,6 @@
149149
"command_name": "listCollections"
150150
}
151151
},
152-
{
153-
"command_started_event": {
154-
"command": {
155-
"listCollections": 1,
156-
"filter": {
157-
"name": "datakeys"
158-
},
159-
"$db": "keyvault"
160-
},
161-
"command_name": "listCollections"
162-
}
163-
},
164152
{
165153
"command_started_event": {
166154
"command": {

src/libmongoc/tests/json/client_side_encryption/countDocuments.json

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,6 @@
150150
"command_name": "listCollections"
151151
}
152152
},
153-
{
154-
"command_started_event": {
155-
"command": {
156-
"listCollections": 1,
157-
"filter": {
158-
"name": "datakeys"
159-
},
160-
"$db": "keyvault"
161-
},
162-
"command_name": "listCollections"
163-
}
164-
},
165153
{
166154
"command_started_event": {
167155
"command": {

src/libmongoc/tests/json/client_side_encryption/delete.json

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -151,18 +151,6 @@
151151
"command_name": "listCollections"
152152
}
153153
},
154-
{
155-
"command_started_event": {
156-
"command": {
157-
"listCollections": 1,
158-
"filter": {
159-
"name": "datakeys"
160-
},
161-
"$db": "keyvault"
162-
},
163-
"command_name": "listCollections"
164-
}
165-
},
166154
{
167155
"command_started_event": {
168156
"command": {
@@ -276,18 +264,6 @@
276264
"command_name": "listCollections"
277265
}
278266
},
279-
{
280-
"command_started_event": {
281-
"command": {
282-
"listCollections": 1,
283-
"filter": {
284-
"name": "datakeys"
285-
},
286-
"$db": "keyvault"
287-
},
288-
"command_name": "listCollections"
289-
}
290-
},
291267
{
292268
"command_started_event": {
293269
"command": {

src/libmongoc/tests/json/client_side_encryption/distinct.json

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,6 @@
161161
"command_name": "listCollections"
162162
}
163163
},
164-
{
165-
"command_started_event": {
166-
"command": {
167-
"listCollections": 1,
168-
"filter": {
169-
"name": "datakeys"
170-
},
171-
"$db": "keyvault"
172-
},
173-
"command_name": "listCollections"
174-
}
175-
},
176164
{
177165
"command_started_event": {
178166
"command": {

src/libmongoc/tests/json/client_side_encryption/explain.json

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -155,18 +155,6 @@
155155
"command_name": "listCollections"
156156
}
157157
},
158-
{
159-
"command_started_event": {
160-
"command": {
161-
"listCollections": 1,
162-
"filter": {
163-
"name": "datakeys"
164-
},
165-
"$db": "keyvault"
166-
},
167-
"command_name": "listCollections"
168-
}
169-
},
170158
{
171159
"command_started_event": {
172160
"command": {

0 commit comments

Comments
 (0)