@@ -756,6 +756,30 @@ static void _test_encrypt_caches_keys(_mongocrypt_tester_t *tester) {
756
756
mongocrypt_destroy (crypt );
757
757
}
758
758
759
+ static void _test_encrypt_cache_expiration (_mongocrypt_tester_t * tester ) {
760
+ mongocrypt_t * crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_WITH_SHORT_CACHE );
761
+ mongocrypt_ctx_t * ctx = mongocrypt_ctx_new (crypt );
762
+ ASSERT_OK (mongocrypt_ctx_encrypt_init (ctx , "test" , -1 , TEST_FILE ("./test/example/cmd.json" )), ctx );
763
+ _mongocrypt_tester_run_ctx_to (tester , ctx , MONGOCRYPT_CTX_DONE );
764
+ mongocrypt_ctx_destroy (ctx );
765
+
766
+ _usleep (2000 );
767
+ /* The next context requests keys again
768
+ */
769
+ ctx = mongocrypt_ctx_new (crypt );
770
+ ASSERT_OK (mongocrypt_ctx_encrypt_init (ctx , "test" , -1 , TEST_FILE ("./test/example/cmd.json" )), ctx );
771
+ _mongocrypt_tester_run_ctx_to (tester , ctx , MONGOCRYPT_CTX_NEED_MONGO_MARKINGS );
772
+ ASSERT_OK (mongocrypt_ctx_mongo_feed (ctx , TEST_FILE ("./test/example/mongocryptd-reply.json" )), ctx );
773
+ ASSERT_OK (mongocrypt_ctx_mongo_done (ctx ), ctx );
774
+ BSON_ASSERT (mongocrypt_ctx_state (ctx ) == MONGOCRYPT_CTX_NEED_MONGO_KEYS );
775
+ ASSERT_OK (mongocrypt_ctx_mongo_feed (ctx , TEST_FILE ("./test/example/key-document.json" )), ctx );
776
+ ASSERT_OK (mongocrypt_ctx_mongo_done (ctx ), ctx );
777
+ _mongocrypt_tester_run_ctx_to (tester , ctx , MONGOCRYPT_CTX_DONE );
778
+
779
+ mongocrypt_ctx_destroy (ctx );
780
+ mongocrypt_destroy (crypt );
781
+ }
782
+
759
783
static void _test_encrypt_caches_keys_by_alt_name (_mongocrypt_tester_t * tester ) {
760
784
mongocrypt_t * crypt ;
761
785
mongocrypt_ctx_t * ctx ;
@@ -5665,6 +5689,7 @@ void _mongocrypt_tester_install_ctx_encrypt(_mongocrypt_tester_t *tester) {
5665
5689
INSTALL_TEST (_test_local_schema );
5666
5690
INSTALL_TEST (_test_encrypt_caches_collinfo );
5667
5691
INSTALL_TEST (_test_encrypt_caches_keys );
5692
+ INSTALL_TEST (_test_encrypt_cache_expiration );
5668
5693
INSTALL_TEST (_test_encrypt_caches_keys_by_alt_name );
5669
5694
INSTALL_TEST (_test_encrypt_random );
5670
5695
INSTALL_TEST (_test_encrypt_is_remote_schema );
0 commit comments