Commit f671de4d authored by Benjamin Peterson's avatar Benjamin Peterson

don't fail tests when www.python.org can't be validated by the system

parent 72275ef7
......@@ -551,12 +551,10 @@ class HTTPSTest(TestCase):
resp = h.getresponse()
self.assertIn('nginx', resp.getheader('server'))
@test_support.system_must_validate_cert
def test_networked_trusted_by_default_cert(self):
# Default settings: requires a valid cert from a trusted CA
test_support.requires('network')
if test_support.verbose:
import ssl
print(ssl._create_default_https_context().get_ca_certs())
with test_support.transient_internet('www.python.org'):
h = httplib.HTTPSConnection('www.python.org', 443)
h.request('GET', '/')
......
......@@ -276,14 +276,15 @@ class NetworkTestCase(unittest.TestCase):
self.assertEqual(parser.can_fetch("*", robots_url), False)
@unittest.skipUnless(HAVE_HTTPS, 'need SSL support to download license')
@test_support.system_must_validate_cert
def testPythonOrg(self):
test_support.requires('network')
with test_support.transient_internet('www.python.org'):
parser = robotparser.RobotFileParser(
"http://www.python.org/robots.txt")
"https://www.python.org/robots.txt")
parser.read()
self.assertTrue(
parser.can_fetch("*", "http://www.python.org/robots.txt"))
parser.can_fetch("*", "https://www.python.org/robots.txt"))
def test_main():
......
......@@ -481,6 +481,19 @@ def _is_ipv6_enabled():
IPV6_ENABLED = _is_ipv6_enabled()
def system_must_validate_cert(f):
"""Skip the test on TLS certificate validation failures."""
@functools.wraps(f)
def dec(*args, **kwargs):
try:
f(*args, **kwargs)
except IOError as e:
if e.reason == "CERTIFICATE_VERIFY_FAILED":
raise unittest.SkipTest("system does not contain "
"necessary certificates")
raise
return dec
FUZZ = 1e-6
def fcmp(x, y): # fuzzy comparison function
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment