Skip to content

Commit

Permalink
MONGOCRYPT-771 Remove check for $jsonSchema siblings (#948)
Browse files Browse the repository at this point in the history
* remove check for `$jsonSchema` siblings

* update test

* remove `_test_encrypt_dupe_jsonschema`

Remove the test. A `validator` with duplicate fields on the server is not expected.
  • Loading branch information
kevinAlbs authored Feb 4, 2025
1 parent ecb7614 commit cf89a08
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 37 deletions.
12 changes: 1 addition & 11 deletions src/mongocrypt-ctx-encrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,7 @@ static bool _set_schema_from_collinfo(mongocrypt_ctx_t *ctx, bson_t *collinfo) {
return _mongocrypt_ctx_fail_w_msg(ctx, "malformed $jsonSchema");
}
found_jsonschema = true;
} else {
ectx->collinfo_has_siblings = true;
break;
}
}
}
Expand Down Expand Up @@ -800,15 +799,6 @@ static bool _mongo_feed_markings(mongocrypt_ctx_t *ctx, mongocrypt_binary_t *in)
"local schema used but does not have encryption specifiers");
}
return true;
} else {
/* if the schema requires encryption, but has sibling validators, error.
*/
if (ectx->collinfo_has_siblings) {
return _mongocrypt_ctx_fail_w_msg(ctx,
"schema requires encryption, "
"but collection JSON schema "
"validator has siblings");
}
}

if (bson_iter_init_find(&iter, &as_bson, "hasEncryptedPlaceholders") && !bson_iter_as_bool(&iter)) {
Expand Down
3 changes: 0 additions & 3 deletions src/mongocrypt-ctx-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,6 @@ typedef struct {
_mongocrypt_buffer_t encrypted_cmd;
_mongocrypt_buffer_t key_id;
bool used_local_schema;
/* collinfo_has_siblings is true if the schema came from a remote JSON
* schema, and there were siblings. */
bool collinfo_has_siblings;
/* encrypted_field_config is set when:
* 1. `target_ns` is present in an encrypted_field_config_map.
* 2. (TODO MONGOCRYPT-414) The collection has encryptedFields in the
Expand Down
25 changes: 2 additions & 23 deletions test/test-mongocrypt-ctx-encrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1004,28 +1004,8 @@ static void _test_encrypt_invalid_siblings(_mongocrypt_tester_t *tester) {
ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);

BSON_ASSERT(MONGOCRYPT_CTX_NEED_MONGO_MARKINGS == mongocrypt_ctx_state(ctx));
ASSERT_FAILS(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/example/mongocryptd-reply.json")),
ctx,
"JSON schema validator has siblings");

mongocrypt_ctx_destroy(ctx);
mongocrypt_destroy(crypt);
}

static void _test_encrypt_dupe_jsonschema(_mongocrypt_tester_t *tester) {
mongocrypt_t *crypt;
mongocrypt_ctx_t *ctx;

crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
ctx = mongocrypt_ctx_new(crypt);
ASSERT_OK(mongocrypt_ctx_encrypt_init(ctx, "test", -1, TEST_FILE("./test/example/cmd.json")), ctx);

BSON_ASSERT(MONGOCRYPT_CTX_NEED_MONGO_COLLINFO == mongocrypt_ctx_state(ctx));
ASSERT_FAILS(mongocrypt_ctx_mongo_feed(ctx,
TEST_BSON("{'options': {'validator': { '$jsonSchema': {}, "
"'$jsonSchema': {} } } }")),
ctx,
"duplicate $jsonSchema");
// MONGOCRYPT-771 removes checks for sibling validators.
ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/example/mongocryptd-reply.json")), ctx);

mongocrypt_ctx_destroy(ctx);
mongocrypt_destroy(crypt);
Expand Down Expand Up @@ -4690,7 +4670,6 @@ void _mongocrypt_tester_install_ctx_encrypt(_mongocrypt_tester_t *tester) {
INSTALL_TEST(_test_encrypt_is_remote_schema);
INSTALL_TEST(_test_encrypt_init_each_cmd);
INSTALL_TEST(_test_encrypt_invalid_siblings);
INSTALL_TEST(_test_encrypt_dupe_jsonschema);
INSTALL_TEST(_test_encrypting_with_explicit_encryption);
INSTALL_TEST(_test_explicit_encryption);
INSTALL_TEST(_test_encrypt_empty_aws);
Expand Down

0 comments on commit cf89a08

Please sign in to comment.