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

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

Issue 14780: urllib.request could use the default CA store
Patch Set: Created 1 year 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 | « Doc/library/urllib.request.rst ('k') | Lib/urllib/request.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 #!/usr/bin/env python3 1 #!/usr/bin/env python3
2 2
3 import os 3 import os
4 import email 4 import email
5 import urllib.parse 5 import urllib.parse
6 import urllib.request 6 import urllib.request
7 import http.server 7 import http.server
8 import unittest 8 import unittest
9 import hashlib 9 import hashlib
10 from test import support 10 from test import support
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 def test_200_with_parameters(self): 447 def test_200_with_parameters(self):
448 expected_response = b"pycon 2008..." 448 expected_response = b"pycon 2008..."
449 handler = self.start_server([(200, [], expected_response)]) 449 handler = self.start_server([(200, [], expected_response)])
450 data = self.urlopen("http://localhost:%s/bizarre" % handler.port, 450 data = self.urlopen("http://localhost:%s/bizarre" % handler.port,
451 b"get=with_feeling") 451 b"get=with_feeling")
452 self.assertEqual(data, expected_response) 452 self.assertEqual(data, expected_response)
453 self.assertEqual(handler.requests, ["/bizarre", b"get=with_feeling"]) 453 self.assertEqual(handler.requests, ["/bizarre", b"get=with_feeling"])
454 454
455 def test_https(self): 455 def test_https(self):
456 handler = self.start_https_server() 456 handler = self.start_https_server()
457 data = self.urlopen("https://localhost:%s/bizarre" % handler.port) 457 data = self.urlopen("https://localhost:%s/bizarre" % handler.port, cadef ault=False)
458 self.assertEqual(data, b"we care a bit") 458 self.assertEqual(data, b"we care a bit")
459 459
460 def test_https_with_cafile(self): 460 def test_https_with_cafile(self):
461 handler = self.start_https_server(certfile=CERT_localhost) 461 handler = self.start_https_server(certfile=CERT_localhost)
462 import ssl 462 import ssl
463 # Good cert 463 # Good cert
464 data = self.urlopen("https://localhost:%s/bizarre" % handler.port, 464 data = self.urlopen("https://localhost:%s/bizarre" % handler.port,
465 cafile=CERT_localhost) 465 cafile=CERT_localhost)
466 self.assertEqual(data, b"we care a bit") 466 self.assertEqual(data, b"we care a bit")
467 # Bad cert 467 # Bad cert
468 with self.assertRaises(urllib.error.URLError) as cm: 468 with self.assertRaises(urllib.error.URLError) as cm:
469 self.urlopen("https://localhost:%s/bizarre" % handler.port, 469 self.urlopen("https://localhost:%s/bizarre" % handler.port,
470 cafile=CERT_fakehostname) 470 cafile=CERT_fakehostname)
471 # Good cert, but mismatching hostname 471 # Good cert, but mismatching hostname
472 handler = self.start_https_server(certfile=CERT_fakehostname) 472 handler = self.start_https_server(certfile=CERT_fakehostname)
473 with self.assertRaises(ssl.CertificateError) as cm: 473 with self.assertRaises(ssl.CertificateError) as cm:
474 self.urlopen("https://localhost:%s/bizarre" % handler.port, 474 self.urlopen("https://localhost:%s/bizarre" % handler.port,
475 cafile=CERT_fakehostname) 475 cafile=CERT_fakehostname)
476
477 def test_https_with_cadefault(self):
478 handler = self.start_https_server(certfile=CERT_localhost)
479 # Self-signed cert should fail verification with system certificate stor e
480 with self.assertRaises(urllib.error.URLError) as cm:
481 self.urlopen("https://localhost:%s/bizarre" % handler.port)
476 482
477 def test_sending_headers(self): 483 def test_sending_headers(self):
478 handler = self.start_server() 484 handler = self.start_server()
479 req = urllib.request.Request("http://localhost:%s/" % handler.port, 485 req = urllib.request.Request("http://localhost:%s/" % handler.port,
480 headers={"Range": "bytes=20-39"}) 486 headers={"Range": "bytes=20-39"})
481 urllib.request.urlopen(req) 487 urllib.request.urlopen(req)
482 self.assertEqual(handler.headers_received["Range"], "bytes=20-39") 488 self.assertEqual(handler.headers_received["Range"], "bytes=20-39")
483 489
484 def test_basic(self): 490 def test_basic(self):
485 handler = self.start_server() 491 handler = self.start_server()
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 (index, len(lines[index]), len(line))) 561 (index, len(lines[index]), len(line)))
556 self.assertEqual(index + 1, len(lines)) 562 self.assertEqual(index + 1, len(lines))
557 563
558 564
559 @support.reap_threads 565 @support.reap_threads
560 def test_main(): 566 def test_main():
561 support.run_unittest(ProxyAuthTests, TestUrlopen) 567 support.run_unittest(ProxyAuthTests, TestUrlopen)
562 568
563 if __name__ == "__main__": 569 if __name__ == "__main__":
564 test_main() 570 test_main()
OLDNEW
« no previous file with comments | « Doc/library/urllib.request.rst ('k') | Lib/urllib/request.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld cbc36f91f3f7