gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] branch master updated (1d08ec59 -> 0692f2f2)


From: gnunet
Subject: [libeufin] branch master updated (1d08ec59 -> 0692f2f2)
Date: Mon, 20 Nov 2023 19:45:24 +0100

This is an automated email from the git hooks/post-receive script.

antoine pushed a change to branch master
in repository libeufin.

    from 1d08ec59 Common auth test routine
     new cc8d7fcf Validate contact data with anastatis regex
     new 0692f2f2 Test iban payto uri normalization

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 bank/src/main/kotlin/tech/libeufin/bank/TalerMessage.kt | 14 +++++++++++++-
 bank/src/main/kotlin/tech/libeufin/bank/helpers.kt      | 12 +++++-------
 bank/src/test/kotlin/DatabaseTest.kt                    | 13 +++++++++++++
 3 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/bank/src/main/kotlin/tech/libeufin/bank/TalerMessage.kt 
b/bank/src/main/kotlin/tech/libeufin/bank/TalerMessage.kt
index 49d9229e..65e8c142 100644
--- a/bank/src/main/kotlin/tech/libeufin/bank/TalerMessage.kt
+++ b/bank/src/main/kotlin/tech/libeufin/bank/TalerMessage.kt
@@ -84,7 +84,19 @@ data class TokenSuccessResponse(
 data class ChallengeContactData(
     val email: String? = null,
     val phone: String? = null
-)
+) {
+    init {
+        if (email != null && !EMAIL_PATTERN.matches(email))
+            throw badRequest("email contact data '$email' is malformed")
+
+        if (phone != null && !PHONE_PATTERN.matches(phone))
+            throw badRequest("phone contact data '$phone' is malformed")
+    }
+    companion object {
+        private val EMAIL_PATTERN = 
Regex("[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}")
+        private val PHONE_PATTERN = Regex("^\\+?[0-9]+$")
+    }
+}
 
 // Type expected at POST /accounts
 @Serializable
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)
+        }
+    }
 }
 
 

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]