Skip to content

Commit 4ac230f

Browse files
committed
MONGOCRYPT-737 set status if mongocrypt_kms_ctx_fail called with retry disabled (#908)
* add regression test * set error status if `mongocrypt_kms_ctx_fail` is called when retry disabled
1 parent 085a0ce commit 4ac230f

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/mongocrypt-kms-ctx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ static bool _ctx_done_kmip_decrypt(mongocrypt_kms_ctx_t *kms_ctx) {
11211121
}
11221122

11231123
bool mongocrypt_kms_ctx_fail(mongocrypt_kms_ctx_t *kms) {
1124-
if (!kms || !kms->retry_enabled) {
1124+
if (!kms) {
11251125
return false;
11261126
}
11271127

test/test-mongocrypt-ctx-encrypt.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5674,6 +5674,24 @@ static void _test_encrypt_retry(_mongocrypt_tester_t *tester) {
56745674
mongocrypt_ctx_destroy(ctx);
56755675
mongocrypt_destroy(crypt);
56765676
}
5677+
5678+
// Test network retry does not occur if not enabled.
5679+
{
5680+
mongocrypt_t *crypt = mongocrypt_new();
5681+
ASSERT_OK(mongocrypt_setopt_kms_providers(
5682+
crypt,
5683+
TEST_BSON(BSON_STR({"aws" : {"accessKeyId" : "foo", "secretAccessKey" : "bar"}}))),
5684+
crypt);
5685+
ASSERT_OK(mongocrypt_init(crypt), crypt);
5686+
mongocrypt_ctx_t *ctx = mongocrypt_ctx_new(crypt);
5687+
ASSERT_OK(mongocrypt_ctx_encrypt_init(ctx, "test", -1, TEST_FILE("./test/example/cmd.json")), ctx);
5688+
_mongocrypt_tester_run_ctx_to(tester, ctx, MONGOCRYPT_CTX_NEED_KMS);
5689+
mongocrypt_kms_ctx_t *kms_ctx = mongocrypt_ctx_next_kms_ctx(ctx);
5690+
ASSERT_OK(kms_ctx, ctx); // Give a retryable network error. Expect error due to retry disabled.
5691+
ASSERT_FAILS(mongocrypt_kms_ctx_fail(kms_ctx), kms_ctx, "KMS request failed due to network error");
5692+
mongocrypt_ctx_destroy(ctx);
5693+
mongocrypt_destroy(crypt);
5694+
}
56775695
}
56785696

56795697
void _mongocrypt_tester_install_ctx_encrypt(_mongocrypt_tester_t *tester) {

0 commit comments

Comments
 (0)