From 7e744fe79031d081b45efdd96e47658c70d2e984 Mon Sep 17 00:00:00 2001 From: iFergal Date: Wed, 7 Aug 2024 20:48:08 +0100 Subject: [PATCH] fix: get cred by SAID should return 404 if missing instead of 500 --- src/keria/app/credentialing.py | 7 ++++--- tests/app/test_credentialing.py | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/keria/app/credentialing.py b/src/keria/app/credentialing.py index 62bdba77..ad6ba7c4 100644 --- a/src/keria/app/credentialing.py +++ b/src/keria/app/credentialing.py @@ -656,15 +656,16 @@ def on_get(req, rep, said): """ agent = req.context.agent accept = req.get_header("accept") + + if not agent.rgy.reger.creds.get(keys=(said,)): + raise falcon.HTTPNotFound(description=f"credential for said {said} not found.") + if accept == "application/json+cesr": rep.content_type = "application/json+cesr" data = CredentialResourceEnd.outputCred(agent.hby, agent.rgy, said) else: rep.content_type = "application/json" creds = agent.rgy.reger.cloneCreds([coring.Saider(qb64=said)], db=agent.hby.db) - if not creds: - raise falcon.HTTPNotFound(description=f"credential for said {said} not found.") - data = json.dumps(creds[0]).encode("utf-8") rep.status = falcon.HTTP_200 diff --git a/tests/app/test_credentialing.py b/tests/app/test_credentialing.py index c4efb06d..980c6b23 100644 --- a/tests/app/test_credentialing.py +++ b/tests/app/test_credentialing.py @@ -435,6 +435,10 @@ def test_credentialing_ends(helpers, seeder): assert res.status_code == 200 assert res.headers['content-type'] == "application/json+cesr" + headers = {"Accept": "application/json+cesr"} + res = client.simulate_get(f"/credentials/doesNotExistSaid", headers=headers) + assert res.status_code == 404 + def test_revoke_credential(helpers, seeder): with helpers.openKeria() as (agency, agent, app, client):