1
0
mirror of https://github.com/laurivosandi/certidude synced 2024-12-23 00:25:18 +00:00

Better branch handling for request API calls

This commit is contained in:
Lauri Võsandi 2017-04-25 16:15:39 +03:00
parent 7225726d66
commit 4c9744308a
3 changed files with 44 additions and 22 deletions

View File

@ -154,8 +154,15 @@ class RequestDetailResource(object):
""" """
Fetch certificate signing request as PEM Fetch certificate signing request as PEM
""" """
resp.set_header("Content-Type", "application/pkcs10")
try:
_, buf, _ = authority.get_request(cn) _, buf, _ = authority.get_request(cn)
except EnvironmentError:
logger.warning(u"Failed to serve non-existant request %s to %s",
cn, req.context.get("remote_addr"))
raise falcon.HTTPNotFound()
resp.set_header("Content-Type", "application/pkcs10")
logger.debug(u"Signing request %s was downloaded by %s", logger.debug(u"Signing request %s was downloaded by %s",
cn, req.context.get("remote_addr")) cn, req.context.get("remote_addr"))

View File

@ -19,7 +19,7 @@ class SignedCertificateDetailResource(object):
logger.warning(u"Failed to serve non-existant certificate %s to %s", logger.warning(u"Failed to serve non-existant certificate %s to %s",
cn, req.context.get("remote_addr")) cn, req.context.get("remote_addr"))
raise falcon.HTTPNotFound() raise falcon.HTTPNotFound()
else:
if preferred_type == "application/x-pem-file": if preferred_type == "application/x-pem-file":
resp.set_header("Content-Type", "application/x-pem-file") resp.set_header("Content-Type", "application/x-pem-file")
resp.set_header("Content-Disposition", ("attachment; filename=%s.pem" % cn)) resp.set_header("Content-Disposition", ("attachment; filename=%s.pem" % cn))

View File

@ -87,6 +87,21 @@ def test_cli_setup_authority():
headers={"content-type":"application/pkcs10"}) headers={"content-type":"application/pkcs10"})
assert r.status_code == 409 # duplicate cn, different keypair assert r.status_code == 409 # duplicate cn, different keypair
r = client().simulate_get("/api/request/test/", headers={"Accept":"application/json"})
assert r.status_code == 200
assert r.headers.get('content-type') == "application/json"
r = client().simulate_get("/api/request/test/", headers={"Accept":"application/x-pem-file"})
assert r.status_code == 200
assert r.headers.get('content-type') == "application/x-pem-file"
r = client().simulate_get("/api/request/test/", headers={"Accept":"text/plain"})
assert r.status_code == 415
r = client().simulate_get("/api/request/nonexistant/", headers={"Accept":"application/json"})
assert r.status_code == 404
# Test command line interface # Test command line interface
result = runner.invoke(cli, ['list', '-srv']) result = runner.invoke(cli, ['list', '-srv'])
assert not result.exception assert not result.exception