Skip to content
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
21 changes: 21 additions & 0 deletions test/srv_seedlist/encoded-userinfo-and-db.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"uri": "mongodb+srv://b*b%40f3tt%3D:%244to%40L8%3DMC@test3.test.build.10gen.cc/mydb%3F?replicaSet=repl0",
"seeds": [
"localhost.test.build.10gen.cc:27017"
],
"hosts": [
"localhost:27017",
"localhost:27018",
"localhost:27019"
],
"options": {
"replicaSet": "repl0",
"ssl": true
},
"parsed_options": {
"user": "b*b@f3tt=",
"password": "$4to@L8=MC",
"db": "mydb?"
},
"comment": "Encoded user, pass, and DB parse correctly"
}
7 changes: 7 additions & 0 deletions test/srv_seedlist/txt-record-not-allowed-option.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"uri": "mongodb+srv://test10.test.build.10gen.cc/?replicaSet=repl0",
"seeds": [],
"hosts": [],
"error": true,
"comment": "Should fail because socketTimeoutMS is not an allowed option."
}
16 changes: 16 additions & 0 deletions test/srv_seedlist/txt-record-with-overridden-ssl-option.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"uri": "mongodb+srv://test5.test.build.10gen.cc/?ssl=false",
"seeds": [
"localhost.test.build.10gen.cc:27017"
],
"hosts": [
"localhost:27017",
"localhost:27018",
"localhost:27019"
],
"options": {
"replicaSet": "repl0",
"authSource": "thisDB",
"ssl": false
}
}
19 changes: 19 additions & 0 deletions test/srv_seedlist/uri-with-admin-database.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"uri": "mongodb+srv://test1.test.build.10gen.cc/adminDB?replicaSet=repl0",
"seeds": [
"localhost.test.build.10gen.cc:27017",
"localhost.test.build.10gen.cc:27018"
],
"hosts": [
"localhost:27017",
"localhost:27018",
"localhost:27019"
],
"options": {
"replicaSet": "repl0",
"ssl": true
},
"parsed_options": {
"auth_database": "adminDB"
}
}
17 changes: 17 additions & 0 deletions test/srv_seedlist/uri-with-auth.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"uri": "mongodb+srv://auser:apass@test1.test.build.10gen.cc/?replicaSet=repl0",
"seeds": [
"localhost.test.build.10gen.cc:27017",
"localhost.test.build.10gen.cc:27018"
],
"hosts": [
"localhost:27017",
"localhost:27018",
"localhost:27019"
],
"parsed_options": {
"user": "auser",
"password": "apass"
},
"comment": "Should preserve auth credentials"
}
33 changes: 25 additions & 8 deletions test/test_dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from test.utils import wait_until


_TEST_PATH = os.path.join(
TEST_PATH = os.path.join(
os.path.dirname(os.path.realpath(__file__)), 'srv_seedlist')

class TestDNS(unittest.TestCase):
Expand All @@ -40,14 +40,22 @@ class TestDNS(unittest.TestCase):
def create_test(test_case):

@client_context.require_replica_set
@client_context.require_tls
def run_test(self):
if not _HAVE_DNSPYTHON:
raise unittest.SkipTest("DNS tests require the dnspython module")
uri = test_case['uri']
seeds = test_case['seeds']
hosts = test_case['hosts']
options = test_case.get('options')
parsed_options = test_case.get('parsed_options')
# See DRIVERS-1324, unless tls is explicitly set to False we need TLS.
needs_tls = not (options and (options.get('ssl') == False or
options.get('tls') == False))
if needs_tls and not client_context.tls:
self.skipTest('this test requires a TLS cluster')
if not needs_tls and client_context.tls:
self.skipTest('this test requires a non-TLS cluster')

if seeds:
seeds = split_hosts(','.join(seeds))
if hosts:
Expand All @@ -63,18 +71,27 @@ def run_test(self):
'readPreferenceTags', opts.pop('readpreferencetags'))
opts['readPreferenceTags'] = rpts
self.assertEqual(result['options'], options)
if parsed_options:
for opt, expected in parsed_options.items():
if opt == 'user':
self.assertEqual(result['username'], expected)
elif opt == 'password':
self.assertEqual(result['password'], expected)
elif opt == 'auth_database' or opt == 'db':
self.assertEqual(result['database'], expected)

hostname = next(iter(client_context.client.nodes))[0]
# The replica set members must be configured as 'localhost'.
if hostname == 'localhost':
copts = client_context.default_client_options.copy()
if client_context.tls is True:
# Our test certs don't support the SRV hosts used in these tests.
copts['ssl_match_hostname'] = False
# Remove tls since SRV parsing should add it automatically.
copts.pop('tls', None)
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't this pose another problem? Since kwargs override opts passed in the URI, we might be overriding what the test wants to pass? Should we check the keys in result to ensure that none of them matches keys in copts?

Copy link
Member Author

Choose a reason for hiding this comment

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

The only test that does this is the ssl=false test which is handled by the needs_tls logic above. So I don't think there's any issue here.

if client_context.tls:
# Our test certs don't support the SRV hosts used in these
# tests.
copts['tlsAllowInvalidHostnames'] = True

client = MongoClient(uri, **copts)
# Force server selection
client.admin.command('ismaster')
wait_until(
lambda: hosts == client.nodes,
'match test hosts to client nodes')
Expand All @@ -90,7 +107,7 @@ def run_test(self):


def create_tests():
for filename in glob.glob(os.path.join(_TEST_PATH, '*.json')):
for filename in glob.glob(os.path.join(TEST_PATH, '*.json')):
test_suffix, _ = os.path.splitext(os.path.basename(filename))
with open(filename) as dns_test_file:
test_method = create_test(json.load(dns_test_file))
Expand Down