Skip to content

Commit fbf4258

Browse files
committed
Implement unified URI options spec
GODRIVER-620 Change-Id: I3e24a0f7978f99967f79b190e2f44e5ad5a9650f
1 parent 1cde213 commit fbf4258

23 files changed

+1310
-17
lines changed

data/uri-options/README.rst

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

data/uri-options/auth-options.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"tests": [
3+
{
4+
"description": "Valid auth options are parsed correctly",
5+
"uri": "mongodb://foo:[email protected]/?authMechanism=GSSAPI&authMechanismProperties=SERVICE_NAME:other,CANONICALIZE_HOST_NAME:true&authSource=$external",
6+
"valid": true,
7+
"warning": false,
8+
"hosts": null,
9+
"auth": null,
10+
"options": {
11+
"authMechanism": "GSSAPI",
12+
"authMechanismProperties": {
13+
"SERVICE_NAME": "other",
14+
"CANONICALIZE_HOST_NAME": true
15+
},
16+
"authSource": "$external"
17+
}
18+
}
19+
]
20+
}

data/uri-options/auth-options.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
tests:
2+
-
3+
description: "Valid auth options are parsed correctly"
4+
uri: "mongodb://foo:[email protected]/?authMechanism=GSSAPI&authMechanismProperties=SERVICE_NAME:other,CANONICALIZE_HOST_NAME:true&authSource=$external"
5+
valid: true
6+
warning: false
7+
hosts: ~
8+
auth: ~
9+
options:
10+
authMechanism: "GSSAPI"
11+
authMechanismProperties:
12+
SERVICE_NAME: "other"
13+
CANONICALIZE_HOST_NAME: true
14+
authSource: "$external"

data/uri-options/ca.pem

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# This file exists solely for the purpose of facilitating drivers which check for the existence of files specified in the URI options at parse time.

data/uri-options/cert.pem

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# This file exists solely for the purpose of facilitating drivers which check for the existence of files specified in the URI options at parse time.

data/uri-options/client.pem

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# This file exists solely for the purpose of facilitating drivers which check for the existence of files specified in the URI options at parse time.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"tests": [
3+
{
4+
"description": "Valid compression options are parsed correctly",
5+
"uri": "mongodb://example.com/?compressors=zlib&zlibCompressionLevel=9",
6+
"valid": true,
7+
"warning": false,
8+
"hosts": null,
9+
"auth": null,
10+
"options": {
11+
"compressors": [
12+
"zlib"
13+
],
14+
"zlibCompressionLevel": 9
15+
}
16+
},
17+
{
18+
"description": "Multiple compressors are parsed correctly",
19+
"uri": "mongodb://example.com/?compressors=snappy,zlib",
20+
"valid": true,
21+
"warning": false,
22+
"hosts": null,
23+
"auth": null,
24+
"options": {
25+
"compressors": [
26+
"snappy",
27+
"zlib"
28+
]
29+
}
30+
},
31+
{
32+
"description": "Non-numeric zlibCompressionLevel causes a warning",
33+
"uri": "mongodb://example.com/?compressors=zlib&zlibCompressionLevel=invalid",
34+
"valid": true,
35+
"warning": true,
36+
"hosts": null,
37+
"auth": null,
38+
"options": {}
39+
},
40+
{
41+
"description": "Too low zlibCompressionLevel causes a warning",
42+
"uri": "mongodb://example.com/?compressors=zlib&zlibCompressionLevel=-2",
43+
"valid": true,
44+
"warning": true,
45+
"hosts": null,
46+
"auth": null,
47+
"options": {}
48+
},
49+
{
50+
"description": "Too high zlibCompressionLevel causes a warning",
51+
"uri": "mongodb://example.com/?compressors=zlib&zlibCompressionLevel=10",
52+
"valid": true,
53+
"warning": true,
54+
"hosts": null,
55+
"auth": null,
56+
"options": {}
57+
}
58+
]
59+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
tests:
2+
-
3+
description: "Valid compression options are parsed correctly"
4+
uri: "mongodb://example.com/?compressors=zlib&zlibCompressionLevel=9"
5+
valid: true
6+
warning: false
7+
hosts: ~
8+
auth: ~
9+
options:
10+
compressors:
11+
- "zlib"
12+
zlibCompressionLevel: 9
13+
-
14+
description: "Multiple compressors are parsed correctly"
15+
uri: "mongodb://example.com/?compressors=snappy,zlib"
16+
valid: true
17+
warning: false
18+
hosts: ~
19+
auth: ~
20+
options:
21+
compressors:
22+
- "snappy"
23+
- "zlib"
24+
-
25+
description: "Non-numeric zlibCompressionLevel causes a warning"
26+
uri: "mongodb://example.com/?compressors=zlib&zlibCompressionLevel=invalid"
27+
valid: true
28+
warning: true
29+
hosts: ~
30+
auth: ~
31+
options: {}
32+
-
33+
description: "Too low zlibCompressionLevel causes a warning"
34+
uri: "mongodb://example.com/?compressors=zlib&zlibCompressionLevel=-2"
35+
valid: true
36+
warning: true
37+
hosts: ~
38+
auth: ~
39+
options: {}
40+
-
41+
description: "Too high zlibCompressionLevel causes a warning"
42+
uri: "mongodb://example.com/?compressors=zlib&zlibCompressionLevel=10"
43+
valid: true
44+
warning: true
45+
hosts: ~
46+
auth: ~
47+
options: {}
48+

