Back to index

python3.2  3.2.2
Public Member Functions
test.test_ssl.ContextTests Class Reference

List of all members.

Public Member Functions

def test_constructor
def test_protocol
def test_ciphers
def test_options
def test_verify
def test_load_cert_chain
def test_load_verify_locations
def test_session_stats
def test_set_default_verify_paths

Detailed Description

Definition at line 314 of file test_ssl.py.


Member Function Documentation

Definition at line 333 of file test_ssl.py.

00333 
00334     def test_ciphers(self):
00335         ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
00336         ctx.set_ciphers("ALL")
00337         ctx.set_ciphers("DEFAULT")
00338         with self.assertRaisesRegex(ssl.SSLError, "No cipher can be selected"):
00339             ctx.set_ciphers("^$:,;?*'dorothyx")

Here is the call graph for this function:

Definition at line 317 of file test_ssl.py.

00317 
00318     def test_constructor(self):
00319         if hasattr(ssl, 'PROTOCOL_SSLv2'):
00320             ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv2)
00321         ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
00322         ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv3)
00323         ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
00324         self.assertRaises(TypeError, ssl.SSLContext)
00325         self.assertRaises(ValueError, ssl.SSLContext, -1)
00326         self.assertRaises(ValueError, ssl.SSLContext, 42)

Here is the call graph for this function:

Definition at line 376 of file test_ssl.py.

00376 
00377     def test_load_cert_chain(self):
00378         ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
00379         # Combined key and cert in a single file
00380         ctx.load_cert_chain(CERTFILE)
00381         ctx.load_cert_chain(CERTFILE, keyfile=CERTFILE)
00382         self.assertRaises(TypeError, ctx.load_cert_chain, keyfile=CERTFILE)
00383         with self.assertRaises(IOError) as cm:
00384             ctx.load_cert_chain(WRONGCERT)
00385         self.assertEqual(cm.exception.errno, errno.ENOENT)
00386         with self.assertRaisesRegex(ssl.SSLError, "PEM lib"):
00387             ctx.load_cert_chain(BADCERT)
00388         with self.assertRaisesRegex(ssl.SSLError, "PEM lib"):
00389             ctx.load_cert_chain(EMPTYCERT)
00390         # Separate key and cert
00391         ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
00392         ctx.load_cert_chain(ONLYCERT, ONLYKEY)
00393         ctx.load_cert_chain(certfile=ONLYCERT, keyfile=ONLYKEY)
00394         ctx.load_cert_chain(certfile=BYTES_ONLYCERT, keyfile=BYTES_ONLYKEY)
00395         with self.assertRaisesRegex(ssl.SSLError, "PEM lib"):
00396             ctx.load_cert_chain(ONLYCERT)
00397         with self.assertRaisesRegex(ssl.SSLError, "PEM lib"):
00398             ctx.load_cert_chain(ONLYKEY)
00399         with self.assertRaisesRegex(ssl.SSLError, "PEM lib"):
00400             ctx.load_cert_chain(certfile=ONLYKEY, keyfile=ONLYCERT)
00401         # Mismatching key and cert
00402         ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
00403         with self.assertRaisesRegex(ssl.SSLError, "key values mismatch"):
00404             ctx.load_cert_chain(SVN_PYTHON_ORG_ROOT_CERT, ONLYKEY)

Here is the call graph for this function:

Definition at line 405 of file test_ssl.py.

