gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] branch master updated (831eed3 -> 68616ce)


From: gnunet
Subject: [libeufin] branch master updated (831eed3 -> 68616ce)
Date: Tue, 15 Dec 2020 01:38:08 +0100

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

ms pushed a change to branch master
in repository libeufin.

    from 831eed3  Get add-incoming test to pass.
     new 6045f48  fix payto-parser
     new 68616ce  Taler wire gateways test.

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:
 integration-tests/tests.py                         |  1 -
 nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt    |  7 +++---
 nexus/src/main/kotlin/tech/libeufin/nexus/Taler.kt | 27 ++++++++++++--------
 util/src/main/kotlin/Payto.kt                      | 19 +++++++-------
 util/src/test/kotlin/PaytoTest.kt                  | 29 ++++++++++++++++------
 5 files changed, 53 insertions(+), 30 deletions(-)

diff --git a/integration-tests/tests.py b/integration-tests/tests.py
index fe15cf8..3eba263 100755
--- a/integration-tests/tests.py
+++ b/integration-tests/tests.py
@@ -282,7 +282,6 @@ def test_taler_facade_incoming(make_taler_facade):
             "taler/history/incoming?delta=5"]),
         auth=PERSONA.nexus.auth
     ))
-    print(resp.json().get("incoming_transactions"))
     assert len(resp.json().get("incoming_transactions")) == 1
 
 def test_taler_facade_outgoing(make_taler_facade):
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
index 465b59e..1e69bd3 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
@@ -66,7 +66,7 @@ object TalerIncomingPayments : LongIdTable() {
     val payment = reference("payment", NexusBankTransactionsTable)
     val reservePublicKey = text("reservePublicKey")
     val timestampMs = long("timestampMs")
-    val incomingPaytoUri = text("incomingPaytoUri")
+    val debtorPaytoUri = text("incomingPaytoUri")
 }
 
 class TalerIncomingPaymentEntity(id: EntityID<Long>) : LongEntity(id) {
@@ -75,7 +75,7 @@ class TalerIncomingPaymentEntity(id: EntityID<Long>) : 
LongEntity(id) {
     var payment by NexusBankTransactionEntity referencedOn 
TalerIncomingPayments.payment
     var reservePublicKey by TalerIncomingPayments.reservePublicKey
     var timestampMs by TalerIncomingPayments.timestampMs
-    var incomingPaytoUri by TalerIncomingPayments.incomingPaytoUri
+    var debtorPaytoUri by TalerIncomingPayments.debtorPaytoUri
 }
 
 /**
@@ -423,7 +423,8 @@ fun dbCreateTables(dbConnectionString: String) {
             FacadesTable,
             TalerFacadeStateTable,
             NexusScheduledTasksTable,
-            OfferedBankAccountsTable
+            OfferedBankAccountsTable,
+            NexusScheduledTasksTable
         )
     }
 }
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Taler.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/Taler.kt
index 7f07be3..52a6edd 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Taler.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Taler.kt
@@ -138,12 +138,11 @@ fun <T : Entity<Long>> SizedIterable<T>.orderTaler(delta: 
Int): List<T> {
 /**
  * Build an IBAN payto URI.
  */
-fun buildIbanPaytoUri(iban: String, bic: String?, name: String): String {
-    if (bic != null) {
-        return "payto://iban/$bic/$iban?receiver-name=$name"
-    } else {
-        return "payto://iban/$iban?receiver-name=$name"
-    }
+fun buildIbanPaytoUri(
+    iban: String, bic: String, name: String, direction: String
+): String {
+    val nameParam = if (direction == "DBIT") "sender-name" else "receiver-name"
+    return "payto://iban/$bic/$iban?$nameParam=$name"
 }
 
 /** Builds the comparison operator for history entries based on the sign of 
'delta'  */
@@ -396,11 +395,17 @@ private fun ingestIncoming(payment: 
NexusBankTransactionEntity, txDtls: Transact
         logger.warn("invalid public key")
         return
     }
+    if (debtorAgent.bic == null) {
+        logger.warn("Not allowing transactions missing the BIC.  IBAN and 
name: ${debtorIban}, ${debtorName}")
+        return
+    }
     TalerIncomingPaymentEntity.new {
         this.payment = payment
         reservePublicKey = reservePub
         timestampMs = System.currentTimeMillis()
-        incomingPaytoUri = buildIbanPaytoUri(debtorIban, debtorAgent.bic, 
debtorName)
+        debtorPaytoUri = buildIbanPaytoUri(
+            debtorIban, debtorAgent.bic, debtorName, "DBIT"
+        )
     }
     return
 }
@@ -494,7 +499,8 @@ private suspend fun historyOutgoing(call: ApplicationCall) {
                         debit_account = buildIbanPaytoUri(
                             subscriberBankAccount.iban,
                             subscriberBankAccount.bankCode,
-                            subscriberBankAccount.accountHolder
+                            subscriberBankAccount.accountHolder,
+                            "DBIT"
                         ),
                         exchange_base_url = 
"FIXME-to-request-along-subscriber-registration"
                     )
@@ -534,9 +540,10 @@ private suspend fun historyIncoming(call: 
ApplicationCall): Unit {
                         credit_account = buildIbanPaytoUri(
                             it.payment.bankAccount.iban,
                             it.payment.bankAccount.bankCode,
-                            it.payment.bankAccount.accountHolder
+                            it.payment.bankAccount.accountHolder,
+                            "CRDT"
                         ),
-                        debit_account = it.incomingPaytoUri
+                        debit_account = it.debtorPaytoUri
                     )
                 )
             }
