summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2014-11-25 15:16:55 -0600
committerBenjamin Peterson <benjamin@python.org>2014-11-25 15:16:55 -0600
commit43ad4563e3a55fa2075deccdec42427343ce0870 (patch)
tree48d779234d31b904a119694c0ff9d4489cf04ec5
parentacc6dd161636ce80b5b73e835fefdb16881de0b2 (diff)
downloadcpython-43ad4563e3a55fa2075deccdec42427343ce0870.tar.gz
don't fail tests when www.python.org can't be validated by the system
-rw-r--r--Lib/test/test_httplib.py4
-rw-r--r--Lib/test/test_robotparser.py5
-rw-r--r--Lib/test/test_support.py13
3 files changed, 17 insertions, 5 deletions
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py
index 4c1f16567f..3e7a57e7f0 100644
--- a/Lib/test/test_httplib.py
+++ b/Lib/test/test_httplib.py
@@ -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', '/')
diff --git a/Lib/test/test_robotparser.py b/Lib/test/test_robotparser.py
index 36ac941ab8..e4b01f1e30 100644
--- a/Lib/test/test_robotparser.py
+++ b/Lib/test/test_robotparser.py
@@ -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():
diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py
index f4434595e8..539ddb3c6d 100644
--- a/Lib/test/test_support.py
+++ b/Lib/test/test_support.py
@@ -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