00405 
00406     def test_load_verify_locations(self):
00407         ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
00408         ctx.load_verify_locations(CERTFILE)
00409         ctx.load_verify_locations(cafile=CERTFILE, capath=None)
00410         ctx.load_verify_locations(BYTES_CERTFILE)
00411         ctx.load_verify_locations(cafile=BYTES_CERTFILE, capath=None)
00412         self.assertRaises(TypeError, ctx.load_verify_locations)
00413         self.assertRaises(TypeError, ctx.load_verify_locations, None, None)
00414         with self.assertRaises(IOError) as cm:
00415             ctx.load_verify_locations(WRONGCERT)
00416         self.assertEqual(cm.exception.errno, errno.ENOENT)
00417         with self.assertRaisesRegex(ssl.SSLError, "PEM lib"):
00418             ctx.load_verify_locations(BADCERT)
00419         ctx.load_verify_locations(CERTFILE, CAPATH)
00420         ctx.load_verify_locations(CERTFILE, capath=BYTES_CAPATH)
00421 
00422         # Issue #10989: crash if the second argument type is invalid
00423         self.assertRaises(TypeError, ctx.load_verify_locations, None, True)

Here is the call graph for this function:

Definition at line 341 of file test_ssl.py.

00341 
00342     def test_options(self):
00343         ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
00344         # OP_ALL is the default value
00345         self.assertEqual(ssl.OP_ALL, ctx.options)
00346         ctx.options |= ssl.OP_NO_SSLv2
00347         self.assertEqual(ssl.OP_ALL | ssl.OP_NO_SSLv2,
00348                          ctx.options)
00349         ctx.options |= ssl.OP_NO_SSLv3
00350         self.assertEqual(ssl.OP_ALL | ssl.OP_NO_SSLv2 | ssl.OP_NO_SSLv3,
00351                          ctx.options)
00352         if can_clear_options():
00353             ctx.options = (ctx.options & ~ssl.OP_NO_SSLv2) | ssl.OP_NO_TLSv1
00354             self.assertEqual(ssl.OP_ALL | ssl.OP_NO_TLSv1 | ssl.OP_NO_SSLv3,
00355                              ctx.options)
00356             ctx.options = 0
00357             self.assertEqual(0, ctx.options)
00358         else:
00359             with self.assertRaises(ValueError):
00360                 ctx.options = 0

Here is the call graph for this function:

Definition at line 328 of file test_ssl.py.

00328 
00329     def test_protocol(self):
00330         for proto in PROTOCOLS:
00331             ctx = ssl.SSLContext(proto)
00332             self.assertEqual(ctx.protocol, proto)

Here is the call graph for this function:

Definition at line 425 of file test_ssl.py.

00425 
00426     def test_session_stats(self):
00427         for proto in PROTOCOLS:
00428             ctx = ssl.SSLContext(proto)
00429             self.assertEqual(ctx.session_stats(), {
00430                 'number': 0,
00431                 'connect': 0,
00432                 'connect_good': 0,
00433                 'connect_renegotiate': 0,
00434                 'accept': 0,
00435                 'accept_good': 0,
00436                 'accept_renegotiate': 0,
00437                 'hits': 0,
00438                 'misses': 0,
00439                 'timeouts': 0,
00440                 'cache_full': 0,
00441             })

Here is the call graph for this function:

Definition at line 442 of file test_ssl.py.

00442 
00443     def test_set_default_verify_paths(self):
00444         # There's not much we can do to test that it acts as expected,
00445         # so just check it doesn't crash or raise an exception.
00446         ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
00447         ctx.set_default_verify_paths()
00448 

Definition at line 361 of file test_ssl.py.

00361 
00362     def test_verify(self):
00363         ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
00364         # Default value
00365         self.assertEqual(ctx.verify_mode, ssl.CERT_NONE)
00366         ctx.verify_mode = ssl.CERT_OPTIONAL
00367         self.assertEqual(ctx.verify_mode, ssl.CERT_OPTIONAL)
00368         ctx.verify_mode = ssl.CERT_REQUIRED
00369         self.assertEqual(ctx.verify_mode, ssl.CERT_REQUIRED)
00370         ctx.verify_mode = ssl.CERT_NONE
00371         self.assertEqual(ctx.verify_mode, ssl.CERT_NONE)
00372         with self.assertRaises(TypeError):
00373             ctx.verify_mode = None
00374         with self.assertRaises(ValueError):
00375             ctx.verify_mode = 42

Here is the call graph for this function:


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