@@ -301,7 +301,8 @@ def handle_error(self):
301301
302302if ssl is not None :
303303
304- CERTFILE = os .path .join (os .path .dirname (__file__ ), "keycert.pem" )
304+ CERTFILE = os .path .join (os .path .dirname (__file__ ), "keycert3.pem" )
305+ CAFILE = os .path .join (os .path .dirname (__file__ ), "pycacert.pem" )
305306
306307 class SSLConnection (asyncore .dispatcher ):
307308 """An asyncore.dispatcher subclass supporting TLS/SSL."""
@@ -923,6 +924,36 @@ def test_ccc(self):
923924 self .client .ccc ()
924925 self .assertRaises (ValueError , self .client .sock .unwrap )
925926
927+ def test_check_hostname (self ):
928+ self .client .quit ()
929+ ctx = ssl .SSLContext (ssl .PROTOCOL_TLSv1 )
930+ ctx .verify_mode = ssl .CERT_REQUIRED
931+ ctx .check_hostname = True
932+ ctx .load_verify_locations (CAFILE )
933+ self .client = ftplib .FTP_TLS (context = ctx , timeout = TIMEOUT )
934+
935+ # 127.0.0.1 doesn't match SAN
936+ self .client .connect (self .server .host , self .server .port )
937+ with self .assertRaises (ssl .CertificateError ):
938+ self .client .auth ()
939+ # exception quits connection
940+
941+ self .client .connect (self .server .host , self .server .port )
942+ self .client .prot_p ()
943+ with self .assertRaises (ssl .CertificateError ):
944+ with self .client .transfercmd ("list" ) as sock :
945+ pass
946+ self .client .quit ()
947+
948+ self .client .connect ("localhost" , self .server .port )
949+ self .client .auth ()
950+ self .client .quit ()
951+
952+ self .client .connect ("localhost" , self .server .port )
953+ self .client .prot_p ()
954+ with self .client .transfercmd ("list" ) as sock :
955+ pass
956+
926957
927958class TestTimeouts (TestCase ):
928959
0 commit comments