Skip to content

Commit 3c354f0

Browse files
author
Micah Scott @ MongoDB
authored
CDRIVER-3769 Deprecate unimplemented URI options (#1770)
* Removes maxidletimems and waitqueuemultiple from the schema of allowed int URI options * Tests that maxidletimems and waitqueuemultiple warn as unsupported options * Replaces conflicting spec tests with modified libmongoc-specific versions
1 parent 3df9bee commit 3c354f0

File tree

6 files changed

+143
-65
lines changed

6 files changed

+143
-65
lines changed

src/libmongoc/src/mongoc/mongoc-uri.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -720,9 +720,12 @@ mongoc_uri_option_is_int32 (const char *key)
720720
!strcasecmp (key, MONGOC_URI_SOCKETCHECKINTERVALMS) || !strcasecmp (key, MONGOC_URI_SOCKETTIMEOUTMS) ||
721721
!strcasecmp (key, MONGOC_URI_LOCALTHRESHOLDMS) || !strcasecmp (key, MONGOC_URI_MAXPOOLSIZE) ||
722722
!strcasecmp (key, MONGOC_URI_MAXSTALENESSSECONDS) || !strcasecmp (key, MONGOC_URI_MINPOOLSIZE) ||
723-
!strcasecmp (key, MONGOC_URI_MAXIDLETIMEMS) || !strcasecmp (key, MONGOC_URI_WAITQUEUEMULTIPLE) ||
724723
!strcasecmp (key, MONGOC_URI_WAITQUEUETIMEOUTMS) || !strcasecmp (key, MONGOC_URI_ZLIBCOMPRESSIONLEVEL) ||
725724
!strcasecmp (key, MONGOC_URI_SRVMAXHOSTS);
725+
/* Not including deprecated unimplemented options:
726+
* - MONGOC_URI_MAXIDLETIMEMS
727+
* - MONGOC_URI_WAITQUEUEMULTIPLE
728+
*/
726729
}
727730

728731
bool
@@ -742,7 +745,7 @@ mongoc_uri_option_is_bool (const char *key)
742745
!strcasecmp (key, MONGOC_URI_TLSALLOWINVALIDHOSTNAMES) ||
743746
!strcasecmp (key, MONGOC_URI_TLSDISABLECERTIFICATEREVOCATIONCHECK) ||
744747
!strcasecmp (key, MONGOC_URI_TLSDISABLEOCSPENDPOINTCHECK) || !strcasecmp (key, MONGOC_URI_LOADBALANCED) ||
745-
/* deprecated options */
748+
/* deprecated options with canonical equivalents */
746749
!strcasecmp (key, MONGOC_URI_SSL) || !strcasecmp (key, MONGOC_URI_SSLALLOWINVALIDCERTIFICATES) ||
747750
!strcasecmp (key, MONGOC_URI_SSLALLOWINVALIDHOSTNAMES);
748751
}
@@ -754,7 +757,7 @@ mongoc_uri_option_is_utf8 (const char *key)
754757
!strcasecmp (key, MONGOC_URI_READPREFERENCE) || !strcasecmp (key, MONGOC_URI_SERVERMONITORINGMODE) ||
755758
!strcasecmp (key, MONGOC_URI_SRVSERVICENAME) || !strcasecmp (key, MONGOC_URI_TLSCERTIFICATEKEYFILE) ||
756759
!strcasecmp (key, MONGOC_URI_TLSCERTIFICATEKEYFILEPASSWORD) || !strcasecmp (key, MONGOC_URI_TLSCAFILE) ||
757-
/* deprecated options */
760+
/* deprecated options with canonical equivalents */
758761
!strcasecmp (key, MONGOC_URI_SSLCLIENTCERTIFICATEKEYFILE) ||
759762
!strcasecmp (key, MONGOC_URI_SSLCLIENTCERTIFICATEKEYPASSWORD) ||
760763
!strcasecmp (key, MONGOC_URI_SSLCERTIFICATEAUTHORITYFILE);

src/libmongoc/tests/json-test.c

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,21 +1716,8 @@ run_json_general_test (const json_test_config_t *config)
17161716
continue;
17171717
}
17181718

