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

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

Issue 22417: PEP 476: verify HTTPS certificates by default
Patch Set: Created 4 years, 7 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_httplib.py ('k') | Lib/test/test_urllib2_localnet.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 2564 matching lines...) Expand 10 before | Expand all | Expand 10 after
2575 def test_socketserver(self): 2575 def test_socketserver(self):
2576 """Using a SocketServer to create and manage SSL connections.""" 2576 """Using a SocketServer to create and manage SSL connections."""
2577 server = make_https_server(self, certfile=CERTFILE) 2577 server = make_https_server(self, certfile=CERTFILE)
2578 # try to connect 2578 # try to connect
2579 if support.verbose: 2579 if support.verbose:
2580 sys.stdout.write('\n') 2580 sys.stdout.write('\n')
2581 with open(CERTFILE, 'rb') as f: 2581 with open(CERTFILE, 'rb') as f:
2582 d1 = f.read() 2582 d1 = f.read()
2583 d2 = '' 2583 d2 = ''
2584 # now fetch the same data from the HTTPS server 2584 # now fetch the same data from the HTTPS server
2585 url = 'https://%s:%d/%s' % ( 2585 url = 'https://localhost:%d/%s' % (
2586 HOST, server.port, os.path.split(CERTFILE)[1]) 2586 server.port, os.path.split(CERTFILE)[1])
2587 f = urllib.request.urlopen(url) 2587 context = ssl.create_default_context(cafile=CERTFILE)
2588 f = urllib.request.urlopen(url, context=context)
2588 try: 2589 try:
2589 dlen = f.info().get("content-length") 2590 dlen = f.info().get("content-length")
2590 if dlen and (int(dlen) > 0): 2591 if dlen and (int(dlen) > 0):
2591 d2 = f.read(int(dlen)) 2592 d2 = f.read(int(dlen))
2592 if support.verbose: 2593 if support.verbose:
2593 sys.stdout.write( 2594 sys.stdout.write(
2594 " client: read %d bytes from remote server '%s'\n" 2595 " client: read %d bytes from remote server '%s'\n"
2595 % (len(d2), server)) 2596 % (len(d2), server))
2596 finally: 2597 finally:
2597 f.close() 2598 f.close()
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
3230 tests.append(ThreadedTests) 3231 tests.append(ThreadedTests)
3231 3232
3232 try: 3233 try:
3233 support.run_unittest(*tests) 3234 support.run_unittest(*tests)
3234 finally: 3235 finally:
3235 if _have_threads: 3236 if _have_threads:
3236 support.threading_cleanup(*thread_info) 3237 support.threading_cleanup(*thread_info)
3237 3238
3238 if __name__ == "__main__": 3239 if __name__ == "__main__":
3239 test_main() 3240 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_httplib.py ('k') | Lib/test/test_urllib2_localnet.py » ('j') | no next file with comments »

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