@@ -87,7 +87,7 @@ def is_server_resolvable():
8787 SERVER_IS_RESOLVABLE = is_server_resolvable ()
8888
8989
90- class TestNoSSLModule (unittest .TestCase ):
90+ class TestClientSSL (unittest .TestCase ):
9191
9292 def test_no_ssl_module (self ):
9393 # Test that ConfigurationError is raised if the ssl
@@ -109,20 +109,6 @@ def test_no_ssl_module(self):
109109 self .assertRaises (ConfigurationError ,
110110 MongoReplicaSetClient , ssl_certfile = CLIENT_PEM )
111111
112-
113- class TestSSL (unittest .TestCase ):
114-
115- def setUp (self ):
116- if not HAS_SSL :
117- raise SkipTest ("The ssl module is not available." )
118-
119- if sys .version .startswith ('3.0' ):
120- raise SkipTest ("Python 3.0.x has problems "
121- "with SSL and socket timeouts." )
122-
123- if not SIMPLE_SSL :
124- raise SkipTest ("No simple mongod available over SSL" )
125-
126112 def test_config_ssl (self ):
127113 """Tests various ssl configurations"""
128114 self .assertRaises (ConfigurationError , MongoClient , ssl = 'foo' )
@@ -187,6 +173,20 @@ def test_config_ssl(self):
187173 ssl_keyfile = CLIENT_PEM ,
188174 ssl_certfile = CLIENT_PEM )
189175
176+
177+ class TestSSL (unittest .TestCase ):
178+
179+ def setUp (self ):
180+ if not HAS_SSL :
181+ raise SkipTest ("The ssl module is not available." )
182+
183+ if sys .version .startswith ('3.0' ):
184+ raise SkipTest ("Python 3.0.x has problems "
185+ "with SSL and socket timeouts." )
186+
187+ if not SIMPLE_SSL :
188+ raise SkipTest ("No simple mongod available over SSL" )
189+
190190 def test_simple_ssl (self ):
191191 # Expects the server to be running with ssl and with
192192 # no --sslPEMKeyFile or with --sslWeakCertificateValidation
@@ -279,6 +279,10 @@ def test_cert_ssl_validation(self):
279279 ssl_ca_certs = CA_PEM )
280280 response = client .admin .command ('ismaster' )
281281 if 'setName' in response :
282+ if response ['primary' ].split (":" )[0 ] != 'server' :
283+ raise SkipTest ("No hosts in the replicaset for 'server'. "
284+ "Cannot validate hostname in the certificate" )
285+
282286 client = MongoReplicaSetClient ('server' ,
283287 replicaSet = response ['setName' ],
284288 w = len (response ['hosts' ]),
@@ -314,8 +318,13 @@ def test_cert_ssl_validation_optional(self):
314318 ssl_certfile = CLIENT_PEM ,
315319 ssl_cert_reqs = ssl .CERT_OPTIONAL ,
316320 ssl_ca_certs = CA_PEM )
321+
317322 response = client .admin .command ('ismaster' )
318323 if 'setName' in response :
324+ if response ['primary' ].split (":" )[0 ] != 'server' :
325+ raise SkipTest ("No hosts in the replicaset for 'server'. "
326+ "Cannot validate hostname in the certificate" )
327+
319328 client = MongoReplicaSetClient ('server' ,
320329 replicaSet = response ['setName' ],
321330 w = len (response ['hosts' ]),
0 commit comments