libeufin

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

commit 523a32feb530c0b9392624a794a8984bf9f81c4a
parent 9187644df5b541b4991a48fa6268aa9ad6c9597b
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date:   Tue,  7 Apr 2020 23:39:18 +0200

Helper to extract URI parameters.

Diffstat:
Mnexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt | 6++++++
Mnexus/src/main/kotlin/tech/libeufin/nexus/taler.kt | 6++++--
Msandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt | 5-----
3 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt @@ -1,5 +1,6 @@ package tech.libeufin.nexus +import io.ktor.application.ApplicationCall import io.ktor.http.HttpStatusCode /** @@ -36,6 +37,11 @@ fun expectIdTransaction(param: String?): EbicsSubscriberEntity { return EbicsSubscriberEntity.findById(param) ?: throw NexusError(HttpStatusCode.NotFound, "Subscriber: $param not found") } +fun ApplicationCall.expectUrlParameter(name: String): String { + return this.request.queryParameters[name] + ?: throw NexusError(HttpStatusCode.BadRequest, "Parameter '$name' not provided in URI") +} + /* Needs a transaction{} block to be called */ fun expectAcctidTransaction(param: String?): EbicsAccountInfoEntity { if (param == null) { diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt @@ -101,7 +101,6 @@ class Taler(app: Route) { private data class TalerOutgoingHistory( var outgoing_transactions: MutableList<TalerOutgoingBankTransaction> = mutableListOf() ) - /** * Test APIs' data structures. */ @@ -116,7 +115,10 @@ class Taler(app: Route) { val row_id: Long ) - // throws error if password is wrong + /** + * throws error if password is wrong + * @param authorization the Authorization:-header line. + */ private fun authenticateRequest(authorization: String?) { val headerLine = authorization ?: throw NexusError( HttpStatusCode.BadRequest, "Authentication:-header line not found" diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt @@ -225,7 +225,6 @@ fun main() { } } routing { - post("/{id}/history") { val req = call.receive<CustomerHistoryRequest>() val customer = findCustomer(call.parameters["id"]) @@ -252,7 +251,6 @@ fun main() { call.respond(ret) return@post } - get("/{id}/balance") { val customer = findCustomer(call.parameters["id"]) val balance = calculateBalance(customer.id.value, null, null) @@ -264,7 +262,6 @@ fun main() { ) return@get } - get("/admin/subscribers") { var ret = AdminGetSubscribers() transaction { @@ -277,7 +274,6 @@ fun main() { call.respond(ret) return@get } - post("/admin/add/subscriber") { val body = call.receive<AdminAddSubscriberRequest>() @@ -332,7 +328,6 @@ fun main() { HttpStatusCode.OK ) return@post - } get("/ebics/hosts/{id}") { val resp = transaction {