gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] branch master updated (d1c303c6 -> 1aa96820)


From: gnunet
Subject: [libeufin] branch master updated (d1c303c6 -> 1aa96820)
Date: Tue, 31 Jan 2023 17:22:56 +0100

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

ms pushed a change to branch master
in repository libeufin.

    from d1c303c6 update Debian rules for 0.9.1
     new 0b3de446 Polishing
     new a15a8e31 test logging
     new d15577e3 indentation, comments
     new 1aa96820 tests

The 4 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:
 cli/tests/debit_test.sh                            |  4 +-
 nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt    |  8 +-
 .../main/kotlin/tech/libeufin/nexus/FacadeUtil.kt  |  5 +-
 nexus/src/main/kotlin/tech/libeufin/nexus/Taler.kt |  8 +-
 .../tech/libeufin/nexus/server/NexusServer.kt      | 49 ++++++------
 nexus/src/test/kotlin/MakeEnv.kt                   | 52 +++++++++++--
 nexus/src/test/kotlin/TalerTest.kt                 | 87 ++++++++++++++++++++++
 .../src/main/kotlin/tech/libeufin/sandbox/Main.kt  |  2 +-
 8 files changed, 176 insertions(+), 39 deletions(-)
 create mode 100644 nexus/src/test/kotlin/TalerTest.kt

diff --git a/cli/tests/debit_test.sh b/cli/tests/debit_test.sh
index 9df06364..9e1ad97e 100755
--- a/cli/tests/debit_test.sh
+++ b/cli/tests/debit_test.sh
@@ -50,7 +50,7 @@ echo -n "Try to surpass the debit threshold (user pays 
admin)..."
   --amount MANA:99999 &> /dev/null || true
 echo DONE
 
-echo -n Check the amount is zero...
+echo -n Check the amount is still the initial zero...
 RESP=$(libeufin-cli sandbox --sandbox-url http://localhost:5000/ demobank info 
--bank-account www)
 BALANCE=$(echo $RESP | jq -r '.balance.amount')
 if [ "$BALANCE" != "MANA:0" ]; then
@@ -67,7 +67,7 @@ libeufin-sandbox \
   MANA:9999 "Go debit again."  &> /dev/null || true
 echo DONE
 
