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

Delta Between Two Patch Sets: Lib/test/test_urllib2_localnet.py

Issue 22417: PEP 476: verify HTTPS certificates by default
Left Patch Set: Created 4 years, 7 months ago
Right 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:
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/test/test_ssl.py ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 import base64 1 import base64
2 import os 2 import os
3 import email 3 import email
4 import urllib.parse 4 import urllib.parse
5 import urllib.request 5 import urllib.request
6 import http.server 6 import http.server
7 import unittest 7 import unittest
8 import hashlib 8 import hashlib
9 9
10 from test import support 10 from test import support
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 def test_200_with_parameters(self): 538 def test_200_with_parameters(self):
539 expected_response = b"pycon 2008..." 539 expected_response = b"pycon 2008..."
540 handler = self.start_server([(200, [], expected_response)]) 540 handler = self.start_server([(200, [], expected_response)])
541 data = self.urlopen("http://localhost:%s/bizarre" % handler.port, 541 data = self.urlopen("http://localhost:%s/bizarre" % handler.port,
542 b"get=with_feeling") 542 b"get=with_feeling")
543 self.assertEqual(data, expected_response) 543 self.assertEqual(data, expected_response)
544 self.assertEqual(handler.requests, ["/bizarre", b"get=with_feeling"]) 544 self.assertEqual(handler.requests, ["/bizarre", b"get=with_feeling"])
545 545
546 def test_https(self): 546 def test_https(self):
547 handler = self.start_https_server() 547 handler = self.start_https_server()
548 data = self.urlopen("https://localhost:%s/bizarre" % handler.port) 548 context = ssl.create_default_context(cafile=CERT_localhost)
549 data = self.urlopen("https://localhost:%s/bizarre" % handler.port, conte xt=context)
549 self.assertEqual(data, b"we care a bit") 550 self.assertEqual(data, b"we care a bit")
550 551
551 def test_https_with_cafile(self): 552 def test_https_with_cafile(self):
552 handler = self.start_https_server(certfile=CERT_localhost) 553 handler = self.start_https_server(certfile=CERT_localhost)
553 import ssl 554 import ssl
554 # Good cert 555 # Good cert
555 data = self.urlopen("https://localhost:%s/bizarre" % handler.port, 556 data = self.urlopen("https://localhost:%s/bizarre" % handler.port,
556 cafile=CERT_localhost) 557 cafile=CERT_localhost)
557 self.assertEqual(data, b"we care a bit") 558 self.assertEqual(data, b"we care a bit")
558 # Bad cert 559 # Bad cert
(...skipping 18 matching lines...) Expand all
577 self.skipTest("ssl module required") 578 self.skipTest("ssl module required")
578 if not ssl.HAS_SNI: 579 if not ssl.HAS_SNI:
579 self.skipTest("SNI support required in OpenSSL") 580 self.skipTest("SNI support required in OpenSSL")
580 sni_name = None 581 sni_name = None
581 def cb_sni(ssl_sock, server_name, initial_context): 582 def cb_sni(ssl_sock, server_name, initial_context):
582 nonlocal sni_name 583 nonlocal sni_name
583 sni_name = server_name 584 sni_name = server_name
584 context = ssl.SSLContext(ssl.PROTOCOL_TLSv1) 585 context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
585 context.set_servername_callback(cb_sni) 586 context.set_servername_callback(cb_sni)
586 handler = self.start_https_server(context=context, certfile=CERT_localho st) 587 handler = self.start_https_server(context=context, certfile=CERT_localho st)
587 self.urlopen("https://localhost:%s" % handler.port) 588 context = ssl.create_default_context(cafile=CERT_localhost)
589 self.urlopen("https://localhost:%s" % handler.port, context=context)
588 self.assertEqual(sni_name, "localhost") 590 self.assertEqual(sni_name, "localhost")
589 591
590 def test_sending_headers(self): 592 def test_sending_headers(self):
591 handler = self.start_server() 593 handler = self.start_server()
592 req = urllib.request.Request("http://localhost:%s/" % handler.port, 594 req = urllib.request.Request("http://localhost:%s/" % handler.port,
593 headers={"Range": "bytes=20-39"}) 595 headers={"Range": "bytes=20-39"})
594 urllib.request.urlopen(req) 596 urllib.request.urlopen(req)
595 self.assertEqual(handler.headers_received["Range"], "bytes=20-39") 597 self.assertEqual(handler.headers_received["Range"], "bytes=20-39")
596 598
597 def test_basic(self): 599 def test_basic(self):
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 # in the tearDown 683 # in the tearDown
682 global threads_key 684 global threads_key
683 threads_key = support.threading_setup() 685 threads_key = support.threading_setup()
684 686
685 def tearDownModule(): 687 def tearDownModule():
686 if threads_key: 688 if threads_key:
687 support.threading_cleanup(threads_key) 689 support.threading_cleanup(threads_key)
688 690
689 if __name__ == "__main__": 691 if __name__ == "__main__":
690 unittest.main() 692 unittest.main()
LEFTRIGHT

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