Skip to content

Commit 38e3093

Browse files
authored
CDRIVER-6104 Update CSE prose tests for libmongocrypt 1.17 (#2153)
1 parent b498496 commit 38e3093

File tree

4 files changed

+123
-1
lines changed

4 files changed

+123
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"bsonType": "object"
3+
}

src/libmongoc/tests/test-libmongoc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2268,6 +2268,8 @@ WIRE_VERSION_CHECKS(24)
22682268
WIRE_VERSION_CHECKS(25)
22692269
/* wire version 26 begins with the 8.1 release. */
22702270
WIRE_VERSION_CHECKS(26)
2271+
/* wire version 27 begins with the 8.2 release. */
2272+
WIRE_VERSION_CHECKS(27)
22712273

22722274
int
22732275
test_framework_skip_if_no_dual_ip_hostname(void)

src/libmongoc/tests/test-libmongoc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ WIRE_VERSION_CHECK_DECLS(24)
214214
WIRE_VERSION_CHECK_DECLS(25)
215215
/* wire version 26 begins with the 8.1 release. */
216216
WIRE_VERSION_CHECK_DECLS(26)
217+
/* wire version 27 begins with the 8.2 release. */
218+
WIRE_VERSION_CHECK_DECLS(27)
217219

218220
#undef WIRE_VERSION_CHECK_DECLS
219221

src/libmongoc/tests/test-mongoc-client-side-encryption.c

Lines changed: 116 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
#include <mongoc/mongoc-error-private.h>
3434
#include <mongoc/mongoc-http-private.h>
3535

36+
/* _mongoc_crypt_get_libmongocrypt_version */
37+
#include <mongoc/mongoc-crypt-private.h>
38+
3639
#include <mongoc/mongoc-uri.h>
3740

3841
#include <mlib/cmp.h>
@@ -6522,6 +6525,16 @@ drop_coll(mongoc_database_t *db, const char *collname)
65226525
mongoc_collection_destroy(coll);
65236526
}
65246527

6528+
server_version_t
6529+
get_libmongocrypt_version(void)
6530+
{
6531+
#ifdef MONGOC_ENABLE_CLIENT_SIDE_ENCRYPTION
6532+
return test_framework_str_to_version(_mongoc_crypt_get_libmongocrypt_version());
6533+
#else
6534+
return 0;
6535+
#endif
6536+
}
6537+
65256538
static void
65266539
test_lookup_setup(void)
65276540
{
@@ -6619,6 +6632,19 @@ test_lookup_setup(void)
66196632
mongoc_collection_destroy(coll);
66206633
}
66216634

6635+
// Create db.non_csfle_schema:
6636+
{
6637+
drop_coll(db, "non_csfle_schema");
6638+
bson_t *const schema = get_bson_from_json_file(TESTDIR "schema-non-csfle.json");
6639+
bson_t *const create_opts = BCON_NEW("validator", "{", "$jsonSchema", BCON_DOCUMENT(schema), "}");
6640+
mongoc_collection_t *const coll =
6641+
mongoc_database_create_collection(db, "non_csfle_schema", create_opts, &error);
6642+
ASSERT_OR_PRINT(coll, error);
6643+
mongoc_collection_destroy(coll);
6644+
bson_destroy(create_opts);
6645+
bson_destroy(schema);
6646+
}
6647+
66226648
mongoc_database_destroy(db);
66236649
}
66246650
#undef TESTDIR
@@ -6699,6 +6725,20 @@ test_lookup_setup(void)
66996725
mongoc_collection_destroy(coll_unencrypted);
67006726
}
67016727

6728+
// Insert to db.non_csfle_schema
6729+
{
6730+
mongoc_collection_t *const coll = mongoc_client_get_collection(client, "db", "non_csfle_schema");
6731+
ok = mongoc_collection_insert_one(
6732+
coll, MAKE_BSON({"non_csfle_schema" : "non_csfle_schema"}), NULL, NULL, &error);
6733+
ASSERT_OR_PRINT(ok, error);
6734+
mongoc_collection_destroy(coll);
6735+
// Find document with unencrypted client to check it is not encrypted.
6736+
mongoc_collection_t *const coll_unencrypted =
6737+
mongoc_client_get_collection(setup_client, "db", "non_csfle_schema");
6738+
ASSERT_COLL_MATCHES_ONE(coll_unencrypted, MAKE_BSON({"non_csfle_schema" : "non_csfle_schema"}));
6739+
mongoc_collection_destroy(coll_unencrypted);
6740+
}
6741+
67026742
mongoc_client_destroy(client);
67036743
}
67046744

@@ -6909,7 +6949,67 @@ test_lookup(void *unused)
69096949
]
69106950
});
69116951

