commit 478947a7e131a1659a29bc48031f813360b5eab1 parent 7ea6b65786704ec04f6f42d669680c0b1e30de3c Author: MS <ms@taler.net> Date: Thu, 9 Jul 2020 18:14:51 +0200 Catching CAMT parsing errors. Diffstat:
5 files changed, 22 insertions(+), 14 deletions(-)
diff --git a/integration-tests/test-bankConnection.py b/integration-tests/test-bankConnection.py @@ -135,11 +135,14 @@ assertResponse( ) ) -connectionsList = assertResponse( +resp = assertResponse( get("http://localhost:5001/bank-connections") ) -for el in connectionsList.json(): +connectionsList = resp.json().get("bankConnections") +assert(connectionsList != None) + +for el in connectionsList: print(el) if el.get("name") == "my-ebics": print("fail: account not deleted!") diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Taler.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Taler.kt @@ -285,7 +285,6 @@ private suspend fun talerTransfer(call: ApplicationCall) { row.id.value } return call.respond( - HttpStatusCode.OK, TextContent( customConverter( TalerTransferResponse( @@ -496,10 +495,7 @@ private suspend fun historyOutgoing(call: ApplicationCall) { } } } - call.respond( - HttpStatusCode.OK, - TextContent(customConverter(history), ContentType.Application.Json) - ) + call.respond(TextContent(customConverter(history), ContentType.Application.Json)) } /** diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/bankaccount/BankAccount.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/bankaccount/BankAccount.kt @@ -29,6 +29,7 @@ import org.w3c.dom.Document import tech.libeufin.nexus.* import tech.libeufin.nexus.ebics.fetchEbicsBySpec import tech.libeufin.nexus.ebics.submitEbicsPaymentInitiation +import tech.libeufin.nexus.iso20022.CamtParsingError import tech.libeufin.nexus.iso20022.CreditDebitIndicator import tech.libeufin.nexus.iso20022.parseCamtMessage import tech.libeufin.nexus.server.FetchSpecJson @@ -130,10 +131,15 @@ fun processCamtMessage( if (acct == null) { throw NexusError(HttpStatusCode.NotFound, "user not found") } - val res = parseCamtMessage(camtDoc) - + val res = try { + parseCamtMessage(camtDoc) + } catch (e: CamtParsingError) { + throw NexusError( + HttpStatusCode.BadGateway, + "Invalid CAMT received from bank" + ) + } val stamp = ZonedDateTime.parse(res.creationDateTime, DateTimeFormatter.ISO_DATE_TIME).toInstant().toEpochMilli() - when (code) { "C52" -> { val s = acct.lastReportCreationTimestamp diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsNexus.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsNexus.kt @@ -319,7 +319,9 @@ private fun getEbicsSubscriberDetails(bankConnectionId: String): EbicsClientSubs if (transport == null) { throw NexusError(HttpStatusCode.NotFound, "transport not found") } - val subscriber = EbicsSubscriberEntity.find { EbicsSubscribersTable.nexusBankConnection eq transport.id }.first() + val subscriber = EbicsSubscriberEntity.find { + EbicsSubscribersTable.nexusBankConnection eq transport.id + }.first() // transport exists and belongs to caller. return getEbicsSubscriberDetailsInternal(subscriber) } @@ -368,7 +370,7 @@ fun Route.ebicsBankProtocolRoutes(client: HttpClient) { post("test-host") { val r = call.receiveJson<EbicsHostTestRequest>() val qr = doEbicsHostVersionQuery(client, r.ebicsBaseUrl, r.ebicsHostId) - call.respond(HttpStatusCode.OK, qr) + call.respond(qr) return@post } } diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt @@ -236,6 +236,7 @@ fun serverMain(dbName: String, host: String) { exception<EbicsProtocolError> { cause -> logger.error("Exception while handling '${call.request.uri}'", cause) call.respond( + cause.httpStatusCode, NexusErrorJson( error = NexusErrorDetailJson( type = "ebics-protocol-error", @@ -287,7 +288,7 @@ fun serverMain(dbName: String, host: String) { superuser = currentUser.superuser ) } - call.respond(HttpStatusCode.OK, ret) + call.respond(ret) return@get } @@ -300,7 +301,7 @@ fun serverMain(dbName: String, host: String) { } } val usersResp = UsersResponse(users) - call.respond(HttpStatusCode.OK, usersResp) + call.respond(usersResp) return@get }