From 85e328381ef80605e590af21846b3176cbbf66ac Mon Sep 17 00:00:00 2001 From: Rodolfo Miranda Date: Fri, 26 Apr 2024 14:40:45 -0300 Subject: [PATCH 1/4] error 400 on serder validation --- src/keria/app/credentialing.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/keria/app/credentialing.py b/src/keria/app/credentialing.py index eb816226..30e06574 100644 --- a/src/keria/app/credentialing.py +++ b/src/keria/app/credentialing.py @@ -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 as e: + rep.status = falcon.HTTP_400 + rep.text = e.args[0] + return regk = iserder.ked['ri'] if regk not in agent.rgy.tevers: From 343803d333f6c36a3e8b4c6b7deabedf2ea74d10 Mon Sep 17 00:00:00 2001 From: Rodolfo Miranda Date: Fri, 26 Apr 2024 15:00:21 -0300 Subject: [PATCH 2/4] macos-13 in CI --- .github/workflows/python-app-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app-ci.yml b/.github/workflows/python-app-ci.yml index c4097aeb..34b39b8c 100644 --- a/.github/workflows/python-app-ci.yml +++ b/.github/workflows/python-app-ci.yml @@ -17,7 +17,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ macos-latest, ubuntu-latest ] + os: [ macos-13, ubuntu-latest ] steps: - uses: actions/checkout@v3 From 90c5432953d00fa107d80c24e8af168ea4b9dca8 Mon Sep 17 00:00:00 2001 From: Rodolfo Miranda Date: Tue, 30 Apr 2024 15:20:30 -0300 Subject: [PATCH 3/4] test coverage --- tests/app/test_credentialing.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/app/test_credentialing.py b/tests/app/test_credentialing.py index d2d26328..94f3ed9f 100644 --- a/tests/app/test_credentialing.py +++ b/tests/app/test_credentialing.py @@ -292,6 +292,11 @@ 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({}).encode("utf-8")) + assert result.status_code == 400 + assert result.json == {'description': "required field 'acdc' missing from request", + 'title': '400 Bad Request'} result = client.simulate_post(path="/identifiers/issuer/credentials", body=json.dumps(body).encode("utf-8")) op = result.json From 36fa77f56aa690379d0bad1510c730798848683a Mon Sep 17 00:00:00 2001 From: Rodolfo Miranda Date: Thu, 2 May 2024 19:31:19 -0300 Subject: [PATCH 4/4] add JSONDecodeError --- src/keria/app/credentialing.py | 2 +- tests/app/test_credentialing.py | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/keria/app/credentialing.py b/src/keria/app/credentialing.py index 30e06574..8201b3d7 100644 --- a/src/keria/app/credentialing.py +++ b/src/keria/app/credentialing.py @@ -553,7 +553,7 @@ def on_post(self, req, rep, name): anc = serdering.SerderKERI(sad=httping.getRequiredParam(body, "ixn")) else: anc = serdering.SerderKERI(sad=httping.getRequiredParam(body, "rot")) - except kering.ValidationError as e: + except (kering.ValidationError, json.decoder.JSONDecodeError) as e: rep.status = falcon.HTTP_400 rep.text = e.args[0] return diff --git a/tests/app/test_credentialing.py b/tests/app/test_credentialing.py index 94f3ed9f..c0725153 100644 --- a/tests/app/test_credentialing.py +++ b/tests/app/test_credentialing.py @@ -293,11 +293,6 @@ def test_issue_credential(helpers, seeder): 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({}).encode("utf-8")) - assert result.status_code == 400 - assert result.json == {'description': "required field 'acdc' missing from request", - 'title': '400 Bad Request'} - result = client.simulate_post(path="/identifiers/issuer/credentials", body=json.dumps(body).encode("utf-8")) op = result.json @@ -309,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'