11#include "mongocrypt.h"
22
33#include "mongocrypt-util-private.h"
4+ #include "test-mongocrypt-assert.h"
45#include "test-mongocrypt.h"
56
67static mongocrypt_t * get_test_mongocrypt (_mongocrypt_tester_t * tester ) {
@@ -199,6 +200,31 @@ static void _test_loading_libmongocrypt_fails(_mongocrypt_tester_t *tester) {
199200 mongocrypt_destroy (crypt );
200201}
201202
203+ static void _test_error_includes_version (_mongocrypt_tester_t * tester ) {
204+ if (!TEST_MONGOCRYPT_HAVE_REAL_CRYPT_SHARED_LIB ) {
205+ TEST_STDERR_PRINTF ("No 'real' csfle library is available. The %s test is a no-op.\n" , BSON_FUNC );
206+ return ;
207+ }
208+
209+ mongocrypt_t * crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_WITH_CRYPT_SHARED_LIB );
210+ const char * version_str = crypt -> csfle .get_version_str ();
211+ // Strip leading mongo_crypt_v1-dev-
212+ if (strstr (version_str , "mongo_crypt_v1-dev-" ) == version_str ) {
213+ version_str += strlen ("mongo_crypt_v1-dev-" );
214+ }
215+
216+ mongocrypt_ctx_t * ctx = mongocrypt_ctx_new (crypt );
217+ mongocrypt_binary_t * cmd = TEST_BSON (BSON_STR ({"insert" : "test ", " bad_field " : 1}));
218+ ASSERT_OK (mongocrypt_ctx_encrypt_init (ctx , "db" , -1 , cmd ), ctx );
219+ ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx ), MONGOCRYPT_CTX_NEED_MONGO_COLLINFO );
220+ ASSERT_OK (mongocrypt_ctx_mongo_feed (ctx , TEST_FILE ("./test/example/collection-info.json" )), ctx );
221+ char * pattern = bson_strdup_printf ("[crypt_shared %s] \"analyze_query\" failed" , version_str );
222+ ASSERT_FAILS (mongocrypt_ctx_mongo_done (ctx ), ctx , pattern );
223+ bson_free (pattern );
224+ mongocrypt_ctx_destroy (ctx );
225+ mongocrypt_destroy (crypt );
226+ }
227+
202228void _mongocrypt_tester_install_csfle_lib (_mongocrypt_tester_t * tester ) {
203229 INSTALL_TEST (_test_csfle_no_paths );
204230 INSTALL_TEST (_test_csfle_not_found );
@@ -212,4 +238,5 @@ void _mongocrypt_tester_install_csfle_lib(_mongocrypt_tester_t *tester) {
212238 INSTALL_TEST (_test_override_error_includes_reason );
213239 INSTALL_TEST (_test_lookup_version_check );
214240 INSTALL_TEST (_test_loading_libmongocrypt_fails );
241+ INSTALL_TEST (_test_error_includes_version );
215242}
0 commit comments