broadinstitute / python-cert_manager

Python interface to the Sectigo Certificate Manager REST API

Repository from Github https://github.combroadinstitute/python-cert_managerRepository from Github https://github.combroadinstitute/python-cert_manager

JSONDecodeError when using the SSL.revoke method

alextremblay opened this issue · comments

When I try to use the revoke method on an instance of the SSL class, I get the following error:

json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Digging into it with a debugger, i can see the problem is that the HTTP response from the server is a message with a status of '204 No Content' and a body that's a blank string. calling result.json() on it fails because the requests.Response.json method can't handle an empty string

Looking at your code and your unit tests, it appears you expect the server to return a response body like '{}' instead of '', but that's not the case.

In fact, if I clone your repo and alter the mocked response to return body='' instead of json={} and run your test suite, I'm able to replicate the error exactly:

Error in tests.test_certificates.TestRevoke.test_success
testtools.testresult.real._StringException: Traceback (most recent call last):
  File "<string>", line 3, in wrapper
  File "/home/alext/python-cert_manager/tests/test_certificates.py", line 623, in test_success
    resp = self.certobj.revoke(cert_id=self.test_id, reason="Because")
  File "/home/alext/python-cert_manager/cert_manager/_certificates.py", line 236, in revoke
    return result.json()
  File "/home/alext/python-cert_manager/.venv/lib/python3.6/site-packages/requests/models.py", line 900, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib64/python3.6/json/__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "/usr/lib64/python3.6/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib64/python3.6/json/decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Looking at the Sectigo SCM REST API docs, I see that the "Revoke SSL certificate by Id", "Revoke SSL certificate by serial number", "Renew SSL certificate by renew Id", "Replace SSL certificate by Id", and "Delete External SSL certificate by Id" endpoints all return 204 No Content on success

Same goes fo r the equivalent enbpoints for Client Certificates