6912-
ASSERT_AGG_ERROR(coll, pipeline, "not supported");
6952+
if (test_framework_get_server_version() < test_framework_str_to_version("8.2.0") ||
6953+
get_libmongocrypt_version() < test_framework_str_to_version("1.17.0")) {
6954+
ASSERT_AGG_ERROR(coll, pipeline, "not supported");
6955+
} else {
6956+
// The error domain differs depending on the query analysis component:
6957+
// * `crypt_shared`: `MONGOC_ERROR_CLIENT_SIDE_ENCRYPTION`
6958+
// * `mongocryptd`: `MONGOC_ERROR_QUERY`
6959+
6960+
static const char *const expected_error_substring =
6961+
"Cannot specify both encryptionInformation and csfleEncryptionSchemas unless csfleEncryptionSchemas only "
6962+
"contains non-encryption JSON schema validators";
6963+
6964+
if (mongoc_client_get_crypt_shared_version(client)) {
6965+
ASSERT_AGG_ERROR(coll, pipeline, expected_error_substring);
6966+
} else {
6967+
mongoc_cursor_t *const cursor = mongoc_collection_aggregate(coll, 0, pipeline, NULL, NULL);
6968+
const bson_t *got;
6969+
ASSERT(!mongoc_cursor_next(cursor, &got));
6970+
ASSERT(mongoc_cursor_error(cursor, &error));
6971+
static const uint32_t expected_error_code = 10026002u;
6972+
ASSERT_ERROR_CONTAINS(error, MONGOC_ERROR_QUERY, expected_error_code, expected_error_substring);
6973+
mongoc_cursor_destroy(cursor);
6974+
}
6975+
}
6976+
6977+
mongoc_collection_destroy(coll);
6978+
mongoc_client_destroy(client);
6979+
}
6980+
}
6981+
6982+
static void
6983+
test_lookup_post82(void *unused)
6984+
{
6985+
BSON_UNUSED(unused);
6986+
test_lookup_setup();
6987+
bson_error_t error;
6988+
6989+
// Case 10: db.qe joins db.non_csfle_schema:
6990+
{
6991+
mongoc_client_t *const client = create_encrypted_client();
6992+
mongoc_collection_t *const coll = mongoc_client_get_collection(client, "db", "qe");
6993+
6994+
bson_t *const pipeline = MAKE_BSON({
6995+
"pipeline" : [
6996+
{"$match" : {"qe" : "qe"}},
6997+
{
6998+
"$lookup" : {
6999+
"from" : "non_csfle_schema",
7000+
"as" : "matched",
7001+
"pipeline" : [
7002+
{"$match" : {"non_csfle_schema" : "non_csfle_schema"}},
7003+
{"$project" : {"_id" : 0, "__safeContent__" : 0}}
7004+
]
7005+
}
7006+
},
7007+
{"$project" : {"_id" : 0, "__safeContent__" : 0}}
7008+
]
7009+
});
7010+
7011+
bson_t *const expect = MAKE_BSON({"qe" : "qe", "matched" : [ {"non_csfle_schema" : "non_csfle_schema"} ]});
7012+
ASSERT_AGG_RETURNS_ONE(coll, pipeline, expect);
69137013
mongoc_collection_destroy(coll);
69147014
mongoc_client_destroy(client);
69157015
}
@@ -6947,6 +7047,12 @@ test_lookup_pre81(void *unused)
69477047
}
69487048
}
69497049

7050+
int
7051+
skip_if_libmongocrypt_less_than_1_17_0(void)
7052+
{
7053+
return get_libmongocrypt_version() >= test_framework_str_to_version("1.17.0");
7054+
}
7055+
69507056
void
69517057
test_client_side_encryption_install(TestSuite *suite)
69527058
{
@@ -7388,6 +7494,15 @@ test_client_side_encryption_install(TestSuite *suite)
73887494
test_framework_skip_if_max_wire_version_less_than_26 /* require server 8.1+ */,
73897495
test_framework_skip_if_single, /* QE not supported on standalone */
73907496
test_framework_skip_if_no_client_side_encryption);
7497+
TestSuite_AddFull(suite,
7498+
"/client_side_encryption/test_lookup/post-8.2",
7499+
test_lookup_post82,
7500+
NULL,
7501+
NULL,
7502+
test_framework_skip_if_max_wire_version_less_than_27, /* require server 8.2+ */
7503+
skip_if_libmongocrypt_less_than_1_17_0, /* require libmongocrypt 1.17.0+ */
7504+
test_framework_skip_if_single, /* QE not supported on standalone */
7505+
test_framework_skip_if_no_client_side_encryption);
73917506
TestSuite_AddFull(suite,
73927507
"/client_side_encryption/test_lookup/pre-8.1",
73937508
test_lookup_pre81,

0 commit comments

Comments
 (0)