1719-
if (config->skips) {
1720-
test_skip_t *iter;
1721-
bool should_skip = false;
1722-
1723-
for (iter = config->skips; iter->description != NULL; iter++) {
1724-
if (0 == strcmp (description, iter->description)) {
1725-
should_skip = true;
1726-
break;
1727-
}
1728-
}
1729-
1730-
if (should_skip) {
1731-
fprintf (stderr, " - %s SKIPPED, due to reason: %s\n", description, iter->reason);
1732-
continue;
1733-
}
1719+
if (test_should_be_skipped (config->skips, description)) {
1720+
continue;
17341721
}
17351722

17361723
uri = (config->uri_str != NULL) ? mongoc_uri_new (config->uri_str) : test_framework_get_uri ();
@@ -1980,3 +1967,30 @@ install_json_test_suite (TestSuite *suite, const char *base, const char *subdir,
19801967
{
19811968
install_json_test_suite_with_check (suite, base, subdir, callback, TestSuite_CheckLive);
19821969
}
1970+
1971+
1972+
/*
1973+
*-----------------------------------------------------------------------
1974+
*
1975+
* test_should_be_skipped --
1976+
*
1977+
* Check a test description string against a list of description strings for
1978+
* tests that should be skipped. "skips" is an optional NULL terminated array.
1979+
*
1980+
* If the test should be skipped, returns 'true' and logs a reason to stderr.
1981+
*
1982+
*-----------------------------------------------------------------------
1983+
*/
1984+
bool
1985+
test_should_be_skipped (const test_skip_t *skips, const char *description)
1986+
{
1987+
if (skips) {
1988+
for (const test_skip_t *iter = skips; iter->description != NULL; iter++) {
1989+
if (0 == strcmp (description, iter->description)) {
1990+
fprintf (stderr, " - %s SKIPPED, due to reason: %s\n", description, iter->reason);
1991+
return true;
1992+
}
1993+
}
1994+
}
1995+
return false;
1996+
}

src/libmongoc/tests/json-test.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,7 @@ check_scenario_version (const bson_t *scenario);
115115
void
116116
check_outcome_collection (mongoc_collection_t *collection, bson_t *test);
117117

118+
bool
119+
test_should_be_skipped (const test_skip_t *skips, const char *description);
120+
118121
#endif

src/libmongoc/tests/json/connection_uri/additional-nonspec-tests.json

Lines changed: 56 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@
4949
],
5050
"auth": null,
5151
"options": {
52-
"authmechanismproperties": { "SERVICE_NAME": "49" }
52+
"authmechanismproperties": {
53+
"SERVICE_NAME": "49"
54+
}
5355
}
5456
},
5557
{
@@ -115,8 +117,8 @@
115117
"source": "$external",
116118
"mechanism": "GSSAPI",
117119
"mechanism_properties": {
118-
"SERVICE_NAME": "mongodb",
119-
"CANONICALIZE_HOST_NAME": true
120+
"SERVICE_NAME": "mongodb",
121+
"CANONICALIZE_HOST_NAME": true
120122
}
121123
}
122124
},
@@ -130,28 +132,59 @@
130132
"source": "$external",
131133
"mechanism": "GSSAPI",
132134
"mechanism_properties": {
133-
"SERVICE_NAME": "abc",
134-
"CANONICALIZE_HOST_NAME": true
135+
"SERVICE_NAME": "abc",
136+
"CANONICALIZE_HOST_NAME": true
135137
}
136138
}
137-
},
138-
{
139-
"description": "Username containing percent encoded multi-byte UTF-8 is valid",
140-
"uri": "mongodb://%E2%98%83",
141-
"valid": true,
142-
"hosts": [
143-
{
144-
"type": "hostname",
145-
"host": "",
146-
"port": null
139+
},
140+
{
141+
"description": "Username containing percent encoded multi-byte UTF-8 is valid",
142+
"uri": "mongodb://%E2%98%83",
143+
"valid": true,
144+
"hosts": [
145+
{
146+
"type": "hostname",
147+
"host": "",
148+
"port": null
149+
}
150+
]
151+
},
152+
{
153+
"description": "Username containing percent encoded multi-byte UTF-8 is valid",
154+
"uri": "mongodb://%E2%D8%83",
155+
"valid": false,
156+
"warning": true
157+
},
158+
{
159+
"description": "Valid connection and timeout options are parsed correctly, libmongoc version without maxIdleTimeMS",
160+
"uri": "mongodb://example.com/?appname=URI-OPTIONS-SPEC-TEST&connectTimeoutMS=20000&heartbeatFrequencyMS=5000&localThresholdMS=3000&replicaSet=uri-options-spec&retryWrites=true&serverSelectionTimeoutMS=15000&socketTimeoutMS=7500",
161+
"valid": true,
162+
"warning": false,
163+
"hosts": null,
164+
"auth": null,
165+
"options": {
166+
"appname": "URI-OPTIONS-SPEC-TEST",
167+
"connectTimeoutMS": 20000,
168+
"heartbeatFrequencyMS": 5000,
169+
"localThresholdMS": 3000,
170+
"replicaSet": "uri-options-spec",
171+
"retryWrites": true,
172+
"serverSelectionTimeoutMS": 15000,
173+
"socketTimeoutMS": 7500
174+
}
175+
},
176+
{
177+
"description": "Valid connection pool options are parsed correctly, libmongoc version without maxIdleTimeMS",
178+
"uri": "mongodb://example.com/?waitQueueTimeoutMS=50000&maxPoolSize=5&minPoolSize=3",
179+
"valid": true,
180+
"warning": false,
181+
"hosts": null,
182+
"auth": null,
183+
"options": {
184+
"waitQueueTimeoutMS": 50000,
185+
"maxPoolSize": 5,
186+
"minPoolSize": 3
147187
}
148-
]
149-
},
150-
{
151-
"description": "Username containing percent encoded multi-byte UTF-8 is valid",
152-
"uri": "mongodb://%E2%D8%83",
153-
"valid": false,
154-
"warning": true
155-
}
188+
}
156189
]
157190
}

