Skip to content

Commit

Permalink
Merge pull request WebOfTrust#234 from roots-id/serder-validation-error
Browse files Browse the repository at this point in the history
Return 400 when Serder validation fails
  • Loading branch information
2byrds authored May 6, 2024
2 parents b74d5cc + 36fa77f commit 44cc2d8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
18 changes: 11 additions & 7 deletions src/keria/app/credentialing.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,13 +546,17 @@ def on_post(self, req, rep, name):
hab = agent.hby.habByName(name)
if hab is None:
raise falcon.HTTPNotFound(description="name is not a valid reference to an identifier")

creder = serdering.SerderACDC(sad=httping.getRequiredParam(body, "acdc"))
iserder = serdering.SerderKERI(sad=httping.getRequiredParam(body, "iss"))
if "ixn" in body:
anc = serdering.SerderKERI(sad=httping.getRequiredParam(body, "ixn"))
else:
anc = serdering.SerderKERI(sad=httping.getRequiredParam(body, "rot"))
try:
creder = serdering.SerderACDC(sad=httping.getRequiredParam(body, "acdc"))
iserder = serdering.SerderKERI(sad=httping.getRequiredParam(body, "iss"))
if "ixn" in body:
anc = serdering.SerderKERI(sad=httping.getRequiredParam(body, "ixn"))
else:
anc = serdering.SerderKERI(sad=httping.getRequiredParam(body, "rot"))
except (kering.ValidationError, json.decoder.JSONDecodeError) as e:
rep.status = falcon.HTTP_400
rep.text = e.args[0]
return

regk = iserder.ked['ri']
if regk not in agent.rgy.tevers:
Expand Down
5 changes: 4 additions & 1 deletion tests/app/test_credentialing.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def test_issue_credential(helpers, seeder):
assert result.status_code == 404
assert result.json == {'description': "name is not a valid reference to an identifier",
'title': '404 Not Found'}

result = client.simulate_post(path="/identifiers/issuer/credentials", body=json.dumps(body).encode("utf-8"))
op = result.json

Expand All @@ -304,6 +304,9 @@ def test_issue_credential(helpers, seeder):

assert agent.credentialer.complete(creder.said) is True

body["acdc"]["a"]["LEI"] = "ACDC10JSON000197_"
result = client.simulate_post(path="/identifiers/issuer/credentials", body=json.dumps(body).encode("utf-8"))
assert result.status_code == 400

def test_credentialing_ends(helpers, seeder):
salt = b'0123456789abcdef'
Expand Down

0 comments on commit 44cc2d8

Please sign in to comment.