Back to index

python3.2  3.2.2
Public Member Functions | Private Member Functions
test.test_httplib.HTTPSTest Class Reference
Inheritance diagram for test.test_httplib.HTTPSTest:
Inheritance graph
[legend]
Collaboration diagram for test.test_httplib.HTTPSTest:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def setUp
def make_server
def test_attributes
def test_networked
def test_networked_good_cert
def test_networked_bad_cert
def test_local_good_hostname
def test_local_bad_hostname

Private Member Functions

def _check_svn_python_org

Detailed Description

Definition at line 452 of file test_httplib.py.


Member Function Documentation

def test.test_httplib.HTTPSTest._check_svn_python_org (   self,
  resp 
) [private]

Definition at line 467 of file test_httplib.py.

00467 
00468     def _check_svn_python_org(self, resp):
00469         # Just a simple check that everything went fine
00470         server_string = resp.getheader('server')
00471         self.assertIn('Apache', server_string)

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_httplib.HTTPSTest.make_server (   self,
  certfile 
)

Definition at line 458 of file test_httplib.py.

00458 
00459     def make_server(self, certfile):
00460         from test.ssl_servers import make_https_server
00461         return make_https_server(self, certfile)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 454 of file test_httplib.py.

00454 
00455     def setUp(self):
00456         if not hasattr(client, 'HTTPSConnection'):
00457             self.skipTest('ssl support required')

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 462 of file test_httplib.py.

00462 
00463     def test_attributes(self):
00464         # simple test to check it's storing the timeout
00465         h = client.HTTPSConnection(HOST, TimeoutTest.PORT, timeout=30)
00466         self.assertEqual(h.timeout, 30)

Here is the call graph for this function:

Definition at line 519 of file test_httplib.py.

00519 
00520     def test_local_bad_hostname(self):
00521         # The (valid) cert doesn't validate the HTTP hostname
00522         import ssl
00523         from test.ssl_servers import make_https_server
00524         server = make_https_server(self, CERT_fakehostname)
00525         context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
00526         context.verify_mode = ssl.CERT_REQUIRED
00527         context.load_verify_locations(CERT_fakehostname)
00528         h = client.HTTPSConnection('localhost', server.port, context=context)
00529         with self.assertRaises(ssl.CertificateError):
00530             h.request('GET', '/')
00531         # Same with explicit check_hostname=True
00532         h = client.HTTPSConnection('localhost', server.port, context=context,
00533                                    check_hostname=True)
00534         with self.assertRaises(ssl.CertificateError):
00535             h.request('GET', '/')
00536         # With check_hostname=False, the mismatching is ignored
00537         h = client.HTTPSConnection('localhost', server.port, context=context,
00538                                    check_hostname=False)
00539         h.request('GET', '/nonexistent')
00540         resp = h.getresponse()
00541         self.assertEqual(resp.status, 404)
00542 

Here is the call graph for this function:

Definition at line 506 of file test_httplib.py.

00506 
00507     def test_local_good_hostname(self):
00508         # The (valid) cert validates the HTTP hostname
00509         import ssl
00510         from test.ssl_servers import make_https_server
00511         server = make_https_server(self, CERT_localhost)
00512         context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
00513         context.verify_mode = ssl.CERT_REQUIRED
00514         context.load_verify_locations(CERT_localhost)
00515         h = client.HTTPSConnection('localhost', server.port, context=context)
00516         h.request('GET', '/nonexistent')
00517         resp = h.getresponse()
00518         self.assertEqual(resp.status, 404)

Here is the call graph for this function:

Definition at line 472 of file test_httplib.py.

00472 
00473     def test_networked(self):
00474         # Default settings: no cert verification is done
00475         support.requires('network')
00476         with support.transient_internet('svn.python.org'):
00477             h = client.HTTPSConnection('svn.python.org', 443)
00478             h.request('GET', '/')
00479             resp = h.getresponse()
00480             self._check_svn_python_org(resp)

Here is the call graph for this function:

Definition at line 494 of file test_httplib.py.

00494 
00495     def test_networked_bad_cert(self):
00496         # We feed a "CA" cert that is unrelated to the server's cert
00497         import ssl
00498         support.requires('network')
00499         with support.transient_internet('svn.python.org'):
00500             context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
00501             context.verify_mode = ssl.CERT_REQUIRED
00502             context.load_verify_locations(CERT_localhost)
00503             h = client.HTTPSConnection('svn.python.org', 443, context=context)
00504             with self.assertRaises(ssl.SSLError):
00505                 h.request('GET', '/')

Here is the call graph for this function:

Definition at line 481 of file test_httplib.py.

00481 
00482     def test_networked_good_cert(self):
00483         # We feed a CA cert that validates the server's cert
00484         import ssl
00485         support.requires('network')
00486         with support.transient_internet('svn.python.org'):
00487             context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
00488             context.verify_mode = ssl.CERT_REQUIRED
00489             context.load_verify_locations(CACERT_svn_python_org)
00490             h = client.HTTPSConnection('svn.python.org', 443, context=context)
00491             h.request('GET', '/')
00492             resp = h.getresponse()
00493             self._check_svn_python_org(resp)

Here is the call graph for this function:


The documentation for this class was generated from the following file: