Skip to content

GODRIVER-2092 Disallow positive srvMaxHosts with replicaSet or loadBalanced=true #767

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 5 commits into from
Oct 14, 2021
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
10 changes: 5 additions & 5 deletions data/initial-dns-seedlist-discovery/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ load-balanced sharded cluster with the mongos servers running on localhost ports
27017 and 27018 (corresponding to the script in `drivers-evergreen-tools`_). The
load balancers, shard servers, and config servers may run on any open ports.

.. _`drivers-evergreen-tools`: ../../connection-string/connection-string-spec.rst
.. _`drivers-evergreen-tools`: https://github.com/mongodb-labs/drivers-evergreen-tools/blob/master/.evergreen/run-load-balancer.sh

The tests in the ``sharded`` directory MUST be executed against a sharded
cluster with the mongos servers running on localhost ports 27017 and 27018.
Expand Down Expand Up @@ -98,7 +98,7 @@ These YAML and JSON files contain the following fields:
hosts cannot be deterministically asserted.
- ``options``: the parsed `URI options`_ as discovered from the
`Connection String`_'s "Connection Options" component and SRV resolution
(e.g. TXT records, implicit ``ssl`` default).
(e.g. TXT records, implicit ``tls`` default).
- ``parsed_options``: additional, parsed options from other `Connection String`_
components. This is mainly used for asserting ``UserInfo`` (as ``user`` and
``password``) and ``Auth database`` (as ``auth_database``).
Expand All @@ -109,7 +109,7 @@ These YAML and JSON files contain the following fields:
.. _`Connection String`: ../../connection-string/connection-string-spec.rst
.. _`URI options`: ../../uri-options/uri-options.rst

For each file, create MongoClient initialized with the ``mongodb+srv``
For each file, create a MongoClient initialized with the ``mongodb+srv``
connection string.

If ``seeds`` is specified, drivers SHOULD verify that the set of hosts in the
Expand All @@ -123,11 +123,11 @@ size of that set matches ``numHosts``.

If ``options`` is specified, drivers MUST verify each of the values under
``options`` match the MongoClient's parsed value for that option. There may be
other options parsed by the Client as well, which a test does not verify.
other options parsed by the MongoClient as well, which a test does not verify.