data/uri-options/concern-options.json

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
"tests": [
3+
{
4+
"description": "Valid read and write concern are parsed correctly",
5+
"uri": "mongodb://example.com/?readConcernLevel=majority&w=5&wTimeoutMS=30000&journal=false",
6+
"valid": true,
7+
"warning": false,
8+
"hosts": null,
9+
"auth": null,
10+
"options": {
11+
"readConcernLevel": "majority",
12+
"w": 5,
13+
"wTimeoutMS": 30000,
14+
"journal": false
15+
}
16+
},
17+
{
18+
"description": "Arbitrary string readConcernLevel does not cause a warning",
19+
"uri": "mongodb://example.com/?readConcernLevel=arbitraryButStillValid",
20+
"valid": true,
21+
"warning": false,
22+
"hosts": null,
23+
"auth": null,
24+
"options": {
25+
"readConcernLevel": "arbitraryButStillValid"
26+
}
27+
},
28+
{
29+
"description": "Arbitrary string w doesn't cause a warning",
30+
"uri": "mongodb://example.com/?w=arbitraryButStillValid",
31+
"valid": true,
32+
"warning": false,
33+
"hosts": null,
34+
"auth": null,
35+
"options": {
36+
"w": "arbitraryButStillValid"
37+
}
38+
},
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+
},
48+
{
49+
"description": "Non-numeric wTimeoutMS causes a warning",
50+
"uri": "mongodb://example.com/?wTimeoutMS=invalid",
51+
"valid": true,
52+
"warning": true,
53+
"hosts": null,
54+
"auth": null,
55+
"options": {}
56+
},
57+
{
58+
"description": "Too low wTimeoutMS causes a warning",
59+
"uri": "mongodb://example.com/?wTimeoutMS=-2",
60+
"valid": true,
61+
"warning": true,
62+
"hosts": null,
63+
"auth": null,
64+
"options": {}
65+
},
66+
{
67+
"description": "Invalid journal causes a warning",
68+
"uri": "mongodb://example.com/?journal=invalid",
69+
"valid": true,
70+
"warning": true,
71+
"hosts": null,
72+
"auth": null,
73+
"options": {}
74+
}
75+
]
76+
}

data/uri-options/concern-options.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
tests:
2+
-
3+
description: "Valid read and write concern are parsed correctly"
4+
uri: "mongodb://example.com/?readConcernLevel=majority&w=5&wTimeoutMS=30000&journal=false"
5+
valid: true
6+
warning: false
7+
hosts: ~
8+
auth: ~
9+
options:
10+
readConcernLevel: "majority"
11+
w: 5
12+
wTimeoutMS: 30000
13+
journal: false
14+
-
15+
description: "Arbitrary string readConcernLevel does not cause a warning"
16+
uri: "mongodb://example.com/?readConcernLevel=arbitraryButStillValid"
17+
valid: true
18+
warning: false
19+
hosts: ~
20+
auth: ~
21+
options:
22+
readConcernLevel: "arbitraryButStillValid"
23+
-
24+
description: "Arbitrary string w doesn't cause a warning"
25+
uri: "mongodb://example.com/?w=arbitraryButStillValid"
26+
valid: true
27+
warning: false
28+
hosts: ~
29+
auth: ~
30+
options:
31+
w: "arbitraryButStillValid"
32+
-
33+
description: "Non-numeric wTimeoutMS causes a warning"
34+
uri: "mongodb://example.com/?wTimeoutMS=invalid"
35+
valid: true
36+
warning: true
37+
hosts: ~
38+
auth: ~
39+
options: {}
40+
-
41+
description: "Too low wTimeoutMS causes a warning"
42+
uri: "mongodb://example.com/?wTimeoutMS=-2"
43+
valid: true
44+
warning: true
45+
hosts: ~
46+
auth: ~
47+
options: {}
48+
-
49+
description: "Invalid journal causes a warning"
50+
uri: "mongodb://example.com/?journal=invalid"
51+
valid: true
52+
warning: true
53+
hosts: ~
54+
auth: ~
55+
options: {}

0 commit comments

Comments
 (0)