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

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

Issue 16510: Using appropriate checks in tests
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/test/test_socket.py ('k') | Lib/test/test_strptime.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 2621 matching lines...) Expand 10 before | Expand all | Expand 10 after
2632 self.assertIn(stats['compression'], { None, 'ZLIB', 'RLE' }) 2632 self.assertIn(stats['compression'], { None, 'ZLIB', 'RLE' })
2633 2633
2634 @unittest.skipUnless(hasattr(ssl, 'OP_NO_COMPRESSION'), 2634 @unittest.skipUnless(hasattr(ssl, 'OP_NO_COMPRESSION'),
2635 "ssl.OP_NO_COMPRESSION needed for this test") 2635 "ssl.OP_NO_COMPRESSION needed for this test")
2636 def test_compression_disabled(self): 2636 def test_compression_disabled(self):
2637 context = ssl.SSLContext(ssl.PROTOCOL_TLSv1) 2637 context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
2638 context.load_cert_chain(CERTFILE) 2638 context.load_cert_chain(CERTFILE)
2639 context.options |= ssl.OP_NO_COMPRESSION 2639 context.options |= ssl.OP_NO_COMPRESSION
2640 stats = server_params_test(context, context, 2640 stats = server_params_test(context, context,
2641 chatty=True, connectionchatty=True) 2641 chatty=True, connectionchatty=True)
2642 self.assertIs(stats['compression'], None) 2642 self.assertIsNone(stats['compression'])
2643 2643
2644 def test_dh_params(self): 2644 def test_dh_params(self):
2645 # Check we can get a connection with ephemeral Diffie-Hellman 2645 # Check we can get a connection with ephemeral Diffie-Hellman
2646 context = ssl.SSLContext(ssl.PROTOCOL_TLSv1) 2646 context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
2647 context.load_cert_chain(CERTFILE) 2647 context.load_cert_chain(CERTFILE)
2648 context.load_dh_params(DHFILE) 2648 context.load_dh_params(DHFILE)
2649 context.set_ciphers("kEDH") 2649 context.set_ciphers("kEDH")
2650 stats = server_params_test(context, context, 2650 stats = server_params_test(context, context,
2651 chatty=True, connectionchatty=True) 2651 chatty=True, connectionchatty=True)
2652 cipher = stats["cipher"][0] 2652 cipher = stats["cipher"][0]
2653 parts = cipher.split("-") 2653 parts = cipher.split("-")
2654 if "ADH" not in parts and "EDH" not in parts and "DHE" not in parts: 2654 if "ADH" not in parts and "EDH" not in parts and "DHE" not in parts:
2655 self.fail("Non-DH cipher: " + cipher[0]) 2655 self.fail("Non-DH cipher: " + cipher[0])
2656 2656
2657 def test_selected_npn_protocol(self): 2657 def test_selected_npn_protocol(self):
2658 # selected_npn_protocol() is None unless NPN is used 2658 # selected_npn_protocol() is None unless NPN is used
2659 context = ssl.SSLContext(ssl.PROTOCOL_TLSv1) 2659 context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
2660 context.load_cert_chain(CERTFILE) 2660 context.load_cert_chain(CERTFILE)
2661 stats = server_params_test(context, context, 2661 stats = server_params_test(context, context,
2662 chatty=True, connectionchatty=True) 2662 chatty=True, connectionchatty=True)
2663 self.assertIs(stats['client_npn_protocol'], None) 2663 self.assertIsNone(stats['client_npn_protocol'])
2664 2664
2665 @unittest.skipUnless(ssl.HAS_NPN, "NPN support needed for this test") 2665 @unittest.skipUnless(ssl.HAS_NPN, "NPN support needed for this test")
2666 def test_npn_protocols(self): 2666 def test_npn_protocols(self):
2667 server_protocols = ['http/1.1', 'spdy/2'] 2667 server_protocols = ['http/1.1', 'spdy/2']
2668 protocol_tests = [ 2668 protocol_tests = [
2669 (['http/1.1', 'spdy/2'], 'http/1.1'), 2669 (['http/1.1', 'spdy/2'], 'http/1.1'),
2670 (['spdy/2', 'http/1.1'], 'http/1.1'), 2670 (['spdy/2', 'http/1.1'], 'http/1.1'),
2671 (['spdy/2', 'test'], 'spdy/2'), 2671 (['spdy/2', 'test'], 'spdy/2'),
2672 (['abc', 'def'], 'abc') 2672 (['abc', 'def'], 'abc')
2673 ] 2673 ]
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
2853 tests.append(ThreadedTests) 2853 tests.append(ThreadedTests)
2854 2854
2855 try: 2855 try:
2856 support.run_unittest(*tests) 2856 support.run_unittest(*tests)
2857 finally: 2857 finally:
2858 if _have_threads: 2858 if _have_threads:
2859 support.threading_cleanup(*thread_info) 2859 support.threading_cleanup(*thread_info)
2860 2860
2861 if __name__ == "__main__": 2861 if __name__ == "__main__":
2862 test_main() 2862 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_socket.py ('k') | Lib/test/test_strptime.py » ('j') | no next file with comments »

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