8000 pass ssl context by argument · python/cpython@fc741e9 · GitHub
[go: up one dir, main page]

Skip to content

Commit fc741e9

Browse files
committed
pass ssl context by argument
1 parent b90e980 commit fc741e9

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Lib/test/test_httpservers.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,13 +1472,7 @@ def setUp(self):
14721472
f.write(self.tls_password.encode())
14731473
self.addCleanup(os_helper.unlink, self.tls_password_file)
14741474

1475-
def fetch_file(self, path):
1476-
context = None
1477-
if ssl is not None:
1478-
context = ssl.create_default_context()
1479-
# allow self-signed certificates
1480-
context.check_hostname = False
1481-
context.verify_mode = ssl.CERT_NONE
1475+
def fetch_file(self, path, context=None):
14821476
req = urllib.request.Request(path, method='GET')
14831477
with urllib.request.urlopen(req, context=context) as res:
14841478
return res.read()
@@ -1524,6 +1518,11 @@ def test_http_client(self):
15241518

15251519
@unittest.skipIf(ssl is None, "requires ssl")
15261520
def test_https_client(self):
1521+
context = ssl.create_default_context()
1522+
# allow self-signed certificates
1523+
context.check_hostname = False
1524+
context.verify_mode = ssl.CERT_NONE
1525+
15271526
port = find_unused_port()
15281527
bind = '127.0.0.1'
15291528
proc = spawn_python('-u', '-m', 'http.server', str(port), '-b', bind,
@@ -1534,7 +1533,8 @@ def test_https_client(self):
15341533
self.addCleanup(kill_python, proc)
15351534
self.addCleanup(proc.terminate)
15361535
self.assertTrue(self.wait_for_server(proc, 'https', port, bind))
1537-
res = self.fetch_file(f'https://{bind}:{port}/{self.served_file_name}')
1536+
res = self.fetch_file(f'https://{bind}:{port}/{self.served_file_name}',
1537+
context=context)
15381538
self.assertEqual(res, self.served_data)
15391539

15401540

0 commit comments

Comments
 (0)
0