diff options
author | Antoine A <> | 2023-11-20 18:45:08 +0000 |
---|---|---|
committer | Antoine A <> | 2023-11-20 18:45:08 +0000 |
commit | 0692f2f29d6106deca9097e83aa4e3f98017a881 (patch) | |
tree | 769c2802012f6046e3c183f377ad0af05c0c4c73 | |
parent | cc8d7fcfce835312ecd2ec9db6c449dba34840b8 (diff) | |
download | libeufin-0692f2f29d6106deca9097e83aa4e3f98017a881.tar.gz libeufin-0692f2f29d6106deca9097e83aa4e3f98017a881.tar.bz2 libeufin-0692f2f29d6106deca9097e83aa4e3f98017a881.zip |
Test iban payto uri normalization
-rw-r--r-- | bank/src/main/kotlin/tech/libeufin/bank/helpers.kt | 12 | ||||
-rw-r--r-- | bank/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 index 9ea82067..b8cc8992 100644 --- 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 index e73e2244..82a57f43 100644 --- 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) + } + } } |