Skip to content

Commit 46213b6

Browse files
committed
encrypt retry test
1 parent aa0397a commit 46213b6

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

test/test-mongocrypt-ctx-rewrap-many-datakey.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,28 @@ static void _test_rewrap_many_datakey_need_kms_retry(_mongocrypt_tester_t *teste
570570
ASSERT(mongocrypt_kms_ctx_bytes_needed(kms) == 0);
571571
ASSERT_OK(mongocrypt_ctx_kms_done(ctx), ctx);
572572
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_KMS); // To encrypt.
573+
mongocrypt_ctx_destroy(ctx);
574+
575+
/* Clear key cache. */
576+
mongocrypt_destroy(crypt);
577+
crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
578+
579+
/* Ensure KMS encrypt requests retry for network errors */
580+
ctx = mongocrypt_ctx_new(crypt);
581+
ASSERT_OK(mongocrypt_ctx_rewrap_many_datakey_init(ctx, filter), ctx);
582+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
583+
ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/data/rmd/key-document-a.json")), ctx);
584+
ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
585+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_KMS); // To decrypt.
586+
ASSERT((kms = mongocrypt_ctx_next_kms_ctx(ctx)));
587+
ASSERT_OK(mongocrypt_kms_ctx_feed(kms, TEST_FILE("./test/data/rmd/kms-decrypt-reply-a.txt")), kms);
588+
ASSERT(mongocrypt_kms_ctx_bytes_needed(kms) == 0);
589+
ASSERT_OK(mongocrypt_ctx_kms_done(ctx), ctx);
590+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_KMS); // To encrypt.
591+
ASSERT((kms = mongocrypt_ctx_next_kms_ctx(ctx)));
592+
ASSERT(mongocrypt_kms_ctx_fail(kms)); // Simulate driver-side network failure for an encrypt request.
593+
ASSERT((kms = mongocrypt_ctx_next_kms_ctx(ctx))); // Assert fails. Expected KMS request to retry but did not.
594+
573595
mongocrypt_ctx_destroy(ctx);
574596
mongocrypt_destroy(crypt);
575597
}

0 commit comments

Comments
 (0)