src/libmongoc/tests/test-mongoc-connection-uri.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ run_uri_test (const char *uri_string, bool valid, const bson_t *hosts, const bso
104104
/* CDRIVER-3167 */
105105
if ((mongoc_uri_get_option_as_int32 (uri, MONGOC_URI_CONNECTTIMEOUTMS, 0) < 0) ||
106106
(mongoc_uri_get_option_as_int32 (uri, MONGOC_URI_LOCALTHRESHOLDMS, 0) < 0) ||
107-
(mongoc_uri_get_option_as_int32 (uri, MONGOC_URI_MAXIDLETIMEMS, 0) < 0) ||
108107
(mongoc_uri_get_option_as_int32 (uri, MONGOC_URI_SERVERSELECTIONTIMEOUTMS, 0) < 0) ||
109108
(mongoc_uri_get_option_as_int32 (uri, MONGOC_URI_SOCKETTIMEOUTMS, 0) < 0)) {
110109
MONGOC_WARNING ("Invalid negative timeout");
@@ -240,11 +239,18 @@ run_uri_test (const char *uri_string, bool valid, const bson_t *hosts, const bso
240239
static void
241240
test_connection_uri_cb (void *scenario_vp)
242241
{
242+
static const test_skip_t skips[] = {
243+
{.description = "Valid connection pool options are parsed correctly",
244+
.reason = "libmongoc does not support maxIdleTimeMS"},
245+
{.description = "Valid connection and timeout options are parsed correctly",
246+
.reason = "libmongoc does not support maxIdleTimeMS"},
247+
{.description = NULL},
248+
};
249+
243250
bson_iter_t iter;
244251
bson_iter_t descendent;
245252
bson_iter_t tests_iter;
246253
bson_iter_t warning_iter;
247-
const char *uri_string = NULL;
248254
bson_t hosts;
249255
bson_t auth;
250256
bson_t options;
@@ -262,23 +268,17 @@ test_connection_uri_cb (void *scenario_vp)
262268

263269
bson_iter_bson (&tests_iter, &test_case);
264270

265-
if (test_suite_debug_output ()) {
266-
bson_iter_t test_case_iter;
267-
268-
ASSERT (bson_iter_recurse (&tests_iter, &test_case_iter));
269-
if (bson_iter_find (&test_case_iter, "description")) {
270-
const char *description = bson_iter_utf8 (&test_case_iter, NULL);
271-
ASSERT (bson_iter_find_case (&test_case_iter, "uri"));
271+
const char *description = bson_lookup_utf8 (&test_case, "description");
272+
if (test_should_be_skipped (skips, description)) {
273+
continue;
274+
}
272275

273-
printf (" - %s: '%s'\n", description, bson_iter_utf8 (&test_case_iter, 0));
274-
fflush (stdout);
275-
} else {
276-
fprintf (stderr, "Couldn't find `description` field in testcase\n");
277-
BSON_ASSERT (0);
278-
}
276+
const char *uri_string = bson_lookup_utf8 (&test_case, "uri");
277+
if (test_suite_debug_output ()) {
278+
printf (" - %s: '%s'\n", description, uri_string);
279+
fflush (stdout);
279280
}
280281

281-
uri_string = bson_lookup_utf8 (&test_case, "uri");
282282
/* newer spec test replaces both "auth" and "options" with "credential"
283283
*/
284284
if (bson_has_field (&test_case, "credential")) {

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

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,10 +1988,6 @@ test_mongoc_uri_duplicates (void)
19881988
ASSERT_LOG_DUPE (MONGOC_URI_LOCALTHRESHOLDMS);
19891989
BSON_ASSERT (mongoc_uri_get_option_as_int32 (uri, MONGOC_URI_LOCALTHRESHOLDMS, 0) == 2);
19901990

1991-
RECREATE_URI (MONGOC_URI_MAXIDLETIMEMS "=1&" MONGOC_URI_MAXIDLETIMEMS "=2");
1992-
ASSERT_LOG_DUPE (MONGOC_URI_MAXIDLETIMEMS);
1993-
BSON_ASSERT (mongoc_uri_get_option_as_int32 (uri, MONGOC_URI_MAXIDLETIMEMS, 0) == 2);
1994-
19951991
RECREATE_URI (MONGOC_URI_MAXPOOLSIZE "=1&" MONGOC_URI_MAXPOOLSIZE "=2");
19961992
ASSERT_LOG_DUPE (MONGOC_URI_MAXPOOLSIZE);
19971993
BSON_ASSERT (mongoc_uri_get_option_as_int32 (uri, MONGOC_URI_MAXPOOLSIZE, 0) == 2);
@@ -2093,10 +2089,6 @@ test_mongoc_uri_duplicates (void)
20932089
wc = mongoc_uri_get_write_concern (uri);
20942090
BSON_ASSERT (mongoc_write_concern_get_w (wc) == MONGOC_WRITE_CONCERN_W_MAJORITY);
20952091

2096-
RECREATE_URI (MONGOC_URI_WAITQUEUEMULTIPLE "=1&" MONGOC_URI_WAITQUEUEMULTIPLE "=2");
2097-
ASSERT_LOG_DUPE (MONGOC_URI_WAITQUEUEMULTIPLE);
2098-
BSON_ASSERT (mongoc_uri_get_option_as_int32 (uri, MONGOC_URI_WAITQUEUEMULTIPLE, 0) == 2);
2099-
21002092
RECREATE_URI (MONGOC_URI_WAITQUEUETIMEOUTMS "=1&" MONGOC_URI_WAITQUEUETIMEOUTMS "=2");
21012093
ASSERT_LOG_DUPE (MONGOC_URI_WAITQUEUETIMEOUTMS);
21022094
BSON_ASSERT (mongoc_uri_get_option_as_int32 (uri, MONGOC_URI_WAITQUEUETIMEOUTMS, 0) == 2);
@@ -2301,6 +2293,38 @@ test_parses_long_ipv6 (void)
23012293
}
23022294
}
23032295

2296+
void
2297+
test_uri_depr (void)
2298+
{
2299+
// Test behavior of deprecated URI options.
2300+
// Regression test for CDRIVER-3769 Deprecate unimplemented URI options
2301+
2302+
// Test an unsupported option warns.
2303+
{
2304+
capture_logs (true);
2305+
mongoc_uri_t *uri = mongoc_uri_new ("mongodb://host/?foo=bar");
2306+
ASSERT_CAPTURED_LOG ("uri", MONGOC_LOG_LEVEL_WARNING, "Unsupported");
2307+
capture_logs (false);
2308+
mongoc_uri_destroy (uri);
2309+
}
2310+
// Test that waitQueueMultiple warns.
2311+
{
2312+
capture_logs (true);
2313+
mongoc_uri_t *uri = mongoc_uri_new ("mongodb://host/?waitQueueMultiple=123");
2314+
ASSERT_CAPTURED_LOG ("uri", MONGOC_LOG_LEVEL_WARNING, "Unsupported");
2315+
capture_logs (false);
2316+
mongoc_uri_destroy (uri);
2317+
}
2318+
// Test that maxIdleTimeMS warns.
2319+
{
2320+
capture_logs (true);
2321+
mongoc_uri_t *uri = mongoc_uri_new ("mongodb://host/?maxIdleTimeMS=123");
2322+
ASSERT_CAPTURED_LOG ("uri", MONGOC_LOG_LEVEL_WARNING, "Unsupported");
2323+
capture_logs (false);
2324+
mongoc_uri_destroy (uri);
2325+
}
2326+
}
2327+
23042328
void
23052329
test_uri_install (TestSuite *suite)
23062330
{
@@ -2328,4 +2352,5 @@ test_uri_install (TestSuite *suite)
23282352
TestSuite_Add (suite, "/Uri/one_tls_option_enables_tls", test_one_tls_option_enables_tls);
23292353
TestSuite_Add (suite, "/Uri/options_casing", test_casing_options);
23302354
TestSuite_Add (suite, "/Uri/parses_long_ipv6", test_parses_long_ipv6);
2355+
TestSuite_Add (suite, "/Uri/depr", test_uri_depr);
23312356
}

0 commit comments

Comments
 (0)