Skip to content

Commit fc243b9

Browse files
authored
CDRIVER-4656 check if server is running with TLS in tests (#1702)
* CDRIVER-4656 skip test if server is not started with TLS * add `test_framework_skip_if_no_server_ssl`
1 parent 35f3880 commit fc243b9

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

src/libmongoc/tests/test-libmongoc.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2624,3 +2624,12 @@ test_framework_is_loadbalanced (void)
26242624
return test_framework_getenv_bool ("MONGOC_TEST_LOADBALANCED") ||
26252625
test_framework_getenv_bool ("MONGOC_TEST_DNS_LOADBALANCED");
26262626
}
2627+
2628+
int
2629+
test_framework_skip_if_no_server_ssl (void)
2630+
{
2631+
if (test_framework_get_ssl ()) {
2632+
return 1; // Proceed.
2633+
}
2634+
return 0; // Skip.
2635+
}

src/libmongoc/tests/test-libmongoc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,8 @@ test_framework_skip_if_serverless (void);
284284
bool
285285
test_framework_is_loadbalanced (void);
286286

287+
// `test_framework_skip_if_no_server_ssl` skips if test runner was not told to connect to the server with SSL.
288+
int
289+
test_framework_skip_if_no_server_ssl (void);
290+
287291
#endif

src/libmongoc/tests/test-mongoc-client.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2222,8 +2222,9 @@ test_client_buildinfo_hang (void)
22222222
#if defined(MONGOC_ENABLE_SSL_OPENSSL)
22232223

22242224
static void
2225-
test_mongoc_client_change_openssl_ctx_before_ops (void)
2225+
test_mongoc_client_change_openssl_ctx_before_ops (void *unused)
22262226
{
2227+
BSON_UNUSED (unused);
22272228
mongoc_client_t *client;
22282229
const mongoc_ssl_opt_t *ssl_opts;
22292230
bson_error_t error;
@@ -2243,8 +2244,9 @@ test_mongoc_client_change_openssl_ctx_before_ops (void)
22432244
}
22442245

22452246
static void
2246-
test_mongoc_client_change_openssl_ctx_between_ops (void)
2247+
test_mongoc_client_change_openssl_ctx_between_ops (void *unused)
22472248
{
2249+
BSON_UNUSED (unused);
22482250
mongoc_client_t *client;
22492251
const mongoc_ssl_opt_t *ssl_opts;
22502252
bson_error_t error;
@@ -4139,9 +4141,17 @@ test_client_install (TestSuite *suite)
41394141
suite, "/Client/resends_handshake_on_network_error", test_mongoc_client_resends_handshake_on_network_error);
41404142
TestSuite_Add (suite, "/Client/failure_to_auth", test_failure_to_auth);
41414143
#if defined(MONGOC_ENABLE_SSL_OPENSSL)
4142-
TestSuite_Add (
4143-
suite, "/Client/openssl/change_ssl_opts_before_ops", test_mongoc_client_change_openssl_ctx_before_ops);
4144-
TestSuite_Add (
4145-
suite, "/Client/openssl/change_ssl_opts_after_ops", test_mongoc_client_change_openssl_ctx_between_ops);
4144+
TestSuite_AddFull (suite,
4145+
"/Client/openssl/change_ssl_opts_before_ops",
4146+
test_mongoc_client_change_openssl_ctx_before_ops,
4147+
NULL,
4148+
NULL,
4149+
test_framework_skip_if_no_server_ssl);
4150+
TestSuite_AddFull (suite,
4151+
"/Client/openssl/change_ssl_opts_after_ops",
4152+
test_mongoc_client_change_openssl_ctx_between_ops,
4153+
NULL,
4154+
NULL,
4155+
test_framework_skip_if_no_server_ssl);
41464156
#endif
41474157
}

0 commit comments

Comments
 (0)