3030from test .utils import wait_until
3131
3232
33- _TEST_PATH = os .path .join (
33+ TEST_PATH = os .path .join (
3434 os .path .dirname (os .path .realpath (__file__ )), 'srv_seedlist' )
3535
3636class TestDNS (unittest .TestCase ):
@@ -40,14 +40,22 @@ class TestDNS(unittest.TestCase):
4040def create_test (test_case ):
4141
4242 @client_context .require_replica_set
43- @client_context .require_tls
4443 def run_test (self ):
4544 if not _HAVE_DNSPYTHON :
4645 raise unittest .SkipTest ("DNS tests require the dnspython module" )
4746 uri = test_case ['uri' ]
4847 seeds = test_case ['seeds' ]
4948 hosts = test_case ['hosts' ]
5049 options = test_case .get ('options' )
50+ parsed_options = test_case .get ('parsed_options' )
51+ # See DRIVERS-1324, unless tls is explicitly set to False we need TLS.
52+ needs_tls = not (options and (options .get ('ssl' ) == False or
53+ options .get ('tls' ) == False ))
54+ if needs_tls and not client_context .tls :
55+ self .skipTest ('this test requires a TLS cluster' )
56+ if not needs_tls and client_context .tls :
57+ self .skipTest ('this test requires a non-TLS cluster' )
58+
5159 if seeds :
5260 seeds = split_hosts (',' .join (seeds ))
5361 if hosts :
@@ -63,18 +71,27 @@ def run_test(self):
6371 'readPreferenceTags' , opts .pop ('readpreferencetags' ))
6472 opts ['readPreferenceTags' ] = rpts
6573 self .assertEqual (result ['options' ], options )
74+ if parsed_options :
75+ for opt , expected in parsed_options .items ():
76+ if opt == 'user' :
77+ self .assertEqual (result ['username' ], expected )
78+ elif opt == 'password' :
79+ self .assertEqual (result ['password' ], expected )
80+ elif opt == 'auth_database' or opt == 'db' :
81+ self .assertEqual (result ['database' ], expected )
6682
6783 hostname = next (iter (client_context .client .nodes ))[0 ]
6884 # The replica set members must be configured as 'localhost'.
6985 if hostname == 'localhost' :
7086 copts = client_context .default_client_options .copy ()
71- if client_context .tls is True :
72- # Our test certs don't support the SRV hosts used in these tests.
73- copts ['ssl_match_hostname' ] = False
87+ # Remove tls since SRV parsing should add it automatically.
88+ copts .pop ('tls' , None )
89+ if client_context .tls :
90+ # Our test certs don't support the SRV hosts used in these
91+ # tests.
92+ copts ['tlsAllowInvalidHostnames' ] = True
7493
7594 client = MongoClient (uri , ** copts )
76- # Force server selection
77- client .admin .command ('ismaster' )
7895 wait_until (
7996 lambda : hosts == client .nodes ,
8097 'match test hosts to client nodes' )
@@ -90,7 +107,7 @@ def run_test(self):
90107
91108
92109def create_tests ():
93- for filename in glob .glob (os .path .join (_TEST_PATH , '*.json' )):
110+ for filename in glob .glob (os .path .join (TEST_PATH , '*.json' )):
94111 test_suffix , _ = os .path .splitext (os .path .basename (filename ))
95112 with open (filename ) as dns_test_file :
96113 test_method = create_test (json .load (dns_test_file ))
0 commit comments