@@ -4651,6 +4651,58 @@ static void _test_encrypt_retry(_mongocrypt_tester_t *tester) {
4651
4651
}
4652
4652
}
4653
4653
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
+
4654
4706
void _mongocrypt_tester_install_ctx_encrypt (_mongocrypt_tester_t * tester ) {
4655
4707
INSTALL_TEST (_test_explicit_encrypt_init );
4656
4708
INSTALL_TEST (_test_encrypt_init );
@@ -4733,4 +4785,5 @@ void _mongocrypt_tester_install_ctx_encrypt(_mongocrypt_tester_t *tester) {
4733
4785
INSTALL_TEST (_test_no_trimFactor );
4734
4786
INSTALL_TEST (_test_range_sends_cryptoParams );
4735
4787
INSTALL_TEST (_test_encrypt_retry );
4788
+ INSTALL_TEST (_test_does_not_warn_for_empty_local_schema );
4736
4789
}
0 commit comments