libeufin

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

commit 0692f2f29d6106deca9097e83aa4e3f98017a881
parent cc8d7fcfce835312ecd2ec9db6c449dba34840b8
Author: Antoine A <>
Date:   Mon, 20 Nov 2023 18:45:08 +0000

Test iban payto uri normalization

Diffstat:
Mbank/src/main/kotlin/tech/libeufin/bank/helpers.kt | 12+++++-------
Mbank/src/test/kotlin/DatabaseTest.kt | 13+++++++++++++
2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/bank/src/main/kotlin/tech/libeufin/bank/helpers.kt b/bank/src/main/kotlin/tech/libeufin/bank/helpers.kt @@ -29,7 +29,7 @@ import io.ktor.server.routing.RouteSelectorEvaluation import io.ktor.server.routing.RoutingResolveContext import io.ktor.server.util.* import io.ktor.util.pipeline.PipelineContext -import java.net.URL +import java.net.* import java.time.* import java.time.temporal.* import java.util.* @@ -56,7 +56,7 @@ suspend fun ApplicationCall.bankInfo(db: Database): BankInfo ) // Generates a new Payto-URI with IBAN scheme. -fun genIbanPaytoUri(): String = "payto://iban/SANDBOXX/${getIban()}" +fun genIbanPaytoUri(): String = "payto://iban/${getIban()}" /** * Builds the taler://withdraw-URI. Such URI will serve the requests @@ -67,7 +67,7 @@ fun genIbanPaytoUri(): String = "payto://iban/SANDBOXX/${getIban()}" * https://$BANK_URL/taler-integration */ fun getTalerWithdrawUri(baseUrl: String, woId: String) = url { - val baseUrlObj = URL(baseUrl) + val baseUrlObj = URI(baseUrl).toURL() protocol = URLProtocol( name = "taler".plus(if (baseUrlObj.protocol.lowercase() == "http") "+http" else ""), defaultPort = -1 ) @@ -98,8 +98,7 @@ fun ApplicationCall.uuidUriComponent(name: String): UUID { try { return UUID.fromString(expectUriComponent(name)) } catch (e: Exception) { - logger.error(e.message) - throw badRequest("UUID uri component malformed") + throw badRequest("UUID uri component malformed: ${e.message}") } } @@ -107,8 +106,7 @@ fun ApplicationCall.longUriComponent(name: String): Long { try { return expectUriComponent(name).toLong() } catch (e: Exception) { - logger.error(e.message) - throw badRequest("UUID uri component malformed") + throw badRequest("Long uri component malformed: ${e.message}") } } diff --git a/bank/src/test/kotlin/DatabaseTest.kt b/bank/src/test/kotlin/DatabaseTest.kt @@ -171,6 +171,19 @@ class DatabaseTest { assertEquals(Pair(true, false), cTry(this, "new-code", expired)) } }} + + // Testing iban payto uri normalization + @Test + fun ibanPayto() = setup { db, ctx -> + val expected = "payto://iban/CH9300762011623852957" + val inputs = listOf( + "payto://iban/BIC/CH9300762011623852957?receiver-name=NotGiven", + "payto://iban/ch%209300-7620-1162-3852-957", + ) + for (input in inputs) { + assertEquals(expected, IbanPayTo(input).canonical) + } + } }