Skip to content

Commit f72bb13

Browse files
committed
add wire version check and test
1 parent 076d164 commit f72bb13

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

src/libmongoc/src/mongoc/mongoc-database.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,26 @@ create_collection_with_encryptedFields (mongoc_database_t *database,
11051105
goto fail;
11061106
}
11071107

1108+
mongoc_server_stream_t *stream =
1109+
mongoc_cluster_stream_for_writes (&database->client->cluster,
1110+
NULL /* client session */,
1111+
NULL /* reply */,
1112+
error);
1113+
if (!stream) {
1114+
goto fail;
1115+
}
1116+
if (stream->sd->max_wire_version < WIRE_VERSION_7_0) {
1117+
bson_set_error (
1118+
error,
1119+
MONGOC_ERROR_PROTOCOL,
1120+
MONGOC_ERROR_PROTOCOL_BAD_WIRE_VERSION,
1121+
"Driver support of Queryable Encryption is incompatible "
1122+
"with server. Upgrade server to use Queryable Encryption.");
1123+
mongoc_server_stream_cleanup (stream);
1124+
goto fail;
1125+
}
1126+
1127+
11081128
/* Create data collection. */
11091129
cc_opts = bson_copy (opts);
11101130
if (!BSON_APPEND_DOCUMENT (cc_opts, "encryptedFields", encryptedFields)) {
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"runOn": [
3+
{
4+
"minServerVersion": "6.0.0",
5+
"maxServerVersion": "6.3.99",
6+
"topology": [
7+
"replicaset",
8+
"sharded",
9+
"load-balanced"
10+
]
11+
}
12+
],
13+
"database_name": "default",
14+
"collection_name": "default",
15+
"tests": [
16+
{
17+
"description": "driver returns an error if creating a QEv2 collection on unsupported server",
18+
"clientOptions": {
19+
"autoEncryptOpts": {
20+
"kmsProviders": {
21+
"aws": {}
22+
},
23+
"encryptedFieldsMap": {
24+
"default.encryptedCollection": {
25+
"escCollection": "enxcol_.encryptedCollection.esc",
26+
"ecocCollection": "enxcol_.encryptedCollection.ecoc",
27+
"fields": [
28+
{
29+
"path": "firstName",
30+
"bsonType": "string",
31+
"keyId": {
32+
"$binary": {
33+
"subType": "04",
34+
"base64": "AAAAAAAAAAAAAAAAAAAAAA=="
35+
}
36+
}
37+
}
38+
]
39+
}
40+
}
41+
}
42+
},
43+
"operations": [
44+
{
45+
"name": "dropCollection",
46+
"object": "database",
47+
"arguments": {
48+
"collection": "encryptedCollection"
49+
}
50+
},
51+
{
52+
"name": "createCollection",
53+
"object": "database",
54+
"arguments": {
55+
"collection": "encryptedCollection"
56+
},
57+
"result": {
58+
"errorContains": "Driver support of Queryable Encryption is incompatible with server. Upgrade server to use Queryable Encryption."
59+
}
60+
}
61+
]
62+
}
63+
]
64+
}

0 commit comments

Comments
 (0)