libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

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

resolving #6770

Diffstat:
Mintegration-tests/tests.py | 34++++++++++++++++++++++++++++++++++
Mnexus/src/main/kotlin/tech/libeufin/nexus/DB.kt | 3+++
Mnexus/src/main/kotlin/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 @@ -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 @@ -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 @@ -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 {