Skip to content

Commit 9081b9d

Browse files
RUST-2066 Sync URI options tests (#1422)
1 parent 2633c6d commit 9081b9d

25 files changed

+1314
-203
lines changed

src/client/options/test.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ static SKIPPED_TESTS: Lazy<Vec<&'static str>> = Lazy::new(|| {
2222
"maxPoolSize=0 does not error",
2323
#[cfg(not(feature = "cert-key-password"))]
2424
"Valid tlsCertificateKeyFilePassword is parsed correctly",
25+
// The driver does not support OCSP (see RUST-361)
26+
"tlsDisableCertificateRevocationCheck can be set to true",
27+
"tlsDisableCertificateRevocationCheck can be set to false",
28+
"tlsDisableOCSPEndpointCheck can be set to true",
29+
"tlsDisableOCSPEndpointCheck can be set to false",
30+
// TODO RUST-582: unskip these tests
31+
"Valid connection and timeout options are parsed correctly",
32+
"timeoutMS=0",
2533
];
2634

2735
// TODO RUST-1896: unskip this test when openssl-tls is enabled
@@ -209,7 +217,11 @@ async fn run_tests(path: &[&str], skipped_files: &[&str]) {
209217

210218
#[tokio::test]
211219
async fn run_uri_options_spec_tests() {
212-
let skipped_files = vec!["single-threaded-options.json"];
220+
let skipped_files = vec![
221+
"single-threaded-options.json",
222+
// TODO RUST-1054 unskip this file
223+
"proxy-options.json",
224+
];
213225
run_tests(&["uri-options"], &skipped_files).await;
214226
}
215227

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# URI Options Tests
2+
3+
The YAML and JSON files in this directory tree are platform-independent tests that drivers can use to prove their
4+
conformance to the URI Options spec.
5+
6+
These tests use the same format as the Connection String spec tests.
7+
8+
## Version
9+
10+
Files in the "specifications" repository have no version scheme. They are not tied to a MongoDB server version.
11+
12+
## Format
13+
14+
Each YAML file contains an object with a single `tests` key. This key is an array of test case objects, each of which
15+
have the following keys:
16+
17+
- `description`: A string describing the test.
18+
- `uri`: A string containing the URI to be parsed.
19+
- `valid`: A boolean indicating if the URI should be considered valid.
20+
- `warning`: A boolean indicating whether URI parsing should emit a warning.
21+
- `hosts`: Included for compatibility with the Connection String spec tests. This will always be `~`.
22+
- `auth`: Included for compatibility with the Connection String spec tests. This will always be `~`.
23+
- `options`: An object containing key/value pairs for each parsed query string option.
24+
25+
If a test case includes a null value for one of these keys (e.g. `auth: ~`, `hosts: ~`), no assertion is necessary. This
26+
both simplifies parsing of the test files (keys should always exist) and allows flexibility for drivers that might
27+
substitute default values *during* parsing (e.g. omitted `hosts` could be parsed as `["localhost"]`).
28+
29+
The `valid` and `warning` fields are boolean in order to keep the tests flexible. We are not concerned with asserting
30+
the format of specific error or warnings messages strings.
31+
32+
Under normal circumstances, it should not be necessary to specify both `valid: false` and `warning: true`. Typically, a
33+
URI test case will either yield an error (e.g. options conflict) or a warning (e.g. invalid type or value for an
34+
option), but not both.
35+
36+
### Use as unit tests
37+
38+
Testing whether a URI is valid or not requires testing whether URI parsing (or MongoClient construction) causes a
39+
warning due to a URI option being invalid and asserting that the options parsed from the URI match those listed in the
40+
`options` field.
41+
42+
Note that there are tests for each of the options marked as optional; drivers will need to implement logic to skip over
43+
the optional tests that they don't implement.

src/test/spec/json/uri-options/README.rst

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/test/spec/json/uri-options/auth-options.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"tests": [
33
{
44
"description": "Valid auth options are parsed correctly (GSSAPI)",
5-
"uri": "mongodb://foo:[email protected]/?authMechanism=GSSAPI&authMechanismProperties=SERVICE_NAME:other,CANONICALIZE_HOST_NAME:true&authSource=$external",
5+
"uri": "mongodb://foo:[email protected]/?authMechanism=GSSAPI&authMechanismProperties=SERVICE_NAME:other,CANONICALIZE_HOST_NAME:forward,SERVICE_HOST:example.com&authSource=$external",
66
"valid": true,
77
"warning": false,
88
"hosts": null,
@@ -11,7 +11,8 @@
1111
"authMechanism": "GSSAPI",
1212
"authMechanismProperties": {
1313
"SERVICE_NAME": "other",
14-
"CANONICALIZE_HOST_NAME": true
14+
"SERVICE_HOST": "example.com",
15+
"CANONICALIZE_HOST_NAME": "forward"
1516
},
1617
"authSource": "$external"
1718
}

src/test/spec/json/uri-options/auth-options.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
tests:
22
-
33
description: "Valid auth options are parsed correctly (GSSAPI)"
4-
uri: "mongodb://foo:[email protected]/?authMechanism=GSSAPI&authMechanismProperties=SERVICE_NAME:other,CANONICALIZE_HOST_NAME:true&authSource=$external"
4+
uri: "mongodb://foo:[email protected]/?authMechanism=GSSAPI&authMechanismProperties=SERVICE_NAME:other,CANONICALIZE_HOST_NAME:forward,SERVICE_HOST:example.com&authSource=$external"
55
valid: true
66
warning: false
77
hosts: ~
@@ -10,7 +10,8 @@ tests:
1010
authMechanism: "GSSAPI"
1111
authMechanismProperties:
1212
SERVICE_NAME: "other"
13-
CANONICALIZE_HOST_NAME: true
13+
SERVICE_HOST: "example.com"
14+
CANONICALIZE_HOST_NAME: "forward"
1415
authSource: "$external"
1516
-
1617
description: "Valid auth options are parsed correctly (SCRAM-SHA-1)"

src/test/spec/json/uri-options/compression-options.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"warning": true,
3636
"hosts": null,
3737
"auth": null,
38-
"options": {}
38+
"options": null
3939
},
4040
{
4141
"description": "Too low zlibCompressionLevel causes a warning",
@@ -44,7 +44,7 @@
4444
"warning": true,
4545
"hosts": null,
4646
"auth": null,
47-
"options": {}
47+
"options": null
4848
},
4949
{
5050
"description": "Too high zlibCompressionLevel causes a warning",
@@ -53,7 +53,7 @@
5353
"warning": true,
5454
"hosts": null,
5555
"auth": null,
56-
"options": {}
56+
"options": null
5757
}
5858
]
5959
}