If ``parsed_options`` is specified, drivers MUST verify that each of the values
under ``parsed_options`` match the MongoClient's parsed value for that option.
Support values include, but are not limited to, ``user`` and ``password``
Supported values include, but are not limited to, ``user`` and ``password``
(parsed from ``UserInfo``) and ``auth_database`` (parsed from
``Auth database``).

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"uri": "mongodb+srv://test20.test.build.10gen.cc/?srvMaxHosts=1",
"seeds": [],
"hosts": [],
"error": true,
"comment": "Should fail because positive integer for srvMaxHosts conflicts with loadBalanced=true (TXT)"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
uri: "mongodb+srv://test20.test.build.10gen.cc/?srvMaxHosts=1"
seeds: []
hosts: []
error: true
comment: Should fail because positive integer for srvMaxHosts conflicts with loadBalanced=true (TXT)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"uri": "mongodb+srv://test3.test.build.10gen.cc/?loadBalanced=true&srvMaxHosts=1",
"seeds": [],
"hosts": [],
"error": true,
"comment": "Should fail because positive integer for srvMaxHosts conflicts with loadBalanced=true"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
uri: "mongodb+srv://test3.test.build.10gen.cc/?loadBalanced=true&srvMaxHosts=1"
seeds: []
hosts: []
error: true
comment: Should fail because positive integer for srvMaxHosts conflicts with loadBalanced=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"uri": "mongodb+srv://test20.test.build.10gen.cc/?srvMaxHosts=0",
"seeds": [
"localhost.test.build.10gen.cc:27017"
],
"hosts": [
"localhost.test.build.10gen.cc:27017"
],
"options": {
"loadBalanced": true,
"srvMaxHosts": 0,
"ssl": true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# loadBalanced=true (TXT) is permitted because srvMaxHosts is non-positive
uri: "mongodb+srv://test20.test.build.10gen.cc/?srvMaxHosts=0"
seeds:
- localhost.test.build.10gen.cc:27017
hosts:
- localhost.test.build.10gen.cc:27017
options:
loadBalanced: true
srvMaxHosts: 0
ssl: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"uri": "mongodb+srv://test3.test.build.10gen.cc/?loadBalanced=true&srvMaxHosts=0",
"seeds": [
"localhost.test.build.10gen.cc:27017"
],
"hosts": [
"localhost.test.build.10gen.cc:27017"
],
"options": {
"loadBalanced": true,
"srvMaxHosts": 0,
"ssl": true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# loadBalanced=true is permitted because srvMaxHosts is non-positive
uri: "mongodb+srv://test3.test.build.10gen.cc/?loadBalanced=true&srvMaxHosts=0"
seeds:
- localhost.test.build.10gen.cc:27017
hosts:
- localhost.test.build.10gen.cc:27017
options:
loadBalanced: true
srvMaxHosts: 0
ssl: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"uri": "mongodb+srv://test5.test.build.10gen.cc/?srvMaxHosts=1",
"seeds": [],
"hosts": [],
"error": true,
"comment": "Should fail because positive integer for srvMaxHosts conflicts with replicaSet option (TXT)"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
uri: "mongodb+srv://test5.test.build.10gen.cc/?srvMaxHosts=1"
seeds: []
hosts: []
error: true
comment: Should fail because positive integer for srvMaxHosts conflicts with replicaSet option (TXT)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"uri": "mongodb+srv://test1.test.build.10gen.cc/?replicaSet=repl0&srvMaxHosts=1",
"seeds": [],
"hosts": [],
"error": true,
"comment": "Should fail because positive integer for srvMaxHosts conflicts with replicaSet option"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
uri: "mongodb+srv://test1.test.build.10gen.cc/?replicaSet=repl0&srvMaxHosts=1"
seeds: []
hosts: []
error: true
comment: Should fail because positive integer for srvMaxHosts conflicts with replicaSet option
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"uri": "mongodb+srv://test1.test.build.10gen.cc/?replicaSet=repl0&srvMaxHosts=2",
"uri": "mongodb+srv://test1.test.build.10gen.cc/?srvMaxHosts=2",
"numSeeds": 2,
"seeds": [
"localhost.test.build.10gen.cc:27017",
Expand All @@ -11,7 +11,6 @@
"localhost:27019"
],
"options": {
"replicaSet": "repl0",
"srvMaxHosts": 2,
"ssl": true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# When srvMaxHosts equals the number of SRV records, all hosts are added to the
# seed list.
uri: "mongodb+srv://test1.test.build.10gen.cc/?replicaSet=repl0&srvMaxHosts=2"
#
# The replicaSet URI option is omitted to avoid a URI validation error.
uri: "mongodb+srv://test1.test.build.10gen.cc/?srvMaxHosts=2"
numSeeds: 2
seeds:
- localhost.test.build.10gen.cc:27017
Expand All @@ -10,6 +12,5 @@ hosts:
- localhost:27018
- localhost:27019
options:
replicaSet: repl0
srvMaxHosts: 2
ssl: true
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"uri": "mongodb+srv://test1.test.build.10gen.cc/?replicaSet=repl0&srvMaxHosts=3",
"uri": "mongodb+srv://test1.test.build.10gen.cc/?srvMaxHosts=3",
"seeds": [
"localhost.test.build.10gen.cc:27017",
"localhost.test.build.10gen.cc:27018"
Expand All @@ -10,7 +10,6 @@
"localhost:27019"
],
"options": {
"replicaSet": "repl0",
"srvMaxHosts": 3,
"ssl": true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# When srvMaxHosts is greater than the number of SRV records, all hosts are
# added to the seed list.
uri: "mongodb+srv://test1.test.build.10gen.cc/?replicaSet=repl0&srvMaxHosts=3"
#
# The replicaSet URI option is omitted to avoid a URI validation error.
uri: "mongodb+srv://test1.test.build.10gen.cc/?srvMaxHosts=3"
seeds:
- localhost.test.build.10gen.cc:27017
- localhost.test.build.10gen.cc:27018
Expand All @@ -9,6 +11,5 @@ hosts:
- localhost:27018
- localhost:27019
options:
replicaSet: repl0
srvMaxHosts: 3
ssl: true
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"uri": "mongodb+srv://test1.test.build.10gen.cc/?replicaSet=repl0&srvMaxHosts=1",
"uri": "mongodb+srv://test1.test.build.10gen.cc/?srvMaxHosts=1",
"numSeeds": 1,
"hosts": [
"localhost:27017",
"localhost:27018",
"localhost:27019"
],
"options": {
"replicaSet": "repl0",
"srvMaxHosts": 1,
"ssl": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
# hosts are added to the seed list. We cannot anticipate which hosts will be
# selected, so this test uses numSeeds instead of seeds. Since this is a replica
# set, all hosts should ultimately be discovered by SDAM.
uri: "mongodb+srv://test1.test.build.10gen.cc/?replicaSet=repl0&srvMaxHosts=1"
#
# The replicaSet URI option is omitted to avoid a URI validation error.
uri: "mongodb+srv://test1.test.build.10gen.cc/?srvMaxHosts=1"
numSeeds: 1
hosts:
- localhost:27017
- localhost:27018
- localhost:27019
options:
replicaSet: repl0
srvMaxHosts: 1
ssl: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"uri": "mongodb+srv://test5.test.build.10gen.cc/?srvMaxHosts=0",
"seeds": [
"localhost.test.build.10gen.cc:27017"
],
"hosts": [
"localhost:27017",
"localhost:27018",
"localhost:27019"
],
"options": {
"authSource": "thisDB",
"replicaSet": "repl0",
"srvMaxHosts": 0,
"ssl": true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# When srvMaxHosts is zero, all hosts are added to the seed list.
#
# replicaSet (TXT) is permitted because srvMaxHosts is non-positive.
uri: "mongodb+srv://test5.test.build.10gen.cc/?srvMaxHosts=0"
seeds:
- localhost.test.build.10gen.cc:27017
hosts:
- localhost:27017
- localhost:27018
- localhost:27019
options:
authSource: thisDB
replicaSet: repl0
srvMaxHosts: 0
ssl: true
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# When srvMaxHosts is zero, all hosts are added to the seed list.
#
# replicaSet is permitted because srvMaxHosts is non-positive.
uri: "mongodb+srv://test1.test.build.10gen.cc/?replicaSet=repl0&srvMaxHosts=0"
seeds:
- localhost.test.build.10gen.cc:27017
Expand Down
5 changes: 1 addition & 4 deletions data/uri-options/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ 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.
- ``valid``: A boolean indicating if the URI should be considered valid.
- ``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 ``~``.
Expand Down
72 changes: 72 additions & 0 deletions data/uri-options/srv-options.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@
"srvMaxHosts": 2
}
},
{
"description": "SRV URI with negative integer for srvMaxHosts",
"uri": "mongodb+srv://test1.test.build.10gen.cc/?srvMaxHosts=-1",
"valid": false,
"warning": true,
"hosts": null,
"auth": null,
"options": {}
},
{
"description": "SRV URI with invalid type for srvMaxHosts",
"uri": "mongodb+srv://test1.test.build.10gen.cc/?srvMaxHosts=foo",
"valid": false,
"warning": true,
"hosts": null,
"auth": null,
"options": {}
},
{
"description": "Non-SRV URI with srvMaxHosts",
"uri": "mongodb://example.com/?srvMaxHosts=2",
Expand All @@ -39,6 +57,60 @@
"hosts": null,
"auth": null,
"options": {}
},
{
"description": "SRV URI with positive srvMaxHosts and replicaSet",
"uri": "mongodb+srv://test1.test.build.10gen.cc/?srvMaxHosts=2&replicaSet=foo",
"valid": false,
"warning": true,
"hosts": null,
"auth": null,
"options": {}
},
{
"description": "SRV URI with positive srvMaxHosts and loadBalanced=true",
"uri": "mongodb+srv://test1.test.build.10gen.cc/?srvMaxHosts=2&loadBalanced=true",
"valid": false,
"warning": true,
"hosts": null,
"auth": null,
"options": {}
},
{
"description": "SRV URI with positive srvMaxHosts and loadBalanced=false",
"uri": "mongodb+srv://test1.test.build.10gen.cc/?srvMaxHosts=2&loadBalanced=false",
"valid": true,
"warning": false,
"hosts": null,
"auth": null,
"options": {
"loadBalanced": false,
"srvMaxHosts": 2
}
},
{
"description": "SRV URI with srvMaxHosts=0 and replicaSet",
"uri": "mongodb+srv://test1.test.build.10gen.cc/?srvMaxHosts=0&replicaSet=foo",
"valid": true,
"warning": false,
"hosts": null,
"auth": null,
"options": {
"replicaSet": "foo",
"srvMaxHosts": 0
}
},
{
"description": "SRV URI with srvMaxHosts=0 and loadBalanced=true",
"uri": "mongodb+srv://test3.test.build.10gen.cc/?srvMaxHosts=0&loadBalanced=true",
"valid": true,
"warning": false,
"hosts": null,
"auth": null,
"options": {
"loadBalanced": true,
"srvMaxHosts": 0
}
}
]
}
Loading