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
diff options
context:
space:
mode:
authoralexzorin <alex@zorin.id.au>2020-02-23 23:49:42 +0300
committerGitHub <noreply@github.com>2020-02-23 23:49:42 +0300
commit2633c3ffb6a4f66933daef238b6a140ffc059818 (patch)
tree7034079ff749b4bec503104f14dcefe36522a78d
parent84b57fac9341453b12135cdf26d9ede092e2c3aa (diff)
acme: ignore params in content-type check (#7342)
* acme: ignore params in content-type check Fixes the warning in #7339 * Suppress coverage complaint in test * Update CHANGELOG * Repair symlink Co-authored-by: Adrien Ferrand <adferrand@users.noreply.github.com>
-rw-r--r--acme/acme/client.py3
-rw-r--r--acme/tests/client_test.py29
-rw-r--r--certbot/CHANGELOG.md1
3 files changed, 33 insertions, 0 deletions
diff --git a/acme/acme/client.py b/acme/acme/client.py
index 3e03748b5..cecb727c7 100644
--- a/acme/acme/client.py
+++ b/acme/acme/client.py
@@ -1022,6 +1022,9 @@ class ClientNetwork(object):
"""
response_ct = response.headers.get('Content-Type')
+ # Strip parameters from the media-type (rfc2616#section-3.7)
+ if response_ct:
+ response_ct = response_ct.split(';')[0].strip()
try:
# TODO: response.json() is called twice, once here, and
# once in _get and _post clients
diff --git a/acme/tests/client_test.py b/acme/tests/client_test.py
index a38fedbd6..a4966140f 100644
--- a/acme/tests/client_test.py
+++ b/acme/tests/client_test.py
@@ -980,6 +980,35 @@ class ClientNetworkTest(unittest.TestCase):
self.assertEqual(
self.response, self.net._check_response(self.response))
+ @mock.patch('acme.client.logger')
+ def test_check_response_ok_ct_with_charset(self, mock_logger):
+ self.response.json.return_value = {}
+ self.response.headers['Content-Type'] = 'application/json; charset=utf-8'
+ # pylint: disable=protected-access
+ self.assertEqual(self.response, self.net._check_response(
+ self.response, content_type='application/json'))
+ try:
+ mock_logger.debug.assert_called_with(
+ 'Ignoring wrong Content-Type (%r) for JSON decodable response',
+ 'application/json; charset=utf-8'
+ )
+ except AssertionError:
+ return
+ raise AssertionError('Expected Content-Type warning ' #pragma: no cover
+ 'to not have been logged')
+
+ @mock.patch('acme.client.logger')
+ def test_check_response_ok_bad_ct(self, mock_logger):
+ self.response.json.return_value = {}
+ self.response.headers['Content-Type'] = 'text/plain'
+ # pylint: disable=protected-access
+ self.assertEqual(self.response, self.net._check_response(
+ self.response, content_type='application/json'))
+ mock_logger.debug.assert_called_with(
+ 'Ignoring wrong Content-Type (%r) for JSON decodable response',
+ 'text/plain'
+ )
+
def test_check_response_conflict(self):
self.response.ok = False
self.response.status_code = 409
diff --git a/certbot/CHANGELOG.md b/certbot/CHANGELOG.md
index 126b07eec..bc5ad90d6 100644
--- a/certbot/CHANGELOG.md
+++ b/certbot/CHANGELOG.md
@@ -14,6 +14,7 @@ Certbot adheres to [Semantic Versioning](https://semver.org/).
### Changed
* certbot._internal.cli is now a package split in submodules instead of a whole module.
+* Fix acme module warnings when response Content-Type includes params (e.g. charset).
### Fixed