Skip to content

Commit 0030d8b

Browse files
rcsanchez97kevinAlbs
authored andcommitted
CDRIVER-3762 use allow_invalid_hostname in test to work around buggy comparison
1 parent 579a31d commit 0030d8b

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2101,21 +2101,47 @@ _test_mongoc_client_ipv6 (bool pooled)
21012101
mongoc_uri_t *uri;
21022102
mongoc_client_pool_t *pool = NULL;
21032103
mongoc_client_t *client;
2104+
#if (defined(__APPLE__) || defined(_WIN32)) && defined(MONGOC_ENABLE_SSL)
2105+
mongoc_ssl_opt_t ssl_opts;
2106+
#endif
21042107
bson_error_t error;
21052108

21062109
uri_str = test_framework_add_user_password_from_env ("mongodb://[::1]/");
21072110
uri = mongoc_uri_new (uri_str);
21082111
BSON_ASSERT (uri);
21092112

2113+
#if (defined(__APPLE__) || defined(_WIN32)) && defined(MONGOC_ENABLE_SSL)
2114+
/* This is necessary because macOS & Windows seem to treat [::1] as not
2115+
* matching the hostname "0:0:0:0:0:0:0:1", which results in a certificate
2116+
* trust failure. This behavior has been captured in CDRIVER-3765 (macOS)
2117+
* and CDRIVER-3766 (Windows). When those are fixed, the code in this
2118+
* function should be restored to its previous state without the use of
2119+
* ssl_opts.allow_invalid_hostname. */
2120+
ssl_opts = *test_framework_get_ssl_opts ();
2121+
ssl_opts.allow_invalid_hostname = true;
2122+
#endif
2123+
21102124
if (pooled) {
21112125
pool = mongoc_client_pool_new (uri);
2126+
#if (defined(__APPLE__) || defined(_WIN32)) && defined(MONGOC_ENABLE_SSL)
2127+
mongoc_client_pool_set_ssl_opts (pool, &ssl_opts);
2128+
#else
21122129
test_framework_set_pool_ssl_opts (pool);
2130+
#endif
21132131
client = mongoc_client_pool_pop (pool);
21142132
} else {
21152133
client = mongoc_client_new_from_uri (uri);
2134+
#if (defined(__APPLE__) || defined(_WIN32)) && defined(MONGOC_ENABLE_SSL)
2135+
mongoc_client_set_ssl_opts (client, &ssl_opts);
2136+
#else
21162137
test_framework_set_ssl_opts (client);
2138+
#endif
21172139
}
21182140

2141+
#if (defined(__APPLE__) || defined(_WIN32)) && defined(MONGOC_ENABLE_SSL)
2142+
BSON_ASSERT (client->ssl_opts.allow_invalid_hostname);
2143+
#endif
2144+
21192145
ASSERT_OR_PRINT (
21202146
mongoc_client_read_command_with_opts (
21212147
client, "admin", tmp_bson ("{'ping': 1}"), NULL, NULL, NULL, &error),

0 commit comments

Comments
 (0)