@@ -427,6 +427,33 @@ static void _test_create_datakey_with_retry(_mongocrypt_tester_t *tester) {
427
427
mongocrypt_destroy (crypt );
428
428
}
429
429
430
+ // Test that an HTTP error is retried in-place.
431
+ {
432
+ mongocrypt_t * crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT );
433
+ mongocrypt_ctx_t * ctx = mongocrypt_ctx_new (crypt );
434
+ ASSERT_OK (
435
+ mongocrypt_ctx_setopt_key_encryption_key (ctx ,
436
+ TEST_BSON ("{'provider': 'aws', 'key': 'foo', 'region': 'bar'}" )),
437
+ ctx );
438
+ ASSERT_OK (mongocrypt_ctx_datakey_init (ctx ), ctx );
439
+ ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx ), MONGOCRYPT_CTX_NEED_KMS );
440
+ mongocrypt_kms_ctx_t * kms_ctx = mongocrypt_ctx_next_kms_ctx (ctx );
441
+ ASSERT_OK (kms_ctx , ctx );
442
+ // Expect no sleep is requested before any error.
443
+ ASSERT_CMPINT64 (mongocrypt_kms_ctx_usleep (kms_ctx ), = = , 0 );
444
+ // Feed a retryable HTTP error.
445
+ ASSERT_OK (mongocrypt_kms_ctx_feed (kms_ctx , TEST_FILE ("./test/data/rmd/kms-decrypt-reply-429.txt" )), kms_ctx );
446
+ // In-place retry is indicated.
447
+ ASSERT (mongocrypt_kms_ctx_should_retry_http (kms_ctx ));
448
+ mongocrypt_kms_ctx_reset (kms_ctx );
449
+ // Feed a successful response.
450
+ ASSERT_OK (mongocrypt_kms_ctx_feed (kms_ctx , TEST_FILE ("./test/data/kms-aws/encrypt-response.txt" )), kms_ctx );
451
+ ASSERT_OK (mongocrypt_ctx_kms_done (ctx ), ctx );
452
+ _mongocrypt_tester_run_ctx_to (tester , ctx , MONGOCRYPT_CTX_DONE );
453
+ mongocrypt_ctx_destroy (ctx );
454
+ mongocrypt_destroy (crypt );
455
+ }
456
+
430
457
// Test that a network error is retried.
431
458
{
432
459
mongocrypt_t * crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT );
@@ -454,6 +481,32 @@ static void _test_create_datakey_with_retry(_mongocrypt_tester_t *tester) {
454
481
mongocrypt_destroy (crypt );
455
482
}
456
483
484
+ // Test that a network error is retried in-place.
485
+ {
486
+ mongocrypt_t * crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT );
487
+ mongocrypt_ctx_t * ctx = mongocrypt_ctx_new (crypt );
488
+ ASSERT_OK (
489
+ mongocrypt_ctx_setopt_key_encryption_key (ctx ,
490
+ TEST_BSON ("{'provider': 'aws', 'key': 'foo', 'region': 'bar'}" )),
491
+ ctx );
492
+ ASSERT_OK (mongocrypt_ctx_datakey_init (ctx ), ctx );
493
+ ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx ), MONGOCRYPT_CTX_NEED_KMS );
494
+ mongocrypt_kms_ctx_t * kms_ctx = mongocrypt_ctx_next_kms_ctx (ctx );
495
+ ASSERT_OK (kms_ctx , ctx );
496
+ // Expect no sleep is requested before any error.
497
+ ASSERT_CMPINT64 (mongocrypt_kms_ctx_usleep (kms_ctx ), = = , 0 );
498
+ // Feed part of a response
499
+ ASSERT_OK (mongocrypt_kms_ctx_feed (kms_ctx , TEST_FILE ("./test/data/kms-aws/encrypt-response-partial.txt" )), kms_ctx );
500
+ // Assume a network error and reset the context.
501
+ mongocrypt_kms_ctx_reset (kms_ctx );
502
+ // Feed a successful response.
503
+ ASSERT_OK (mongocrypt_kms_ctx_feed (kms_ctx , TEST_FILE ("./test/data/kms-aws/encrypt-response.txt" )), kms_ctx );
504
+ ASSERT_OK (mongocrypt_ctx_kms_done (ctx ), ctx );
505
+ _mongocrypt_tester_run_ctx_to (tester , ctx , MONGOCRYPT_CTX_DONE );
506
+ mongocrypt_ctx_destroy (ctx );
507
+ mongocrypt_destroy (crypt );
508
+ }
509
+
457
510
// Test that an oauth request is retried for a network error.
458
511
{
459
512
mongocrypt_t * crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT );
0 commit comments