Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(7180)

Side by Side Diff: Lib/test/test_ssl.py

Issue 19689: ssl.create_default_context()
Patch Set: Created 5 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/ssl.py ('k') | Lib/urllib/request.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Test the support for SSL and sockets 1 # Test the support for SSL and sockets
2 2
3 import sys 3 import sys
4 import unittest 4 import unittest
5 from test import support 5 from test import support
6 import socket 6 import socket
7 import select 7 import select
8 import time 8 import time
9 import datetime 9 import datetime
10 import gc 10 import gc
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 self.assertIsInstance(obj.oid, (str, type(None))) 599 self.assertIsInstance(obj.oid, (str, type(None)))
600 600
601 val = ssl._ASN1Object.fromname('TLS Web Server Authentication') 601 val = ssl._ASN1Object.fromname('TLS Web Server Authentication')
602 self.assertEqual(val, expected) 602 self.assertEqual(val, expected)
603 self.assertIsInstance(val, ssl._ASN1Object) 603 self.assertIsInstance(val, ssl._ASN1Object)
604 self.assertEqual(ssl._ASN1Object.fromname('serverAuth'), expected) 604 self.assertEqual(ssl._ASN1Object.fromname('serverAuth'), expected)
605 self.assertEqual(ssl._ASN1Object.fromname('1.3.6.1.5.5.7.3.1'), 605 self.assertEqual(ssl._ASN1Object.fromname('1.3.6.1.5.5.7.3.1'),
606 expected) 606 expected)
607 with self.assertRaisesRegex(ValueError, "unknown object 'serverauth'"): 607 with self.assertRaisesRegex(ValueError, "unknown object 'serverauth'"):
608 ssl._ASN1Object.fromname('serverauth') 608 ssl._ASN1Object.fromname('serverauth')
609
610 def test_create_default_context(self):
611 ctx = ssl.create_default_context()
612 self.assertEqual(ctx.protocol, ssl.PROTOCOL_SSLv23)
613 self.assertEqual(ctx.verify_mode, ssl.CERT_NONE)
614 self.assertEqual(ctx.options & ssl.OP_NO_SSLv2, ssl.OP_NO_SSLv2)
615
616 ctx = ssl.create_default_context(ssl.PROTOCOL_TLSv1)
617 self.assertEqual(ctx.protocol, ssl.PROTOCOL_TLSv1)
618 self.assertEqual(ctx.verify_mode, ssl.CERT_NONE)
619 self.assertEqual(ctx.options & ssl.OP_NO_SSLv2, ssl.OP_NO_SSLv2)
620
621 ctx = ssl.create_default_context(ssl.PROTOCOL_TLSv1_1,
622 cert_reqs=ssl.CERT_REQUIRED)
623 self.assertEqual(ctx.protocol, ssl.PROTOCOL_TLSv1_1)
624 self.assertEqual(ctx.verify_mode, ssl.CERT_REQUIRED)
625 self.assertEqual(ctx.options & ssl.OP_NO_SSLv2, ssl.OP_NO_SSLv2)
626
627 ctx = ssl.create_default_context(certfile=CERTFILE)
628 ctx = ssl.create_default_context(certfile=ONLYCERT,
629 keyfile=ONLYKEY)
630 with self.assertRaises(FileNotFoundError):
631 ssl.create_default_context(certfile=WRONGCERT)
609 632
610 633
611 class ContextTests(unittest.TestCase): 634 class ContextTests(unittest.TestCase):
612 635
613 @skip_if_broken_ubuntu_ssl 636 @skip_if_broken_ubuntu_ssl
614 def test_constructor(self): 637 def test_constructor(self):
615 for protocol in PROTOCOLS: 638 for protocol in PROTOCOLS:
616 ssl.SSLContext(protocol) 639 ssl.SSLContext(protocol)
617 self.assertRaises(TypeError, ssl.SSLContext) 640 self.assertRaises(TypeError, ssl.SSLContext)
618 self.assertRaises(ValueError, ssl.SSLContext, -1) 641 self.assertRaises(ValueError, ssl.SSLContext, -1)
(...skipping 2058 matching lines...) Expand 10 before | Expand all | Expand 10 after
2677 tests.append(ThreadedTests) 2700 tests.append(ThreadedTests)
2678 2701
2679 try: 2702 try:
2680 support.run_unittest(*tests) 2703 support.run_unittest(*tests)
2681 finally: 2704 finally:
2682 if _have_threads: 2705 if _have_threads:
2683 support.threading_cleanup(*thread_info) 2706 support.threading_cleanup(*thread_info)
2684 2707
2685 if __name__ == "__main__": 2708 if __name__ == "__main__":
2686 test_main() 2709 test_main()
OLDNEW
« no previous file with comments | « Lib/ssl.py ('k') | Lib/urllib/request.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+