gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] branch master updated: resolving #6770


From: gnunet
Subject: [libeufin] branch master updated: resolving #6770
Date: Fri, 26 Feb 2021 11:06:31 +0100

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

ms pushed a commit to branch master
in repository libeufin.

The following commit(s) were added to refs/heads/master by this push:
     new 3ade91b  resolving #6770
3ade91b is described below

commit 3ade91b4426c58703c314d6875d07704e72ec4fe
Author: MS <ms@taler.net>
AuthorDate: Fri Feb 26 11:06:27 2021 +0100

    resolving #6770
---
 integration-tests/tests.py                         | 34 ++++++++++++++++++++++
 nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt    |  3 ++
 .../tech/libeufin/nexus/server/NexusServer.kt      | 21 +++++++++----
 3 files changed, 52 insertions(+), 6 deletions(-)

diff --git a/integration-tests/tests.py b/integration-tests/tests.py
index 1f24fc8..ce47800 100755
--- a/integration-tests/tests.py
+++ b/integration-tests/tests.py
@@ -384,6 +384,40 @@ def make_taler_facade():
         )
     )
 
+def test_facade_name_collision():
+    assertResponse(
+        post(
+            f"{user0.nexus.base_url}/facades",
+            json=dict(
+                name=user0.nexus.taler_facade_name,
+                type="taler-wire-gateway",
+                config=dict(
+                    currency="EUR",
+                    bankAccount=user0.nexus.bank_label,
+                    bankConnection=user0.nexus.bank_connection,
+                    reserveTransferLevel="UNUSED",
+                )
+            ),
+            auth=user0.nexus.auth
+        )
+    )
+    assertResponse(
+        post(
+            f"{user0.nexus.base_url}/facades",
+            json=dict(
+                name=user0.nexus.taler_facade_name,
+                type="taler-wire-gateway",
+                config=dict(
+                    currency="EUR",
+                    bankAccount=user0.nexus.bank_label,
+                    bankConnection=user0.nexus.bank_connection,
+                    reserveTransferLevel="UNUSED",
+                )
+            ),
+            auth=user0.nexus.auth
+        ),
+        acceptedResponses=[400]
+    )
 
 def test_taler_facade_config(make_taler_facade):
     resp = assertResponse(
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
index 37b6e28..75c5f88 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
@@ -339,6 +339,9 @@ object FacadesTable : LongIdTable() {
     val facadeName = text("facadeName")
     val type = text("type")
     val creator = reference("creator", NexusUsersTable)
+    init {
+        uniqueIndex(facadeName)
+    }
 }
 
 class FacadeEntity(id: EntityID<Long>) : LongEntity(id) {
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 a679d28..90c6f81 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt
@@ -42,6 +42,7 @@ import io.ktor.server.netty.*
 import io.ktor.util.*
 import io.ktor.util.pipeline.*
 import io.ktor.utils.io.*
+import org.jetbrains.exposed.exceptions.ExposedSQLException
 import org.jetbrains.exposed.sql.and
 import org.jetbrains.exposed.sql.transactions.transaction
 import org.slf4j.event.Level
@@ -956,13 +957,21 @@ fun serverMain(dbName: String, host: String, port: Int) {
                     HttpStatusCode.NotImplemented,
                     "Facade type '${body.type}' is not implemented"
                 )
-                val newFacade = transaction {
-                    val user = authenticateRequest(call.request)
-                    FacadeEntity.new {
-                        facadeName = body.name
-                        type = body.type
-                        creator = user
+                val newFacade = try {
+                    transaction {
+                        val user = authenticateRequest(call.request)
+                        FacadeEntity.new {
+                            facadeName = body.name
+                            type = body.type
+                            creator = user
+                        }
                     }
+                } 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 {
                     TalerFacadeStateEntity.new {

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