Skip to content

Add uri options tests #414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Jan 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions source/uri-options/tests/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
=======================
URI Options Tests
=======================

The YAML and JSON files in this directory tree are platform-independent tests
that drivers can use to prove their conformance to the URI Options spec.

These tests use the same format as the Connection String spec tests.

Version
-------

Files in the "specifications" repository have no version scheme. They are not
tied to a MongoDB server version.

Format
------

Each YAML file contains an object with a single ``tests`` key. This key is an
array of test case objects, each of which have the following keys:

- ``description``: A string describing the test.
- ``uri``: A string containing the URI to be parsed.
- ``valid``: A boolean indicating if the URI should be considered valid.
This will always be true, as the Connection String spec tests the validity of the structure, but
it's still included to make it easier to reuse the connection string spec test runners that
drivers already have.
- ``warning``: A boolean indicating whether URI parsing should emit a warning.
- ``hosts``: Included for compatibility with the Connection String spec tests. This will always be ``~``.
- ``auth``: Included for compatibility with the Connection String spec tests. This will always be ``~``.
- ``options``: An object containing key/value pairs for each parsed query string
option.

If a test case includes a null value for one of these keys (e.g. ``auth: ~``,
``hosts: ~``), no assertion is necessary. This both simplifies parsing of the
test files (keys should always exist) and allows flexibility for drivers that
might substitute default values *during* parsing (e.g. omitted ``hosts`` could be
parsed as ``["localhost"]``).

The ``valid`` and ``warning`` fields are boolean in order to keep the tests
flexible. We are not concerned with asserting the format of specific error or
warnings messages strings.

Use as unit tests
=================

Testing whether a URI is valid or not requires testing whether URI parsing (or
MongoClient construction) causes a warning due to a URI option being invalid and asserting that the
options parsed from the URI match those listed in the ``options`` field.

Note that there are tests for each of the options marked as optional; drivers will need to implement
logic to skip over the optional tests that they don’t implement.
20 changes: 20 additions & 0 deletions source/uri-options/tests/auth-options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"tests": [
{
"description": "Valid auth options are parsed correctly",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this test. It's saying that you should be able to specify all the auth options, but if there's no user name, auth should be disabled (but the auth properties should still be accessible)?

Java driver doesn't support this, as the ConnectionString returns a fully formed MongoCredential, not individual properties?

Would it go against the purpose of this test to add a username to the URI?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hadn't considered that drivers might parse all options into a single object at once; I can add a username to this test.

"uri": "mongodb://foo:bar@example.com/?authMechanism=GSSAPI&authMechanismProperties=SERVICE_NAME:other,CANONICALIZE_HOST_NAME:true&authSource=$external",
"valid": true,
"warning": false,
"hosts": null,
"auth": null,
"options": {
"authMechanism": "GSSAPI",
"authMechanismProperties": {
"SERVICE_NAME": "other",
"CANONICALIZE_HOST_NAME": true
},
"authSource": "$external"
}
}
]
}
14 changes: 14 additions & 0 deletions source/uri-options/tests/auth-options.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
tests:
-
description: "Valid auth options are parsed correctly"
uri: "mongodb://foo:bar@example.com/?authMechanism=GSSAPI&authMechanismProperties=SERVICE_NAME:other,CANONICALIZE_HOST_NAME:true&authSource=$external"
valid: true
warning: false
hosts: ~
auth: ~
options:
authMechanism: "GSSAPI"
authMechanismProperties:
SERVICE_NAME: "other"
CANONICALIZE_HOST_NAME: true
authSource: "$external"
1 change: 1 addition & 0 deletions source/uri-options/tests/ca.pem
Original file line number Diff line number Diff line change
@@ -0,0 +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.
1 change: 1 addition & 0 deletions source/uri-options/tests/cert.pem
Original file line number Diff line number Diff line change
@@ -0,0 +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.
1 change: 1 addition & 0 deletions source/uri-options/tests/client.pem
Original file line number Diff line number Diff line change
@@ -0,0 +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.
59 changes: 59 additions & 0 deletions source/uri-options/tests/compression-options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"tests": [
{
"description": "Valid compression options are parsed correctly",
"uri": "mongodb://example.com/?compressors=zlib&zlibCompressionLevel=9",
"valid": true,
"warning": false,
"hosts": null,
"auth": null,
"options": {
"compressors": [
"zlib"
],
"zlibCompressionLevel": 9
}
},
{
"description": "Multiple compressors are parsed correctly",
"uri": "mongodb://example.com/?compressors=snappy,zlib",
"valid": true,
"warning": true,
"hosts": null,
"auth": null,
"options": {
"compressors": [
"snappy",
"zlib"
]
}
},
{
"description": "Non-numeric zlibCompressionLevel causes a warning",
"uri": "mongodb://example.com/?compressors=zlib&zlibCompressionLevel=invalid",
"valid": true,
"warning": true,
"hosts": null,
"auth": null,
"options": {}
},
{
"description": "Too low zlibCompressionLevel causes a warning",
"uri": "mongodb://example.com/?compressors=zlib&zlibCompressionLevel=-2",
"valid": true,
"warning": true,
"hosts": null,
"auth": null,
"options": {}
},
{
"description": "Too high zlibCompressionLevel causes a warning",
"uri": "mongodb://example.com/?compressors=zlib&zlibCompressionLevel=10",
"valid": true,
"warning": true,
"hosts": null,
"auth": null,
"options": {}
}
]
}
48 changes: 48 additions & 0 deletions source/uri-options/tests/compression-options.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
tests:
-
description: "Valid compression options are parsed correctly"
uri: "mongodb://example.com/?compressors=zlib&zlibCompressionLevel=9"
valid: true
warning: false
hosts: ~
auth: ~
options:
compressors:
- "zlib"
zlibCompressionLevel: 9
-
description: "Multiple compressors are parsed correctly"
uri: "mongodb://example.com/?compressors=snappy,zlib"
valid: true
warning: true
hosts: ~
auth: ~
options:
compressors:
- "snappy"
- "zlib"
-
description: "Non-numeric zlibCompressionLevel causes a warning"
uri: "mongodb://example.com/?compressors=zlib&zlibCompressionLevel=invalid"
valid: true
warning: true
hosts: ~
auth: ~
options: {}
-
description: "Too low zlibCompressionLevel causes a warning"
uri: "mongodb://example.com/?compressors=zlib&zlibCompressionLevel=-2"
valid: true
warning: true
hosts: ~
auth: ~
options: {}
-
description: "Too high zlibCompressionLevel causes a warning"
uri: "mongodb://example.com/?compressors=zlib&zlibCompressionLevel=10"
valid: true
warning: true
hosts: ~
auth: ~
options: {}