diff --git a/util/src/main/kotlin/Payto.kt b/util/src/main/kotlin/Payto.kt
index a1cccee..a35aa71 100644
--- a/util/src/main/kotlin/Payto.kt
+++ b/util/src/main/kotlin/Payto.kt
@@ -1,7 +1,5 @@
 package tech.libeufin.util
 
-import io.ktor.http.HttpStatusCode
-import tech.libeufin.util.EbicsProtocolError
 import java.net.URI
 
 /**
@@ -10,28 +8,31 @@ import java.net.URI
 data class Payto(
     val name: String,
     val iban: String,
-    val bic: String = "NOTGIVEN"
+    val bic: String
 )
+class InvalidPaytoError(msg: String) : Exception(msg)
 
 fun parsePayto(paytoLine: String): Payto {
+    if (!"^payto://".toRegex().containsMatchIn(paytoLine)) throw 
InvalidPaytoError("Invalid payto line: $paytoLine")
     val javaParsedUri = try {
         URI(paytoLine)
     } catch (e: java.lang.Exception) {
-        throw EbicsProtocolError(HttpStatusCode.BadRequest, "'${paytoLine}' is 
not a valid URI")
+        throw InvalidPaytoError("'${paytoLine}' is not a valid URI")
     }
     if (javaParsedUri.scheme != "payto") {
-        throw EbicsProtocolError(HttpStatusCode.BadRequest, "'${paytoLine}' is 
not payto")
+        throw InvalidPaytoError("'${paytoLine}' is not payto")
     }
-    val iban = javaParsedUri.path.split("/").last()
     val queryStringAsList = javaParsedUri.query.split("&")
     // admit only ONE parameter: receiver-name.
     if (queryStringAsList.size != 1) {
-        throw EbicsProtocolError(HttpStatusCode.BadRequest, "'${paytoLine}' 
has unsupported query string")
+        throw InvalidPaytoError("'${paytoLine}' has unsupported query string")
     }
     val splitParameter = queryStringAsList.first().split("=")
     if (splitParameter.first() != "receiver-name" && splitParameter.first() != 
"sender-name") {
-        throw EbicsProtocolError(HttpStatusCode.BadRequest, "'${paytoLine}' 
has unsupported query string")
+        throw InvalidPaytoError("'${paytoLine}' has unsupported query string")
     }
     val receiverName = splitParameter.last()
-    return Payto(iban = iban, name = receiverName)
+    val split_path = javaParsedUri.path.split("/").filter { it.isNotEmpty() }
+    if (split_path.size != 2) throw InvalidPaytoError("BIC and IBAN are both 
mandatory ($split_path)")
+    return Payto(iban = split_path[1], bic = split_path[0], name = 
receiverName)
 }
\ No newline at end of file
diff --git a/util/src/test/kotlin/PaytoTest.kt 
b/util/src/test/kotlin/PaytoTest.kt
index 761c445..5c1f50a 100644
--- a/util/src/test/kotlin/PaytoTest.kt
+++ b/util/src/test/kotlin/PaytoTest.kt
@@ -1,26 +1,41 @@
 import org.junit.Test
 import tech.libeufin.util.EbicsProtocolError
+import tech.libeufin.util.InvalidPaytoError
 import tech.libeufin.util.parsePayto
 
 class PaytoTest {
 
     @Test
-    fun parsePaytoTest() {
-        val noBic = parsePayto("payto://iban/IBAN123?receiver-name=The%20Name")
-        assert(noBic.iban == "IBAN123" && noBic.name == "The Name")
-        val withBic = 
parsePayto("payto://iban/BIC123/IBAN123?receiver-name=The%20Name")
-        assert(withBic.iban == "IBAN123" && withBic.name == "The Name")
+    fun wrongCases() {
         try {
             parsePayto("http://iban/BIC123/IBAN123?receiver-name=The%20Name";)
-        } catch (e: EbicsProtocolError) {
+        } catch (e: InvalidPaytoError) {
+            println(e)
             println("wrong scheme was caught")
         }
         try {
             parsePayto(
                 
"payto://iban/BIC123/IBAN123?receiver-name=The%20Name&address=house"
             )
-        } catch (e: EbicsProtocolError) {
+        } catch (e: InvalidPaytoError) {
+            println(e)
             println("more than one parameter isn't allowed")
         }
+        try {
+            parsePayto(
+                
"payto:iban/BIC123/IBAN123?receiver-name=The%20Name&address=house"
+            )
+        } catch (e: InvalidPaytoError) {
+            println(e)
+            println("'://' missing, invalid Payto")
+        }
+    }
+
+    @Test
+    fun parsePaytoTest() {
+        val withBic = 
parsePayto("payto://iban/BIC123/IBAN123?receiver-name=The%20Name")
+        assert(withBic.iban == "IBAN123")
+        assert(withBic.bic == "BIC123")
+        assert(withBic.name == "The Name")
     }
 }
\ No newline at end of file

-- 
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]