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

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

Issue 16510: Using appropriate checks in tests
Patch Set: Created 6 years, 4 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 2239 matching lines...) Expand 10 before | Expand all | Expand 10 after
2250 self.assertIn(stats['compression'], { None, 'ZLIB', 'RLE' }) 2250 self.assertIn(stats['compression'], { None, 'ZLIB', 'RLE' })
2251 2251
2252 @unittest.skipUnless(hasattr(ssl, 'OP_NO_COMPRESSION'), 2252 @unittest.skipUnless(hasattr(ssl, 'OP_NO_COMPRESSION'),
2253 "ssl.OP_NO_COMPRESSION needed for this test") 2253 "ssl.OP_NO_COMPRESSION needed for this test")
2254 def test_compression_disabled(self): 2254 def test_compression_disabled(self):
2255 context = ssl.SSLContext(ssl.PROTOCOL_TLSv1) 2255 context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
2256 context.load_cert_chain(CERTFILE) 2256 context.load_cert_chain(CERTFILE)
2257 context.options |= ssl.OP_NO_COMPRESSION 2257 context.options |= ssl.OP_NO_COMPRESSION
2258 stats = server_params_test(context, context, 2258 stats = server_params_test(context, context,
2259 chatty=True, connectionchatty=True) 2259 chatty=True, connectionchatty=True)
2260 self.assertIs(stats['compression'], None) 2260 self.assertIsNone(stats['compression'])
2261 2261
2262 def test_dh_params(self): 2262 def test_dh_params(self):
2263 # Check we can get a connection with ephemeral Diffie-Hellman 2263 # Check we can get a connection with ephemeral Diffie-Hellman
2264 context = ssl.SSLContext(ssl.PROTOCOL_TLSv1) 2264 context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
2265 context.load_cert_chain(CERTFILE) 2265 context.load_cert_chain(CERTFILE)
2266 context.load_dh_params(DHFILE) 2266 context.load_dh_params(DHFILE)
2267 context.set_ciphers("kEDH") 2267 context.set_ciphers("kEDH")
2268 stats = server_params_test(context, context, 2268 stats = server_params_test(context, context,
2269 chatty=True, connectionchatty=True) 2269 chatty=True, connectionchatty=True)
2270 cipher = stats["cipher"][0] 2270 cipher = stats["cipher"][0]
2271 parts = cipher.split("-") 2271 parts = cipher.split("-")
2272 if "ADH" not in parts and "EDH" not in parts and "DHE" not in parts: 2272 if "ADH" not in parts and "EDH" not in parts and "DHE" not in parts:
2273 self.fail("Non-DH cipher: " + cipher[0]) 2273 self.fail("Non-DH cipher: " + cipher[0])
2274 2274
2275 def test_selected_npn_protocol(self): 2275 def test_selected_npn_protocol(self):
2276 # selected_npn_protocol() is None unless NPN is used 2276 # selected_npn_protocol() is None unless NPN is used
2277 context = ssl.SSLContext(ssl.PROTOCOL_TLSv1) 2277 context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
2278 context.load_cert_chain(CERTFILE) 2278 context.load_cert_chain(CERTFILE)
2279 stats = server_params_test(context, context, 2279 stats = server_params_test(context, context,
2280 chatty=True, connectionchatty=True) 2280 chatty=True, connectionchatty=True)
2281 self.assertIs(stats['client_npn_protocol'], None) 2281 self.assertIsNone(stats['client_npn_protocol'])
2282 2282
2283 @unittest.skipUnless(ssl.HAS_NPN, "NPN support needed for this test") 2283 @unittest.skipUnless(ssl.HAS_NPN, "NPN support needed for this test")
2284 def test_npn_protocols(self): 2284 def test_npn_protocols(self):
2285 server_protocols = ['http/1.1', 'spdy/2'] 2285 server_protocols = ['http/1.1', 'spdy/2']
2286 protocol_tests = [ 2286 protocol_tests = [
2287 (['http/1.1', 'spdy/2'], 'http/1.1'), 2287 (['http/1.1', 'spdy/2'], 'http/1.1'),
2288 (['spdy/2', 'http/1.1'], 'http/1.1'), 2288 (['spdy/2', 'http/1.1'], 'http/1.1'),
2289 (['spdy/2', 'test'], 'spdy/2'), 2289 (['spdy/2', 'test'], 'spdy/2'),
2290 (['abc', 'def'], 'abc') 2290 (['abc', 'def'], 'abc')
2291 ] 2291 ]
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
2471 tests.append(ThreadedTests) 2471 tests.append(ThreadedTests)
2472 2472
2473 try: 2473 try:
2474 support.run_unittest(*tests) 2474 support.run_unittest(*tests)
2475 finally: 2475 finally:
2476 if _have_threads: 2476 if _have_threads:
2477 support.threading_cleanup(*thread_info) 2477 support.threading_cleanup(*thread_info)
2478 2478
2479 if __name__ == "__main__": 2479 if __name__ == "__main__":
2480 test_main() 2480 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+