Skip to content

Commit 5c136f3

Browse files
committed
early abort
1 parent b189d06 commit 5c136f3

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

Lib/test/test_httpservers.py

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

1475-
@unittest.skipIf(ssl is None, "requires ssl")
1476-
def get_ssl_context(self):
1477-
context = ssl.create_default_context()
1478-
# allow self-signed certificates
1479-
context.check_hostname = False
1480-
context.verify_mode = ssl.CERT_NONE
1481-
return context
1482-
14831475
def fetch_file(self, path, context=None):
14841476
req = urllib.request.Request(path, method='GET')
14851477
with urllib.request.urlopen(req, context=context) as res:
@@ -1515,7 +1507,13 @@ def test_http_client(self):
15151507
res = self.fetch_file(f'http://{bind}:{port}/{self.served_file_name}')
15161508
self.assertEqual(res, self.served_data)
15171509

1510+
@unittest.skipIf(ssl is None, "requires ssl")
15181511
def test_https_client(self):
1512+
context = ssl.create_default_context()
1513+
# allow self-signed certificates
1514+
context.check_hostname = False
1515+
context.verify_mode = ssl.CERT_NONE
1516+
15191517
port = find_unused_port()
15201518
proc = spawn_python('-u', '-m', 'http.server', str(port),
15211519
'--tls-cert', self.tls_cert,
@@ -1527,7 +1525,7 @@ def test_https_client(self):
15271525
bind = self.wait_for_server(proc, 'https', port)
15281526
self.assertIsNotNone(bind)
15291527
url = f'https://{bind}:{port}/{self.served_file_name}'
1530-
res = self.fetch_file(url, context=self.get_ssl_context())
1528+
res = self.fetch_file(url, context=context)
15311529
self.assertEqual(res, self.served_data)
15321530

15331531

0 commit comments

Comments
 (0)