Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/certbot/certbot.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/acme
diff options
context:
space:
mode:
authorJacob Hoffman-Andrews <github@hoffman-andrews.com>2017-02-23 05:48:01 +0300
committerBrad Warren <bmw@users.noreply.github.com>2017-02-23 05:48:01 +0300
commita92ca8e97c38a8adbdf5088af058ec50e55b2602 (patch)
tree5fb74dc03cf5d53461036284701e8456672f45c2 /acme
parent5bab6b512f56707632682328be2c8c060516e212 (diff)
Add default timeout to ClientNetwork. (#4217)
In https://community.letsencrypt.org/t/letsencrypt-cli-hangs-on-certificate-request/27211, a community member pointed out that Certbot seems to hang when there are routing problems.
Diffstat (limited to 'acme')
-rw-r--r--acme/acme/client.py1
-rw-r--r--acme/acme/client_test.py22
2 files changed, 18 insertions, 5 deletions
diff --git a/acme/acme/client.py b/acme/acme/client.py
index d01555c75..168574d58 100644
--- a/acme/acme/client.py
+++ b/acme/acme/client.py
@@ -607,6 +607,7 @@ class ClientNetwork(object): # pylint: disable=too-many-instance-attributes
kwargs['verify'] = self.verify_ssl
kwargs.setdefault('headers', {})
kwargs['headers'].setdefault('User-Agent', self.user_agent)
+ kwargs.setdefault('timeout', 45) # timeout after 45 seconds
response = self.session.request(method, url, *args, **kwargs)
# If content is DER, log the base64 of it instead of raw bytes, to keep
# binary data out of the logs.
diff --git a/acme/acme/client_test.py b/acme/acme/client_test.py
index 0f4506203..b7bd0740c 100644
--- a/acme/acme/client_test.py
+++ b/acme/acme/client_test.py
@@ -532,7 +532,7 @@ class ClientNetworkTest(unittest.TestCase):
'HEAD', 'http://example.com/', 'foo', bar='baz'))
self.net.session.request.assert_called_once_with(
'HEAD', 'http://example.com/', 'foo',
- headers=mock.ANY, verify=mock.ANY, bar='baz')
+ headers=mock.ANY, verify=mock.ANY, timeout=mock.ANY, bar='baz')
@mock.patch('acme.client.logger')
def test_send_request_get_der(self, mock_logger):
@@ -542,7 +542,8 @@ class ClientNetworkTest(unittest.TestCase):
headers={"Content-Type": "application/pkix-cert"},
content=b"hi")
# pylint: disable=protected-access
- self.net._send_request('HEAD', 'http://example.com/', 'foo', bar='baz')
+ self.net._send_request('HEAD', 'http://example.com/', 'foo',
+ timeout=mock.ANY, bar='baz')
mock_logger.debug.assert_called_once_with(
'Received response:\nHTTP %d\n%s\n\n%s', 200,
'Content-Type: application/pkix-cert', b'aGk=')
@@ -555,7 +556,7 @@ class ClientNetworkTest(unittest.TestCase):
'POST', 'http://example.com/', 'foo', data='qux', bar='baz'))
self.net.session.request.assert_called_once_with(
'POST', 'http://example.com/', 'foo',
- headers=mock.ANY, verify=mock.ANY, data='qux', bar='baz')
+ headers=mock.ANY, verify=mock.ANY, timeout=mock.ANY, data='qux', bar='baz')
def test_send_request_verify_ssl(self):
# pylint: disable=protected-access
@@ -568,7 +569,8 @@ class ClientNetworkTest(unittest.TestCase):
self.response,
self.net._send_request('GET', 'http://example.com/'))
self.net.session.request.assert_called_once_with(
- 'GET', 'http://example.com/', verify=verify, headers=mock.ANY)
+ 'GET', 'http://example.com/', verify=verify,
+ timeout=mock.ANY, headers=mock.ANY)
def test_send_request_user_agent(self):
self.net.session = mock.MagicMock()
@@ -577,13 +579,23 @@ class ClientNetworkTest(unittest.TestCase):
headers={'bar': 'baz'})
self.net.session.request.assert_called_once_with(
'GET', 'http://example.com/', verify=mock.ANY,
+ timeout=mock.ANY,
headers={'User-Agent': 'acme-python-test', 'bar': 'baz'})
self.net._send_request('GET', 'http://example.com/',
headers={'User-Agent': 'foo2'})
self.net.session.request.assert_called_with(
'GET', 'http://example.com/',
- verify=mock.ANY, headers={'User-Agent': 'foo2'})
+ verify=mock.ANY, timeout=mock.ANY, headers={'User-Agent': 'foo2'})
+
+ def test_send_request_timeout(self):
+ self.net.session = mock.MagicMock()
+ # pylint: disable=protected-access
+ self.net._send_request('GET', 'http://example.com/',
+ headers={'bar': 'baz'})
+ self.net.session.request.assert_called_once_with(
+ mock.ANY, mock.ANY, verify=mock.ANY, headers=mock.ANY,
+ timeout=45)
def test_del(self):
sess = mock.MagicMock()