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

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

Issue 16510: Using appropriate checks in tests
Patch Set: Created 6 years, 5 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 gc 9 import gc
10 import os 10 import os
(...skipping 1967 matching lines...) Expand 10 before | Expand all | Expand 10 after
1978 self.assertIn(stats['compression'], { None, 'ZLIB', 'RLE' }) 1978 self.assertIn(stats['compression'], { None, 'ZLIB', 'RLE' })
1979 1979
1980 @unittest.skipUnless(hasattr(ssl, 'OP_NO_COMPRESSION'), 1980 @unittest.skipUnless(hasattr(ssl, 'OP_NO_COMPRESSION'),
1981 "ssl.OP_NO_COMPRESSION needed for this test") 1981 "ssl.OP_NO_COMPRESSION needed for this test")
1982 def test_compression_disabled(self): 1982 def test_compression_disabled(self):
1983 context = ssl.SSLContext(ssl.PROTOCOL_TLSv1) 1983 context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
1984 context.load_cert_chain(CERTFILE) 1984 context.load_cert_chain(CERTFILE)
1985 context.options |= ssl.OP_NO_COMPRESSION 1985 context.options |= ssl.OP_NO_COMPRESSION
1986 stats = server_params_test(context, context, 1986 stats = server_params_test(context, context,
1987 chatty=True, connectionchatty=True) 1987 chatty=True, connectionchatty=True)
1988 self.assertIs(stats['compression'], None) 1988 self.assertIsNone(stats['compression'])
1989 1989
1990 def test_dh_params(self): 1990 def test_dh_params(self):
1991 # Check we can get a connection with ephemeral Diffie-Hellman 1991 # Check we can get a connection with ephemeral Diffie-Hellman
1992 context = ssl.SSLContext(ssl.PROTOCOL_TLSv1) 1992 context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
1993 context.load_cert_chain(CERTFILE) 1993 context.load_cert_chain(CERTFILE)
1994 context.load_dh_params(DHFILE) 1994 context.load_dh_params(DHFILE)
1995 context.set_ciphers("kEDH") 1995 context.set_ciphers("kEDH")
1996 stats = server_params_test(context, context, 1996 stats = server_params_test(context, context,
1997 chatty=True, connectionchatty=True) 1997 chatty=True, connectionchatty=True)
1998 cipher = stats["cipher"][0] 1998 cipher = stats["cipher"][0]
1999 parts = cipher.split("-") 1999 parts = cipher.split("-")
2000 if "ADH" not in parts and "EDH" not in parts and "DHE" not in parts: 2000 if "ADH" not in parts and "EDH" not in parts and "DHE" not in parts:
2001 self.fail("Non-DH cipher: " + cipher[0]) 2001 self.fail("Non-DH cipher: " + cipher[0])
2002 2002
2003 def test_selected_npn_protocol(self): 2003 def test_selected_npn_protocol(self):
2004 # selected_npn_protocol() is None unless NPN is used 2004 # selected_npn_protocol() is None unless NPN is used
2005 context = ssl.SSLContext(ssl.PROTOCOL_TLSv1) 2005 context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
2006 context.load_cert_chain(CERTFILE) 2006 context.load_cert_chain(CERTFILE)
2007 stats = server_params_test(context, context, 2007 stats = server_params_test(context, context,
2008 chatty=True, connectionchatty=True) 2008 chatty=True, connectionchatty=True)
2009 self.assertIs(stats['client_npn_protocol'], None) 2009 self.assertIsNone(stats['client_npn_protocol'])
2010 2010
2011 @unittest.skipUnless(ssl.HAS_NPN, "NPN support needed for this test") 2011 @unittest.skipUnless(ssl.HAS_NPN, "NPN support needed for this test")
2012 def test_npn_protocols(self): 2012 def test_npn_protocols(self):
2013 server_protocols = ['http/1.1', 'spdy/2'] 2013 server_protocols = ['http/1.1', 'spdy/2']
2014 protocol_tests = [ 2014 protocol_tests = [
2015 (['http/1.1', 'spdy/2'], 'http/1.1'), 2015 (['http/1.1', 'spdy/2'], 'http/1.1'),
2016 (['spdy/2', 'http/1.1'], 'http/1.1'), 2016 (['spdy/2', 'http/1.1'], 'http/1.1'),
2017 (['spdy/2', 'test'], 'spdy/2'), 2017 (['spdy/2', 'test'], 'spdy/2'),
2018 (['abc', 'def'], 'abc') 2018 (['abc', 'def'], 'abc')
2019 ] 2019 ]
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
2170 tests.append(ThreadedTests) 2170 tests.append(ThreadedTests)
2171 2171
2172 try: 2172 try:
2173 support.run_unittest(*tests) 2173 support.run_unittest(*tests)
2174 finally: 2174 finally:
2175 if _have_threads: 2175 if _have_threads:
2176 support.threading_cleanup(*thread_info) 2176 support.threading_cleanup(*thread_info)
2177 2177
2178 if __name__ == "__main__": 2178 if __name__ == "__main__":
2179 test_main() 2179 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+