-echo -n Check the amount is again zero...
+echo -n Check the amount is still the initial zero...
 RESP=$(libeufin-cli sandbox --sandbox-url http://localhost:5000/ demobank info 
--bank-account www)
 BALANCE=$(echo $RESP | jq -r '.balance.amount')
 if [ "$BALANCE" != "MANA:0" ]; then
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
index 9e0798e0..6d3f586b 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
@@ -380,9 +380,7 @@ object FacadesTable : LongIdTable() {
     val facadeName = text("facadeName")
     val type = text("type")
     val creator = reference("creator", NexusUsersTable)
-    init {
-        uniqueIndex(facadeName)
-    }
+    init { uniqueIndex(facadeName) }
 }
 
 class FacadeEntity(id: EntityID<Long>) : LongEntity(id) {
@@ -402,9 +400,7 @@ object FacadeStateTable : LongIdTable() {
     val bankConnection = text("bankConnection")
     val currency = text("currency")
 
-    /**
-     *  "statement", "report", "notification"
-     **/
+    // "statement", "report", "notification"
     val reserveTransferLevel = text("reserveTransferLevel")
     val facade = reference("facade", FacadesTable)
 
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/FacadeUtil.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/FacadeUtil.kt
index 0227489c..7fdd2c26 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/FacadeUtil.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/FacadeUtil.kt
@@ -72,7 +72,10 @@ fun ingestFacadeTransactions(
             when (tx.creditDebitIndicator) {
                 CreditDebitIndicator.CRDT -> {
                     if (incomingFilterCb != null) {
-                        incomingFilterCb(it, details)
+                        incomingFilterCb(
+                            it, // payment DB object
+                            details // wire transfer details
+                        )
                     }
                 }
                 else -> Unit
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Taler.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/Taler.kt
index 1777522c..957373d8 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Taler.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Taler.kt
@@ -237,7 +237,10 @@ private suspend fun talerTransfer(call: ApplicationCall) {
     )
 }
 
-fun talerFilter(payment: NexusBankTransactionEntity, txDtls: 
TransactionDetails) {
+fun talerFilter(
+    payment: NexusBankTransactionEntity,
+    txDtls: TransactionDetails
+) {
     var isInvalid = false // True when pub is invalid or duplicate.
     val subject = txDtls.unstructuredRemittanceInformation
     val debtorName = txDtls.debtor?.name
@@ -366,8 +369,7 @@ fun maybeTalerRefunds(bankAccount: NexusBankAccountEntity, 
lastSeenId: Long) {
                         it[NexusBankTransactionsTable.bankAccount] == 
bankAccount.id,
                 "Cannot refund a _outgoing_ payment!"
             )
-            // FIXME: the amount to refund should be reduced, according to the 
bounce fee
-            // see bug #7116.
+            // FIXME #7116
             addPaymentInitiation(
                 Pain001Data(
                     creditorIban = debtorAccount.iban,
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt
index b8c33065..b600fbcd 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt
@@ -46,6 +46,7 @@ import io.ktor.server.routing.*
 import io.ktor.util.*
 import org.jetbrains.exposed.exceptions.ExposedSQLException
 import org.jetbrains.exposed.sql.and
+import org.jetbrains.exposed.sql.transactions.TransactionManager
 import org.jetbrains.exposed.sql.transactions.transaction
 import org.slf4j.event.Level
 import tech.libeufin.nexus.*
@@ -211,13 +212,24 @@ val nexusApp: Application.() -> Unit = {
                 )
             )
         }
-        exception<BadRequestException> { call, cause ->
-            logger.error("Exception while handling '${call.request.uri}', 
${cause.message}")
+        exception<BadRequestException> { call, wrapper ->
+            var rootCause = wrapper.cause
+            while (rootCause?.cause != null) rootCause = rootCause.cause
+            val errorMessage: String? = rootCause?.message ?: wrapper.message
+            if (errorMessage == null) {
+                logger.error("The bank didn't detect the cause of a bad 
request, fail.")
+                logger.error(wrapper.stackTraceToString())
+                throw NexusError(
+                    HttpStatusCode.InternalServerError,
+                    "Did not find bad request details."
+                )
+            }
+            logger.error(errorMessage)
             call.respond(
                 HttpStatusCode.BadRequest,
                 ErrorResponse(
                     code = 
TalerErrorCode.TALER_EC_LIBEUFIN_NEXUS_GENERIC_ERROR.code,
-                    detail = cause.message ?: "Bad request but did not find 
exact cause.",
+                    detail = errorMessage,
                     hint = "Malformed request or unacceptable values"
                 )
             )
@@ -953,32 +965,27 @@ val nexusApp: Application.() -> Unit = {
                     HttpStatusCode.NotImplemented,
                     "Facade type '${body.type}' is not implemented"
                 )
-            val newFacade = try {
+            try {
                 transaction {
                     val user = authenticateRequest(call.request)
-                    FacadeEntity.new {
+                    val newFacade = FacadeEntity.new {
                         facadeName = body.name
                         type = body.type
                         creator = user
                     }
+                    FacadeStateEntity.new {
+                        bankAccount = body.config.bankAccount
+                        bankConnection = body.config.bankConnection
+                        reserveTransferLevel = body.config.reserveTransferLevel
+                        facade = newFacade
+                        currency = body.config.currency
+                    }
                 }
-            } catch (e: ExposedSQLException) {
-                logger.error("Could not persist facade name/type/creator: $e")
-                throw NexusError(
-                    HttpStatusCode.BadRequest,
-                    "Server could not persist data, possibly due to 
unavailable facade name"
-                )
-            }
-            transaction {
-                FacadeStateEntity.new {
-                    bankAccount = body.config.bankAccount
-                    bankConnection = body.config.bankConnection
-                    reserveTransferLevel = body.config.reserveTransferLevel
-                    facade = newFacade
-                    currency = body.config.currency
-                }
+            } catch (e: Exception) {
+                logger.error(e.stackTraceToString())
+                throw internalServerError("Could not create facade")
             }
-            call.respondText("Facade created")
+            call.respond(HttpStatusCode.OK)
             return@post
         }
 
diff --git a/nexus/src/test/kotlin/MakeEnv.kt b/nexus/src/test/kotlin/MakeEnv.kt
index bb25a0b6..b8adad2d 100644
--- a/nexus/src/test/kotlin/MakeEnv.kt
+++ b/nexus/src/test/kotlin/MakeEnv.kt
@@ -1,9 +1,13 @@
+import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
 import org.jetbrains.exposed.sql.Database
 import org.jetbrains.exposed.sql.statements.api.ExposedBlob
 import org.jetbrains.exposed.sql.transactions.transaction
+import org.jetbrains.exposed.sql.transactions.transactionManager
 import tech.libeufin.nexus.*
 import tech.libeufin.nexus.dbCreateTables
 import tech.libeufin.nexus.dbDropTables
+import tech.libeufin.nexus.server.FetchLevel
+import tech.libeufin.nexus.server.FetchSpecAllJson
 import tech.libeufin.sandbox.*
 import tech.libeufin.util.CryptoUtil
 import tech.libeufin.util.EbicsInitState
@@ -59,11 +63,10 @@ fun withTestDatabase(f: () -> Unit) {
         }
     }
     Database.connect("jdbc:sqlite:$TEST_DB_FILE")
+    // ).transactionManager.defaultIsolationLevel = 
java.sql.Connection.TRANSACTION_SERIALIZABLE
     dbDropTables(TEST_DB_CONN)
     tech.libeufin.sandbox.dbDropTables(TEST_DB_CONN)
-    try {
-        f()
-    }
+    try { f() }
     finally {
         File(TEST_DB_FILE).also {
             if (it.exists()) {
@@ -73,13 +76,22 @@ fun withTestDatabase(f: () -> Unit) {
     }
 }
 
+val reportSpec: String = jacksonObjectMapper().
+writerWithDefaultPrettyPrinter().
+writeValueAsString(
+    FetchSpecAllJson(
+        level = FetchLevel.REPORT,
+        "foo"
+    )
+)
+
 fun prepNexusDb() {
     dbCreateTables(TEST_DB_CONN)
     transaction {
         val u = NexusUserEntity.new {
             username = "foo"
-            passwordHash = "foo"
-            superuser = false
+            passwordHash = CryptoUtil.hashpw("foo")
+            superuser = true
         }
         val c = NexusBankConnectionEntity.new {
             connectionId = "foo"
@@ -118,6 +130,36 @@ fun prepNexusDb() {
             highestSeenBankMessageSerialId = 0
             accountHolder = "bar"
         }
+        NexusScheduledTaskEntity.new {
+            resourceType = "bank-account"
+            resourceId = "foo"
+            this.taskCronspec = "* * *" // Every second.
+            this.taskName = "read-report"
+            this.taskType = "fetch"
+            this.taskParams = reportSpec
+        }
+        NexusScheduledTaskEntity.new {
+            resourceType = "bank-account"
+            resourceId = "foo"
+            this.taskCronspec = "* * *" // Every second.
+            this.taskName = "send-payment"
+            this.taskType = "submit"
+            this.taskParams = "{}"
+        }
+        // Giving 'foo' a Taler facade.
+        val f = FacadeEntity.new {
+            facadeName = "taler"
+            type = "taler-wire-gateway"
+            creator = u
+        }
+        FacadeStateEntity.new {
+            bankAccount = "foo"
+            bankConnection = "foo"
+            currency = "TESTKUDOS"
+            reserveTransferLevel = "report"
+            facade = f
+            highestSeenMessageSerialId = 0
+        }
     }
 }
 
diff --git a/nexus/src/test/kotlin/TalerTest.kt 
b/nexus/src/test/kotlin/TalerTest.kt
new file mode 100644
index 00000000..bc117307
--- /dev/null
+++ b/nexus/src/test/kotlin/TalerTest.kt
@@ -0,0 +1,87 @@
+import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
+import io.ktor.client.plugins.*
+import io.ktor.client.request.*
+import io.ktor.http.*
+import io.ktor.server.testing.*
+import kotlinx.coroutines.*
+import org.jetbrains.exposed.sql.transactions.TransactionManager
+import org.jetbrains.exposed.sql.transactions.transaction
+import org.junit.Ignore
+import org.junit.Test
+import tech.libeufin.nexus.*
+import tech.libeufin.nexus.bankaccount.fetchBankAccountTransactions
+import tech.libeufin.nexus.server.FetchLevel
+import tech.libeufin.nexus.server.FetchSpecAllJson
+import tech.libeufin.nexus.server.client
+import tech.libeufin.nexus.server.nexusApp
+import tech.libeufin.sandbox.sandboxApp
+import tech.libeufin.sandbox.wireTransfer
+
+// This class tests the features related to the Taler facade.
+class TalerTest {
+
+    @Ignore // Ignoring because no assert takes place.
+    @Test // Triggering a refund because of a duplicate reserve pub.
+    fun refundTest() {
+        withNexusAndSandboxUser {
+            // Creating a Taler facade for the user 'foo'.
+            testApplication {
+                application(nexusApp)
+                client.post("/facades") {
+                    expectSuccess = true
+                    contentType(ContentType.Application.Json)
+                    basicAuth("foo", "foo")
+                    setBody("""
+                        { "name":"foo-facade",
+                          "type":"taler-wire-gateway",
+                          "config": {
+                            "bankAccount":"foo",
+                            "bankConnection":"foo",
+                            "currency":"TESTKUDOS",
+                            "reserveTransferLevel":"report"
+                          }
+                    }""".trimIndent()
+                    )
+                }
+            }
+            wireTransfer(
+                "bar",
+                "foo",
+                demobank = "default",
+                "5WFM8PXN7Y315RVZFJ280299B94W1HR1AAHH6XNDYEJBC0T3E5N0",
+                "TESTKUDOS:3"
+            )
+            testApplication {
+                application(sandboxApp)
+                // Nexus downloads the fresh transaction.
+                fetchBankAccountTransactions(
+                    client,
+                    fetchSpec = FetchSpecAllJson(
+                        level = FetchLevel.REPORT,
+                        "foo"
+                    ),
+                    "foo"
+                )
+            }
+            wireTransfer(
+                "bar",
+                "foo",
+                demobank = "default",
+                "5WFM8PXN7Y315RVZFJ280299B94W1HR1AAHH6XNDYEJBC0T3E5N0",
+                "TESTKUDOS:3"
+            )
+            testApplication {
+                application(sandboxApp)
+                // Nexus downloads the new transaction, having a duplicate 
subject.
+                fetchBankAccountTransactions(
+                    client,
+                    fetchSpec = FetchSpecAllJson(
+                        level = FetchLevel.REPORT,
+                        "foo"
+                    ),
+                    "foo"
+                )
+            }
+        }
+    }
+}
\ No newline at end of file
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
index d0ab1a8b..072a5acc 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -571,7 +571,7 @@ val sandboxApp: Application.() -> Unit = {
                 HttpStatusCode.BadRequest,
                 SandboxErrorJson(
                     error = SandboxErrorDetailJson(
-                        type = "util-error",
+                        type = "sandbox-error",
                         description = errorMessage
                     )
                 )

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