From 03ecafdc5834e64cc9f1f1493ddfaa82210ace47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Touceda?= Date: Thu, 29 Aug 2013 17:41:43 -0300 Subject: Do not raise on not 2XX error codes Also accept unicode ascii keys --- keymanager/changes/bug_minor_issues | 4 ++++ keymanager/src/leap/keymanager/__init__.py | 15 ++++++++++----- keymanager/src/leap/keymanager/openpgp.py | 4 ++-- 3 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 keymanager/changes/bug_minor_issues (limited to 'keymanager') diff --git a/keymanager/changes/bug_minor_issues b/keymanager/changes/bug_minor_issues new file mode 100644 index 0000000..91a69ed --- /dev/null +++ b/keymanager/changes/bug_minor_issues @@ -0,0 +1,4 @@ + o Do not raise exception when a GET request doesn't return 2XX + code. Nickserver uses error codes for more verbosity in the + result. + o Accept unicode ascii keys along with str. \ No newline at end of file diff --git a/keymanager/src/leap/keymanager/__init__.py b/keymanager/src/leap/keymanager/__init__.py index 05cbcca..2f39ad9 100644 --- a/keymanager/src/leap/keymanager/__init__.py +++ b/keymanager/src/leap/keymanager/__init__.py @@ -127,11 +127,16 @@ class KeyManager(object): self._ca_cert_path is not None, 'We need the CA certificate path!') res = self._fetcher.get(uri, data=data, verify=self._ca_cert_path) - # assert that the response is valid - res.raise_for_status() - leap_assert( - res.headers['content-type'].startswith('application/json'), - 'Content-type is not JSON.') + # Nickserver now returns 404 for key not found and 500 for + # other cases (like key too small), so we are skipping this + # check for the time being + # res.raise_for_status() + + # Responses are now text/plain, although it's json anyway, but + # this will fail when it shouldn't + # leap_assert( + # res.headers['content-type'].startswith('application/json'), + # 'Content-type is not JSON.') return res def _put(self, uri, data=None): diff --git a/keymanager/src/leap/keymanager/openpgp.py b/keymanager/src/leap/keymanager/openpgp.py index aa04ed0..7946db8 100644 --- a/keymanager/src/leap/keymanager/openpgp.py +++ b/keymanager/src/leap/keymanager/openpgp.py @@ -301,9 +301,9 @@ class OpenPGPScheme(EncryptionScheme): Put key contained in ascii-armored C{key_data} in local storage. :param key_data: The key data to be stored. - :type key_data: str + :type key_data: str or unicode """ - leap_assert_type(key_data, str) + leap_assert_type(key_data, (str, unicode)) # TODO: add more checks for correct key data. leap_assert(key_data is not None, 'Data does not represent a key.') -- cgit v1.2.3