Skip to content

Commit 0a5054e

Browse files
authored
GODRIVER-2092 Disallow positive srvMaxHosts with replicaSet or loadBalanced=true (#767)
1 parent 2fa2b7c commit 0a5054e

29 files changed

+331
-22
lines changed

data/initial-dns-seedlist-discovery/README.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ load-balanced sharded cluster with the mongos servers running on localhost ports
1717
27017 and 27018 (corresponding to the script in `drivers-evergreen-tools`_). The
1818
load balancers, shard servers, and config servers may run on any open ports.
1919

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

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

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

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

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

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

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"uri": "mongodb+srv://test20.test.build.10gen.cc/?srvMaxHosts=1",
3+
"seeds": [],
4+
"hosts": [],
5+
"error": true,
6+
"comment": "Should fail because positive integer for srvMaxHosts conflicts with loadBalanced=true (TXT)"
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
uri: "mongodb+srv://test20.test.build.10gen.cc/?srvMaxHosts=1"
2+
seeds: []
3+
hosts: []
4+
error: true
5+
comment: Should fail because positive integer for srvMaxHosts conflicts with loadBalanced=true (TXT)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"uri": "mongodb+srv://test3.test.build.10gen.cc/?loadBalanced=true&srvMaxHosts=1",
3+
"seeds": [],
4+
"hosts": [],
5+
"error": true,
6+
"comment": "Should fail because positive integer for srvMaxHosts conflicts with loadBalanced=true"
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
uri: "mongodb+srv://test3.test.build.10gen.cc/?loadBalanced=true&srvMaxHosts=1"
2+
seeds: []
3+
hosts: []
4+
error: true
5+
comment: Should fail because positive integer for srvMaxHosts conflicts with loadBalanced=true
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"uri": "mongodb+srv://test20.test.build.10gen.cc/?srvMaxHosts=0",
3+
"seeds": [
4+
"localhost.test.build.10gen.cc:27017"
5+
],
6+
"hosts": [
7+
"localhost.test.build.10gen.cc:27017"
8+
],
9+
"options": {
10+
"loadBalanced": true,
11+
"srvMaxHosts": 0,
12+
"ssl": true
13+
}
14+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# loadBalanced=true (TXT) is permitted because srvMaxHosts is non-positive
2+
uri: "mongodb+srv://test20.test.build.10gen.cc/?srvMaxHosts=0"
3+
seeds:
4+
- localhost.test.build.10gen.cc:27017
5+
hosts:
6+
- localhost.test.build.10gen.cc:27017
7+
options:
8+
loadBalanced: true
9+
srvMaxHosts: 0
10+
ssl: true
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"uri": "mongodb+srv://test3.test.build.10gen.cc/?loadBalanced=true&srvMaxHosts=0",
3+
"seeds": [
4+
"localhost.test.build.10gen.cc:27017"
5+
],
6+
"hosts": [
7+
"localhost.test.build.10gen.cc:27017"
8+
],
9+
"options": {
10+
"loadBalanced": true,
11+
"srvMaxHosts": 0,
12+
"ssl": true
13+
}
14+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# loadBalanced=true is permitted because srvMaxHosts is non-positive
2+
uri: "mongodb+srv://test3.test.build.10gen.cc/?loadBalanced=true&srvMaxHosts=0"
3+
seeds:
4+
- localhost.test.build.10gen.cc:27017
5+
hosts:
6+
- localhost.test.build.10gen.cc:27017
7+
options:
8+
loadBalanced: true
9+
srvMaxHosts: 0
10+
ssl: true
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"uri": "mongodb+srv://test5.test.build.10gen.cc/?srvMaxHosts=1",
3+
"seeds": [],
4+
"hosts": [],
5+
"error": true,
6+
"comment": "Should fail because positive integer for srvMaxHosts conflicts with replicaSet option (TXT)"
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
uri: "mongodb+srv://test5.test.build.10gen.cc/?srvMaxHosts=1"
2+
seeds: []
3+
hosts: []
4+
error: true
5+
comment: Should fail because positive integer for srvMaxHosts conflicts with replicaSet option (TXT)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"uri": "mongodb+srv://test1.test.build.10gen.cc/?replicaSet=repl0&srvMaxHosts=1",
3+
"seeds": [],
4+
"hosts": [],
5+
"error": true,
6+
"comment": "Should fail because positive integer for srvMaxHosts conflicts with replicaSet option"
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
uri: "mongodb+srv://test1.test.build.10gen.cc/?replicaSet=repl0&srvMaxHosts=1"
2+
seeds: []
3+
hosts: []
4+
error: true
5+
comment: Should fail because positive integer for srvMaxHosts conflicts with replicaSet option

data/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-equal_to_srv_records.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"uri": "mongodb+srv://test1.test.build.10gen.cc/?replicaSet=repl0&srvMaxHosts=2",
2+
"uri": "mongodb+srv://test1.test.build.10gen.cc/?srvMaxHosts=2",
33
"numSeeds": 2,
44
"seeds": [
55
"localhost.test.build.10gen.cc:27017",
@@ -11,7 +11,6 @@
1111
"localhost:27019"
1212
],
1313
"options": {
14-
"replicaSet": "repl0",
1514
"srvMaxHosts": 2,
1615
"ssl": true
1716
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# When srvMaxHosts equals the number of SRV records, all hosts are added to the
22
# seed list.
3-
uri: "mongodb+srv://test1.test.build.10gen.cc/?replicaSet=repl0&srvMaxHosts=2"
3+
#
4+
# The replicaSet URI option is omitted to avoid a URI validation error.
5+
uri: "mongodb+srv://test1.test.build.10gen.cc/?srvMaxHosts=2"
46
numSeeds: 2
57
seeds:
68
- localhost.test.build.10gen.cc:27017
@@ -10,6 +12,5 @@ hosts:
1012
- localhost:27018
1113
- localhost:27019
1214
options:
13-
replicaSet: repl0
1415
srvMaxHosts: 2
1516
ssl: true

data/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-greater_than_srv_records.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"uri": "mongodb+srv://test1.test.build.10gen.cc/?replicaSet=repl0&srvMaxHosts=3",
2+
"uri": "mongodb+srv://test1.test.build.10gen.cc/?srvMaxHosts=3",
33
"seeds": [
44
"localhost.test.build.10gen.cc:27017",
55
"localhost.test.build.10gen.cc:27018"
@@ -10,7 +10,6 @@
1010
"localhost:27019"
1111
],
1212
"options": {
13-
"replicaSet": "repl0",
1413
"srvMaxHosts": 3,
1514
"ssl": true
1615
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# When srvMaxHosts is greater than the number of SRV records, all hosts are
22
# added to the seed list.
3-
uri: "mongodb+srv://test1.test.build.10gen.cc/?replicaSet=repl0&srvMaxHosts=3"
3+
#
4+
# The replicaSet URI option is omitted to avoid a URI validation error.
5+
uri: "mongodb+srv://test1.test.build.10gen.cc/?srvMaxHosts=3"
46
seeds:
57
- localhost.test.build.10gen.cc:27017
68
- localhost.test.build.10gen.cc:27018
@@ -9,6 +11,5 @@ hosts:
911
- localhost:27018
1012
- localhost:27019
1113
options:
12-
replicaSet: repl0
1314
srvMaxHosts: 3
1415
ssl: true

data/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-less_than_srv_records.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
{
2-
"uri": "mongodb+srv://test1.test.build.10gen.cc/?replicaSet=repl0&srvMaxHosts=1",
2+
"uri": "mongodb+srv://test1.test.build.10gen.cc/?srvMaxHosts=1",
33
"numSeeds": 1,
44
"hosts": [
55
"localhost:27017",
66
"localhost:27018",
77
"localhost:27019"
88
],
99
"options": {
10-
"replicaSet": "repl0",
1110
"srvMaxHosts": 1,
1211
"ssl": true
1312
}

data/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-less_than_srv_records.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
# hosts are added to the seed list. We cannot anticipate which hosts will be
33
# selected, so this test uses numSeeds instead of seeds. Since this is a replica
44
# set, all hosts should ultimately be discovered by SDAM.
5-
uri: "mongodb+srv://test1.test.build.10gen.cc/?replicaSet=repl0&srvMaxHosts=1"
5+
#
6+
# The replicaSet URI option is omitted to avoid a URI validation error.
7+
uri: "mongodb+srv://test1.test.build.10gen.cc/?srvMaxHosts=1"
68
numSeeds: 1
79
hosts:
810
- localhost:27017
911
- localhost:27018
1012
- localhost:27019
1113
options:
12-
replicaSet: repl0
1314
srvMaxHosts: 1
1415
ssl: true
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"uri": "mongodb+srv://test5.test.build.10gen.cc/?srvMaxHosts=0",
3+
"seeds": [
4+
"localhost.test.build.10gen.cc:27017"
5+
],
6+
"hosts": [
7+
"localhost:27017",
8+
"localhost:27018",
9+
"localhost:27019"
10+
],
11+
"options": {
12+
"authSource": "thisDB",
13+
"replicaSet": "repl0",
14+
"srvMaxHosts": 0,
15+
"ssl": true
16+
}
17+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# When srvMaxHosts is zero, all hosts are added to the seed list.
2+
#
3+
# replicaSet (TXT) is permitted because srvMaxHosts is non-positive.
4+
uri: "mongodb+srv://test5.test.build.10gen.cc/?srvMaxHosts=0"
5+
seeds:
6+
- localhost.test.build.10gen.cc:27017
7+
hosts:
8+
- localhost:27017
9+
- localhost:27018
10+
- localhost:27019
11+
options:
12+
authSource: thisDB
13+
replicaSet: repl0
14+
srvMaxHosts: 0
15+
ssl: true

data/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-zero.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# When srvMaxHosts is zero, all hosts are added to the seed list.
2+
#
3+
# replicaSet is permitted because srvMaxHosts is non-positive.
24
uri: "mongodb+srv://test1.test.build.10gen.cc/?replicaSet=repl0&srvMaxHosts=0"
35
seeds:
46
- localhost.test.build.10gen.cc:27017

data/uri-options/README.rst

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ array of test case objects, each of which have the following keys:
2121

2222
- ``description``: A string describing the test.
2323
- ``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.
24+
- ``valid``: A boolean indicating if the URI should be considered valid.
2825
- ``warning``: A boolean indicating whether URI parsing should emit a warning.
2926
- ``hosts``: Included for compatibility with the Connection String spec tests. This will always be ``~``.
3027
- ``auth``: Included for compatibility with the Connection String spec tests. This will always be ``~``.

data/uri-options/srv-options.json

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,24 @@
3131
"srvMaxHosts": 2
3232
}
3333
},
34+
{
35+
"description": "SRV URI with negative integer for srvMaxHosts",
36+
"uri": "mongodb+srv://test1.test.build.10gen.cc/?srvMaxHosts=-1",
37+
"valid": false,
38+
"warning": true,
39+
"hosts": null,
40+
"auth": null,
41+
"options": {}
42+
},
43+
{
44+
"description": "SRV URI with invalid type for srvMaxHosts",
45+
"uri": "mongodb+srv://test1.test.build.10gen.cc/?srvMaxHosts=foo",
46+
"valid": false,
47+
"warning": true,
48+
"hosts": null,
49+
"auth": null,
50+
"options": {}
51+
},
3452
{
3553
"description": "Non-SRV URI with srvMaxHosts",
3654
"uri": "mongodb://example.com/?srvMaxHosts=2",
@@ -39,6 +57,60 @@
3957
"hosts": null,
4058
"auth": null,
4159
"options": {}
60+
},
61+
{
62+
"description": "SRV URI with positive srvMaxHosts and replicaSet",
63+
"uri": "mongodb+srv://test1.test.build.10gen.cc/?srvMaxHosts=2&replicaSet=foo",
64+
"valid": false,
65+
"warning": true,
66+
"hosts": null,
67+
"auth": null,
68+
"options": {}
69+
},
70+
{
71+
"description": "SRV URI with positive srvMaxHosts and loadBalanced=true",
72+
"uri": "mongodb+srv://test1.test.build.10gen.cc/?srvMaxHosts=2&loadBalanced=true",
73+
"valid": false,
74+
"warning": true,
75+
"hosts": null,
76+
"auth": null,
77+
"options": {}
78+
},
79+
{
80+
"description": "SRV URI with positive srvMaxHosts and loadBalanced=false",
81+
"uri": "mongodb+srv://test1.test.build.10gen.cc/?srvMaxHosts=2&loadBalanced=false",
82+
"valid": true,
83+
"warning": false,
84+
"hosts": null,
85+
"auth": null,
86+
"options": {
87+
"loadBalanced": false,
88+
"srvMaxHosts": 2
89+
}
90+
},
91+
{
92+
"description": "SRV URI with srvMaxHosts=0 and replicaSet",
93+
"uri": "mongodb+srv://test1.test.build.10gen.cc/?srvMaxHosts=0&replicaSet=foo",
94+
"valid": true,
95+
"warning": false,
96+
"hosts": null,
97+
"auth": null,
98+
"options": {
99+
"replicaSet": "foo",
100+
"srvMaxHosts": 0
101+
}
102+
},
103+
{
104+
"description": "SRV URI with srvMaxHosts=0 and loadBalanced=true",
105+
"uri": "mongodb+srv://test3.test.build.10gen.cc/?srvMaxHosts=0&loadBalanced=true",
106+
"valid": true,
107+
"warning": false,
108+
"hosts": null,
109+
"auth": null,
110+
"options": {
111+
"loadBalanced": true,
112+
"srvMaxHosts": 0
113+
}
42114
}
43115
]
44116
}

0 commit comments

Comments
 (0)