libeufin

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

commit c094c812a75d373791ceb228d073b90ea2415f90
parent 0ee8d69d27567a4f28b6e2312a66f5d232bba48b
Author: MS <ms@taler.net>
Date:   Sat, 11 Mar 2023 21:36:29 +0100

/history/incoming: no negative start param.

Diffstat:
Mnexus/src/main/kotlin/tech/libeufin/nexus/Taler.kt | 7+++++--
Mnexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt | 2+-
Mnexus/src/test/kotlin/TalerTest.kt | 3++-
3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Taler.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Taler.kt @@ -131,11 +131,14 @@ fun getComparisonOperator(delta: Int, start: Long, table: IdTable<Long>): Op<Boo } } -fun expectLong(param: String?): Long { +fun expectLong(param: String?, allowNegative: Boolean = false): Long { if (param == null) throw badRequest("'$param' is not Long") - return try { param.toLong() } catch (e: Exception) { + val maybeLong = try { param.toLong() } catch (e: Exception) { throw badRequest("'$param' is not Long") } + if (!allowNegative && maybeLong < 0) + throw badRequest("Not expecting a negative: $param") + return maybeLong } // Helper handling 'start' being optional and its dependence on 'delta'. diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt @@ -190,7 +190,7 @@ val nexusApp: Application.() -> Unit = { ) } exception<UtilError> { call, cause -> - logger.error("Exception while handling '${call.request.uri}'", cause.message) + logger.error("Exception while handling '${call.request.uri}': ${cause.message}") call.respond( cause.statusCode, message = ErrorResponse( diff --git a/nexus/src/test/kotlin/TalerTest.kt b/nexus/src/test/kotlin/TalerTest.kt @@ -32,11 +32,12 @@ class TalerTest { application(nexusApp) runBlocking { launch { - val r = client.get("/facades/taler/taler-wire-gateway/history/incoming?delta=5") { + val r = client.get("/facades/taler/taler-wire-gateway/history/incoming?delta=5&start=3") { expectSuccess = false contentType(ContentType.Application.Json) basicAuth("foo", "foo") } + assert(r.status.value == HttpStatusCode.OK.value) val j = mapper.readTree(r.readBytes()) val reservePubFromTwg = j.get("incoming_transactions").get(0).get("reserve_pub").asText() assert(reservePubFromTwg == reservePub)