libeufin

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

commit 9496810ba34a119e74df7fe8b1deeaebf064a321
parent 63e9009c6256dd1a00223b2324d4a171b0c0788e
Author: Antoine A <>
Date:   Wed, 30 Jul 2025 16:19:22 +0200

common: add unix domain socket support

Diffstat:
Mcommon/src/main/kotlin/Config.kt | 4++--
Mcommon/src/main/kotlin/api/server.kt | 5+++--
Mcontrib/bank.conf | 3---
Mtestbench/conf/integration.conf | 2++
Mtestbench/src/test/kotlin/IntegrationTest.kt | 35+++++++++++++++++++++++------------
5 files changed, 30 insertions(+), 19 deletions(-)

diff --git a/common/src/main/kotlin/Config.kt b/common/src/main/kotlin/Config.kt @@ -20,7 +20,7 @@ package tech.libeufin.common sealed interface ServerConfig { - data class Unix(val path: String, val mode: Int): ServerConfig + data class Unix(val path: String): ServerConfig data class Tcp(val addr: String, val port: Int): ServerConfig } @@ -28,6 +28,6 @@ fun TalerConfig.loadServerConfig(section: String): ServerConfig { val sect = section(section) return sect.mapLambda("serve", "server method", mapOf( "tcp" to { ServerConfig.Tcp(sect.string("address").orNull() ?: sect.string("bind_to").require(), sect.number("port").require()) }, - "unix" to { ServerConfig.Unix(sect.string("unixpath").require(), sect.number("unixpath_mode").require()) } + "unix" to { ServerConfig.Unix(sect.string("unixpath").require()) } )).require() } \ No newline at end of file diff --git a/common/src/main/kotlin/api/server.kt b/common/src/main/kotlin/api/server.kt @@ -293,8 +293,9 @@ fun serve(cfg: tech.libeufin.common.ServerConfig, api: Application.() -> Unit) { } } } - is ServerConfig.Unix -> - throw Exception("Can only serve via TCP") + is ServerConfig.Unix -> { + unixConnector(cfg.path) + } } }, module = api diff --git a/contrib/bank.conf b/contrib/bank.conf @@ -75,9 +75,6 @@ BIND_TO = 0.0.0.0 # Which unix domain path should we bind to? Only used if SERVE is unix. # UNIXPATH = libeufin-bank.sock -# What should be the file access permissions for UNIXPATH? Only used if SERVE is unix. -# UNIXPATH_MODE = 660 - # Path to spa files SPA = $DATADIR/spa/ diff --git a/testbench/conf/integration.conf b/testbench/conf/integration.conf @@ -9,6 +9,8 @@ allow_conversion = YES FIAT_CURRENCY = EUR tan_sms = libeufin-tan-file.sh tan_email = libeufin-tan-fail.sh +SERVE = unix +UNIXPATH = /tmp/libeufin.sock [nexus-ebics] CURRENCY = EUR diff --git a/testbench/src/test/kotlin/IntegrationTest.kt b/testbench/src/test/kotlin/IntegrationTest.kt @@ -45,6 +45,8 @@ import kotlin.io.path.readText import kotlin.test.* import tech.libeufin.nexus.db.Database as NexusDb +const val UNIX_SOCKET_PATH: String = "/tmp/libeufin.sock"; + fun CliktCommand.run(cmd: String) { val result = test(cmd) if (result.statusCode != 0) @@ -56,7 +58,7 @@ fun HttpResponse.assertNoContent() { assertEquals(HttpStatusCode.NoContent, this.status) } -fun server(lambda: () -> Unit) { +fun server(client: HttpClient, lambda: () -> Unit) { globalTestTokens.clear() // Start the HTTP server in another thread kotlin.concurrent.thread(isDaemon = true) { @@ -64,12 +66,7 @@ fun server(lambda: () -> Unit) { } // Wait for the HTTP server to be up runBlocking { - HttpClient(CIO) { - install(HttpRequestRetry) { - maxRetries = 10 - constantDelay(200, 100) - } - }.get("http://0.0.0.0:8080/config") + client.get("/config") } } @@ -99,19 +96,33 @@ class IntegrationTest { val nexusCmd = LibeufinNexus() val bankCmd = LibeufinBank() val client = HttpClient(CIO) { + install(HttpRequestRetry) { + maxRetries = 10 + constantDelay(200, 100) + } defaultRequest { - url("http://0.0.0.0:8080/") + url("http://socket/") + unixSocket(UNIX_SOCKET_PATH) } } @Test fun mini() { + val client = HttpClient(CIO) { + install(HttpRequestRetry) { + maxRetries = 10 + constantDelay(200, 100) + } + defaultRequest { + url("http://0.0.0.0:8080/") + } + } val flags = "-c conf/mini.conf -L DEBUG" bankCmd.run("dbinit $flags -r") bankCmd.run("passwd admin admin-password $flags") bankCmd.run("dbinit $flags") // Idempotent - server { + server(client) { bankCmd.run("serve $flags") } @@ -122,7 +133,7 @@ class IntegrationTest { bankCmd.run("gc $flags") - server { + server(client) { nexusCmd.run("serve $flags") } engine?.stop(0, 0) @@ -196,7 +207,7 @@ class IntegrationTest { db.checkCount(2, 1, 1) // Start server - server { + server(client) { bankCmd.run("serve $flags") } @@ -261,7 +272,7 @@ class IntegrationTest { nexusCmd.run("dbinit $flags") // Idempotent bankCmd.run("dbinit $flags") // Idempotent - server { + server(client) { bankCmd.run("serve $flags") }