Skip to content

Commit 6b00083

Browse files
authored
MONGOCRYPT-770 do not warn if local schema does not require encryption (#947)
* add regression test * remove warning
1 parent cf89a08 commit 6b00083

File tree

2 files changed

+54
-7
lines changed

2 files changed

+54
-7
lines changed

src/mongocrypt-ctx-encrypt.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -791,13 +791,7 @@ static bool _mongo_feed_markings(mongocrypt_ctx_t *ctx, mongocrypt_binary_t *in)
791791

792792
if (bson_iter_init_find(&iter, &as_bson, "schemaRequiresEncryption") && !bson_iter_as_bool(&iter)) {
793793
/* TODO: update cache: this schema does not require encryption. */
794-
795-
/* If using a local schema, warn if there are no encrypted fields. */
796-
if (ectx->used_local_schema) {
797-
_mongocrypt_log(&ctx->crypt->log,
798-
MONGOCRYPT_LOG_LEVEL_WARNING,
799-
"local schema used but does not have encryption specifiers");
800-
}
794+
// Schema does not require encryption. Skip copying the `result`.
801795
return true;
802796
}
803797

test/test-mongocrypt-ctx-encrypt.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4651,6 +4651,58 @@ static void _test_encrypt_retry(_mongocrypt_tester_t *tester) {
46514651
}
46524652
}
46534653

4654+
static void capture_logs(mongocrypt_log_level_t level, const char *message, uint32_t message_len, void *ctx) {
4655+
mc_array_t *log_msgs = ctx;
4656+
char *message_copy = bson_strdup(message);
4657+
_mc_array_append_val(log_msgs, message_copy);
4658+
}
4659+
4660+
// Regression test for: MONGOCRYPT-770
4661+
static void _test_does_not_warn_for_empty_local_schema(_mongocrypt_tester_t *tester) {
4662+
mongocrypt_t *crypt = mongocrypt_new();
4663+
ASSERT_OK(mongocrypt_setopt_kms_providers(
4664+
crypt,
4665+
TEST_BSON(BSON_STR({"aws" : {"accessKeyId" : "foo", "secretAccessKey" : "bar"}}))),
4666+
crypt);
4667+
4668+
mc_array_t log_msgs; // Array of char *;
4669+
_mc_array_init(&log_msgs, sizeof(char *));
4670+
ASSERT_OK(mongocrypt_setopt_log_handler(crypt, capture_logs, &log_msgs), crypt);
4671+
4672+
// Configure a local schema for "db.coll":
4673+
ASSERT_OK(mongocrypt_setopt_schema_map(crypt, TEST_BSON(BSON_STR({"db.coll" : {}}))), crypt);
4674+
4675+
ASSERT_OK(mongocrypt_init(crypt), crypt);
4676+
mongocrypt_ctx_t *ctx = mongocrypt_ctx_new(crypt);
4677+
ASSERT_OK(mongocrypt_ctx_encrypt_init(ctx, "db", -1, TEST_BSON(BSON_STR({"find" : "coll", "filter" : {}}))), ctx);
4678+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_MARKINGS);
4679+
4680+
// Feed mongocryptd reply indicating `schemaRequiresEncryption: false`.
4681+
ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_BSON(BSON_STR({
4682+
"hasEncryptionPlaceholders" : false,
4683+
"schemaRequiresEncryption" : false,
4684+
"result" : {"find" : "test", "filter" : {}},
4685+
"ok" : {"$numberDouble" : "1.0"}
4686+
}))),
4687+
ctx);
4688+
4689+
// Expect no warning (passing an empty local schema is a valid use-case).
4690+
if (log_msgs.len > 0) {
4691+
TEST_STDERR_PRINTF("Got unexpected log messages:\n");
4692+
for (size_t i = 0; i < log_msgs.len; i++) {
4693+
TEST_STDERR_PRINTF("> %s\n", _mc_array_index(&log_msgs, char *, i));
4694+
}
4695+
abort();
4696+
}
4697+
4698+
for (size_t i = 0; i < log_msgs.len; i++) {
4699+
bson_free(_mc_array_index(&log_msgs, char *, i));
4700+
}
4701+
_mc_array_destroy(&log_msgs);
4702+
mongocrypt_ctx_destroy(ctx);
4703+
mongocrypt_destroy(crypt);
4704+
}
4705+
46544706
void _mongocrypt_tester_install_ctx_encrypt(_mongocrypt_tester_t *tester) {
46554707
INSTALL_TEST(_test_explicit_encrypt_init);
46564708
INSTALL_TEST(_test_encrypt_init);
@@ -4733,4 +4785,5 @@ void _mongocrypt_tester_install_ctx_encrypt(_mongocrypt_tester_t *tester) {
47334785
INSTALL_TEST(_test_no_trimFactor);
47344786
INSTALL_TEST(_test_range_sends_cryptoParams);
47354787
INSTALL_TEST(_test_encrypt_retry);
4788+
INSTALL_TEST(_test_does_not_warn_for_empty_local_schema);
47364789
}

0 commit comments

Comments
 (0)