Skip to content

CDRIVER-4515 Add prose test to not spawn mongocrypt if shared library is loaded #1149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/libmongoc/tests/test-mongoc-client-side-encryption.c
Original file line number Diff line number Diff line change
Expand Up @@ -2675,13 +2675,27 @@ test_bypass_spawning_via_helper (const char *auto_encryption_opt)
mongoc_auto_encryption_opts_set_bypass_query_analysis (
auto_encryption_opts, true);
} else if (0 == strcmp (auto_encryption_opt, "cryptSharedLibRequired")) {
bson_t *schema =
get_bson_from_json_file ("./src/libmongoc/tests/"
"client_side_encryption_prose/external/"
"external-schema.json");
BSON_ASSERT (schema);
bson_t *schema_map = BCON_NEW ("db.coll", BCON_DOCUMENT (schema));
mongoc_auto_encryption_opts_set_schema_map (auto_encryption_opts,
schema_map);
check_crypt_shared = true;
char *env_cryptSharedLibPath =
test_framework_getenv ("MONGOC_TEST_CRYPT_SHARED_LIB_PATH");
BSON_ASSERT (env_cryptSharedLibPath);
BSON_APPEND_UTF8 (extra, "cryptSharedLibPath", env_cryptSharedLibPath);
BSON_APPEND_BOOL (extra, "cryptSharedLibRequired", true);
BSON_APPEND_UTF8 (
extra,
"mongocryptdURI",
"mongodb://localhost:27021/db?serverSelectionTimeoutMS=1000");
bson_free (env_cryptSharedLibPath);
bson_destroy (schema);
bson_destroy (schema_map);
} else {
test_error ("Unexpected 'auto_encryption_opt' argument: %s",
auto_encryption_opt);
Expand All @@ -2706,7 +2720,7 @@ test_bypass_spawning_via_helper (const char *auto_encryption_opt)
NULL);
}

/* Insert { 'encrypt': 'test' }. Should succeed. */
/* Insert { 'unencrypted': 'test' }. Should succeed. */
coll = mongoc_client_get_collection (client_encrypted, "db", "coll");
doc_to_insert = BCON_NEW ("unencrypted", "test");
ret = mongoc_collection_insert_one (
Expand Down Expand Up @@ -2740,8 +2754,9 @@ test_bypass_spawning_via_bypassQueryAnalysis (void *unused)
test_bypass_spawning_via_helper ("bypass_query_analysis");
}

/* Prose Test 8: Bypass Spawning mongocryptd - Via loading shared library */
static void
test_bypass_spawning_via_cryptSharedLibRequired (void *unused)
test_bypass_spawning_via_cryptSharedLibLoaded (void *unused)
{
BSON_UNUSED (unused);
test_bypass_spawning_via_helper ("cryptSharedLibRequired");
Expand Down Expand Up @@ -5773,8 +5788,8 @@ test_client_side_encryption_install (TestSuite *suite)
test_framework_skip_if_max_wire_version_less_than_8);
TestSuite_AddFull (suite,
"/client_side_encryption/bypass_spawning_mongocryptd/"
"cryptSharedLibRequired",
test_bypass_spawning_via_cryptSharedLibRequired,
"cryptSharedLibLoaded",
test_bypass_spawning_via_cryptSharedLibLoaded,
NULL,
NULL,
test_framework_skip_if_no_client_side_encryption,
Expand Down