76 changes: 76 additions & 0 deletions source/uri-options/tests/concern-options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"tests": [
{
"description": "Valid read and write concern are parsed correctly",
"uri": "mongodb://example.com/?readConcernLevel=majority&w=5&wTimeoutMS=30000&journal=false",
"valid": true,
"warning": false,
"hosts": null,
"auth": null,
"options": {
"readConcernLevel": "majority",
"w": 5,
"wTimeoutMS": 30000,
"journal": false
}
},
{
"description": "Arbitrary string readConcernLevel does not cause a warning",
"uri": "mongodb://example.com/?readConcernLevel=arbitraryButStillValid",
"valid": true,
"warning": false,
"hosts": null,
"auth": null,
"options": {
"readConcernLevel": "arbitraryButStillValid"
}
},
{
"description": "Arbitrary string w doesn't cause a warning",
"uri": "mongodb://example.com/?w=arbitraryButStillValid",
"valid": true,
"warning": false,
"hosts": null,
"auth": null,
"options": {
"w": "arbitraryButStillValid"
}
},
{
"description": "Too low w causes a warning",
"uri": "mongodb://example.com/?w=-2",
"valid": true,
"warning": true,
"hosts": null,
"auth": null,
"options": {}
},
{
"description": "Non-numeric wTimeoutMS causes a warning",
"uri": "mongodb://example.com/?wTimeoutMS=invalid",
"valid": true,
"warning": true,
"hosts": null,
"auth": null,
"options": {}
},
{
"description": "Too low wTimeoutMS causes a warning",
"uri": "mongodb://example.com/?wTimeoutMS=-2",
"valid": true,
"warning": true,
"hosts": null,
"auth": null,
"options": {}
},
{
"description": "Invalid journal causes a warning",
"uri": "mongodb://example.com/?journal=invalid",
"valid": true,
"warning": true,
"hosts": null,
"auth": null,
"options": {}
}
]
}
55 changes: 55 additions & 0 deletions source/uri-options/tests/concern-options.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
tests:
-
description: "Valid read and write concern are parsed correctly"
uri: "mongodb://example.com/?readConcernLevel=majority&w=5&wTimeoutMS=30000&journal=false"
valid: true
warning: false
hosts: ~
auth: ~
options:
readConcernLevel: "majority"
w: 5
wTimeoutMS: 30000
journal: false
-
description: "Arbitrary string readConcernLevel does not cause a warning"
uri: "mongodb://example.com/?readConcernLevel=arbitraryButStillValid"
valid: true
warning: false
hosts: ~
auth: ~
options:
readConcernLevel: "arbitraryButStillValid"
-
description: "Arbitrary string w doesn't cause a warning"
uri: "mongodb://example.com/?w=arbitraryButStillValid"
valid: true
warning: false
hosts: ~
auth: ~
options:
w: "arbitraryButStillValid"
-
description: "Non-numeric wTimeoutMS causes a warning"
uri: "mongodb://example.com/?wTimeoutMS=invalid"
valid: true
warning: true
hosts: ~
auth: ~
options: {}
-
description: "Too low wTimeoutMS causes a warning"
uri: "mongodb://example.com/?wTimeoutMS=-2"
valid: true
warning: true
hosts: ~
auth: ~
options: {}
-
description: "Invalid journal causes a warning"
uri: "mongodb://example.com/?journal=invalid"
valid: true
warning: true
hosts: ~
auth: ~
options: {}
Loading