src/test/spec/json/uri-options/compression-options.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,21 @@ tests:
2828
warning: true
2929
hosts: ~
3030
auth: ~
31-
options: {}
31+
options: ~
3232
-
3333
description: "Too low zlibCompressionLevel causes a warning"
3434
uri: "mongodb://example.com/?compressors=zlib&zlibCompressionLevel=-2"
3535
valid: true
3636
warning: true
3737
hosts: ~
3838
auth: ~
39-
options: {}
39+
options: ~
4040
-
4141
description: "Too high zlibCompressionLevel causes a warning"
4242
uri: "mongodb://example.com/?compressors=zlib&zlibCompressionLevel=10"
4343
valid: true
4444
warning: true
4545
hosts: ~
4646
auth: ~
47-
options: {}
47+
options: ~
4848

src/test/spec/json/uri-options/concern-options.json

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,14 @@
3636
"w": "arbitraryButStillValid"
3737
}
3838
},
39-
{
40-
"description": "Too low w causes a warning",
41-
"uri": "mongodb://example.com/?w=-2",
42-
"valid": true,
43-
"warning": true,
44-
"hosts": null,
45-
"auth": null,
46-
"options": {}
47-
},
4839
{
4940
"description": "Non-numeric wTimeoutMS causes a warning",
5041
"uri": "mongodb://example.com/?wTimeoutMS=invalid",
5142
"valid": true,
5243
"warning": true,
5344
"hosts": null,
5445
"auth": null,
55-
"options": {}
46+
"options": null
5647
},
5748
{
5849
"description": "Too low wTimeoutMS causes a warning",
@@ -61,7 +52,7 @@
6152
"warning": true,
6253
"hosts": null,
6354
"auth": null,
64-
"options": {}
55+
"options": null
6556
},
6657
{
6758
"description": "Invalid journal causes a warning",
@@ -70,7 +61,7 @@
7061
"warning": true,
7162
"hosts": null,
7263
"auth": null,
73-
"options": {}
64+
"options": null
7465
}
7566
]
7667
}

src/test/spec/json/uri-options/concern-options.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,20 @@ tests:
3636
warning: true
3737
hosts: ~
3838
auth: ~
39-
options: {}
39+
options: ~
4040
-
4141
description: "Too low wTimeoutMS causes a warning"
4242
uri: "mongodb://example.com/?wTimeoutMS=-2"
4343
valid: true
4444
warning: true
4545
hosts: ~
4646
auth: ~
47-
options: {}
47+
options: ~
4848
-
4949
description: "Invalid journal causes a warning"
5050
uri: "mongodb://example.com/?journal=invalid"
5151
valid: true
5252
warning: true
5353
hosts: ~
5454
auth: ~
55-
options: {}
55+
options: ~

0 commit comments

Comments
 (0)