libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

commit 3883732379d0dc00658f186145d6c4cf834a5d21
parent 6feb227dd3f9b14c081e26e6caa09675a7d96070
Author: MS <ms@taler.net>
Date:   Wed, 27 Jan 2021 16:08:39 +0100

testing malformed JSON handling

Diffstat:
Mintegration-tests/tests.py | 20+++++++++++++++++++-
Mnexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt | 1-
2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/integration-tests/tests.py b/integration-tests/tests.py @@ -511,7 +511,7 @@ def test_sandbox_camt(): assertResponse( post( - f"{PERSONA.banking.bank_base_url}/admin/payments/camt", + f"{persona.Banking.bank_base_url}/admin/payments/camt", json=dict(iban="GB33BUKB20201555555555", type=53) ) ) @@ -566,3 +566,21 @@ def test_schedule_deletion(): ), acceptedResponses=[404] ) + +def test_invalid_json(): + assertResponse( + post( + f"{PERSONA.nexus.base_url}/users", + data="malformed", + headers={"Content-Type": "application/json"}, + auth=auth.HTTPBasicAuth("admin", "x")), + acceptedResponses=[400] + ) + assertResponse( + post( + f"{PERSONA.banking.bank_base_url}/admin/ebics/hosts", + data="malformed", + headers={"Content-Type": "application/json"}, + auth=auth.HTTPBasicAuth("admin", "x")), + acceptedResponses=[400] + ) diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt @@ -138,7 +138,6 @@ suspend inline fun <reified T : Any> ApplicationCall.receiveJson(): T { } catch (e: MissingKotlinParameterException) { throw NexusError(HttpStatusCode.BadRequest, "Missing value for ${e.pathReference}") } catch (e: MismatchedInputException) { - // Note: POSTing "[]" gets here but e.pathReference is blank. throw NexusError(HttpStatusCode.BadRequest, "Invalid value for '${e.pathReference}'") } catch (e: JsonParseException) { throw NexusError(HttpStatusCode.BadRequest, "Invalid JSON")