Commit 400e761b authored by Antoine Pitrou's avatar Antoine Pitrou

Use transient_internet() where appropriate in test_ssl

(svn.python.org is sometimes unavailable)
parent 90886a7b
...@@ -305,14 +305,9 @@ class ContextTests(unittest.TestCase): ...@@ -305,14 +305,9 @@ class ContextTests(unittest.TestCase):
class NetworkedTests(unittest.TestCase): class NetworkedTests(unittest.TestCase):
def setUp(self):
self.old_timeout = socket.getdefaulttimeout()
socket.setdefaulttimeout(30)
def tearDown(self):
socket.setdefaulttimeout(self.old_timeout)
def test_connect(self): def test_connect(self):
with support.transient_internet("svn.python.org"):
s = ssl.wrap_socket(socket.socket(socket.AF_INET), s = ssl.wrap_socket(socket.socket(socket.AF_INET),
cert_reqs=ssl.CERT_NONE) cert_reqs=ssl.CERT_NONE)
try: try:
...@@ -339,6 +334,7 @@ class NetworkedTests(unittest.TestCase): ...@@ -339,6 +334,7 @@ class NetworkedTests(unittest.TestCase):
s.close() s.close()
def test_connect_with_context(self): def test_connect_with_context(self):
with support.transient_internet("svn.python.org"):
# Same as test_connect, but with a separately created context # Same as test_connect, but with a separately created context
ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23) ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
s = ctx.wrap_socket(socket.socket(socket.AF_INET)) s = ctx.wrap_socket(socket.socket(socket.AF_INET))
...@@ -369,6 +365,7 @@ class NetworkedTests(unittest.TestCase): ...@@ -369,6 +365,7 @@ class NetworkedTests(unittest.TestCase):
# OpenSSL 0.9.8n and 1.0.0, as a result the capath directory must # OpenSSL 0.9.8n and 1.0.0, as a result the capath directory must
# contain both versions of each certificate (same content, different # contain both versions of each certificate (same content, different
# filename) for this test to be portable across OpenSSL releases. # filename) for this test to be portable across OpenSSL releases.
with support.transient_internet("svn.python.org"):
ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23) ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
ctx.verify_mode = ssl.CERT_REQUIRED ctx.verify_mode = ssl.CERT_REQUIRED
ctx.load_verify_locations(capath=CAPATH) ctx.load_verify_locations(capath=CAPATH)
...@@ -396,6 +393,7 @@ class NetworkedTests(unittest.TestCase): ...@@ -396,6 +393,7 @@ class NetworkedTests(unittest.TestCase):
# Issue #5238: creating a file-like object with makefile() shouldn't # Issue #5238: creating a file-like object with makefile() shouldn't
# delay closing the underlying "real socket" (here tested with its # delay closing the underlying "real socket" (here tested with its
# file descriptor, hence skipping the test under Windows). # file descriptor, hence skipping the test under Windows).
with support.transient_internet("svn.python.org"):
ss = ssl.wrap_socket(socket.socket(socket.AF_INET)) ss = ssl.wrap_socket(socket.socket(socket.AF_INET))
ss.connect(("svn.python.org", 443)) ss.connect(("svn.python.org", 443))
fd = ss.fileno() fd = ss.fileno()
...@@ -411,6 +409,7 @@ class NetworkedTests(unittest.TestCase): ...@@ -411,6 +409,7 @@ class NetworkedTests(unittest.TestCase):
self.assertEqual(e.exception.errno, errno.EBADF) self.assertEqual(e.exception.errno, errno.EBADF)
def test_non_blocking_handshake(self): def test_non_blocking_handshake(self):
with support.transient_internet("svn.python.org"):
s = socket.socket(socket.AF_INET) s = socket.socket(socket.AF_INET)
s.connect(("svn.python.org", 443)) s.connect(("svn.python.org", 443))
s.setblocking(False) s.setblocking(False)
...@@ -435,6 +434,7 @@ class NetworkedTests(unittest.TestCase): ...@@ -435,6 +434,7 @@ class NetworkedTests(unittest.TestCase):
sys.stdout.write("\nNeeded %d calls to do_handshake() to establish session.\n" % count) sys.stdout.write("\nNeeded %d calls to do_handshake() to establish session.\n" % count)
def test_get_server_certificate(self): def test_get_server_certificate(self):
with support.transient_internet("svn.python.org"):
pem = ssl.get_server_certificate(("svn.python.org", 443)) pem = ssl.get_server_certificate(("svn.python.org", 443))
if not pem: if not pem:
self.fail("No server certificate on svn.python.org:443!") self.fail("No server certificate on svn.python.org:443!")
...@@ -456,6 +456,7 @@ class NetworkedTests(unittest.TestCase): ...@@ -456,6 +456,7 @@ class NetworkedTests(unittest.TestCase):
def test_ciphers(self): def test_ciphers(self):
remote = ("svn.python.org", 443) remote = ("svn.python.org", 443)
with support.transient_internet(remote[0]):
s = ssl.wrap_socket(socket.socket(socket.AF_INET), s = ssl.wrap_socket(socket.socket(socket.AF_INET),
cert_reqs=ssl.CERT_NONE, ciphers="ALL") cert_reqs=ssl.CERT_NONE, ciphers="ALL")
s.connect(remote) s.connect(remote)
......
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