diff options
author | Antoine A <> | 2024-04-19 07:50:29 +0900 |
---|---|---|
committer | Antoine A <> | 2024-04-19 07:50:29 +0900 |
commit | fccc2eff22a0528658d6d1a42ac27e5dd2b4f34c (patch) | |
tree | 019e4e390ef9784280b21162c1becf1eef1a22a9 /testbench | |
parent | 9d8599f68e063c47eba1a9b1348f79f6357023b2 (diff) | |
download | libeufin-fccc2eff22a0528658d6d1a42ac27e5dd2b4f34c.tar.gz libeufin-fccc2eff22a0528658d6d1a42ac27e5dd2b4f34c.tar.bz2 libeufin-fccc2eff22a0528658d6d1a42ac27e5dd2b4f34c.zip |
Improve EBICS testbench
Diffstat (limited to 'testbench')
-rw-r--r-- | testbench/README.md | 15 | ||||
-rw-r--r-- | testbench/build.gradle | 1 | ||||
-rw-r--r-- | testbench/src/main/kotlin/Main.kt | 42 |
3 files changed, 51 insertions, 7 deletions
diff --git a/testbench/README.md b/testbench/README.md index 6c377ff8..e065114f 100644 --- a/testbench/README.md +++ b/testbench/README.md @@ -5,6 +5,7 @@ To add a platform write a minimal configuration file at `testbench/test/PLATFORM/ebics.conf` such as : ``` ini +# testbench/test/PLATFORM/ebics.conf [nexus-ebics] currency = CHF @@ -30,4 +31,16 @@ make testbench platform=PLATFORM If HOST_BASE_URL is one a known test platform we will generate and then offer to reset client private keys to test keys registration, otherwise, we will expect existing keys to be found at `testbench/test/PLATFORM/client-ebics-keys.json`. -This minimal configuration will be augmented on start, you can find the full documentation at `testbench/test/PLATFORM/ebics.edited.conf`.
\ No newline at end of file +This minimal configuration will be augmented on start, you can find the full documentation at `testbench/test/PLATFORM/ebics.edited.conf`. + +By default, the testbench will use a random dummy IBAN when issuing transactions, but you can specify a real IBAN for real-life testing in the testbench configuration at `testbench/test/config.json` : + +``` json +// testbench/test/PLATFORM/ebics.conf +{ + "payto": { + "CHF": "payto://iban/CH4189144589712575493?receiver-name=John%20Smith", + "EUR": "payto://iban/DE54500105177452372744?receiver-name=John%20Smith" + } +} +``` diff --git a/testbench/build.gradle b/testbench/build.gradle index 93fb6a46..4dda8348 100644 --- a/testbench/build.gradle +++ b/testbench/build.gradle @@ -1,6 +1,7 @@ plugins { id("kotlin") id("application") + id("org.jetbrains.kotlin.plugin.serialization") version "$kotlin_version" } java { diff --git a/testbench/src/main/kotlin/Main.kt b/testbench/src/main/kotlin/Main.kt index ed7fcd02..7ba9c7e3 100644 --- a/testbench/src/main/kotlin/Main.kt +++ b/testbench/src/main/kotlin/Main.kt @@ -23,13 +23,17 @@ import com.github.ajalt.clikt.core.CliktCommand import com.github.ajalt.clikt.core.ProgramResult import com.github.ajalt.clikt.parameters.arguments.argument import com.github.ajalt.clikt.testing.test +import io.ktor.http.URLBuilder +import io.ktor.http.takeFrom import io.ktor.client.* import io.ktor.client.engine.cio.* import kotlinx.coroutines.runBlocking +import kotlinx.serialization.Serializable import tech.libeufin.nexus.LibeufinNexusCommand import tech.libeufin.nexus.loadBankKeys import tech.libeufin.nexus.loadClientKeys import tech.libeufin.nexus.loadConfig +import tech.libeufin.nexus.loadJsonFile import kotlin.io.path.* val nexusCmd = LibeufinNexusCommand() @@ -64,6 +68,11 @@ data class Kind(val name: String, val settings: String?) { val test get() = settings != null } +@Serializable +data class Config( + val payto: Map<String, String> +) + class Cli : CliktCommand("Run integration tests on banks provider") { val platform by argument() @@ -105,6 +114,10 @@ class Cli : CliktCommand("Run integration tests on banks provider") { else -> Kind("Unknown", null) } + // Read testbench config + val benchCfg: Config = loadJsonFile(Path("test/config.json"), "testbench config") + ?: Config(emptyMap()) + // Prepare cmds val log = "DEBUG" val flags = " -c $conf -L $log" @@ -113,11 +126,15 @@ class Cli : CliktCommand("Run integration tests on banks provider") { val bankKeysPath = cfg.requirePath("nexus-ebics", "bank_public_keys_file") val currency = cfg.requireString("nexus-ebics", "currency") - val payto = when (currency) { - "CHF" -> "payto://iban/CH6208704048981247126?receiver-name=Grothoff%20Hans" - "EUR" -> "payto://iban/GENODEM1GLS/DE76430609674126675300?receiver-name=Grothoff%20Hans" - else -> throw Exception("Missing test payto for $currency") - } + val dummyPaytos = mapOf( + "CHF" to "payto://iban/CH4189144589712575493?receiver-name=John%20Smith", + "EUR" to "payto://iban/DE54500105177452372744?receiver-name=John%20Smith" + ) + val dummyPayto = dummyPaytos[currency] + ?: throw Exception("Missing dummy payto for $currency") + val payto = benchCfg.payto[currency] ?: dummyPayto + ?: throw Exception("Missing test payto for $currency") + val recoverDoc = when (cfg.requireString("nexus-ebics", "bank_dialect")) { "gls" -> "statement" else -> "notification" @@ -175,12 +192,25 @@ class Cli : CliktCommand("Run integration tests on banks provider") { } else { put("tx", suspend { step("Submit new transaction") - // TODO interactive payment editor nexusCmd.run("initiate-payment $flags \"$payto&amount=$currency:1.1&message=single%20transaction%20test\"") nexusCmd.run("ebics-submit $ebicsFlags") Unit }) } + put("tx-bad-name", suspend { + val badPayto = URLBuilder().takeFrom(payto) + badPayto.parameters.set("receiver-name", "John Smith") + step("Submit new transaction with a bad name") + nexusCmd.run("initiate-payment $flags \"$badPayto&amount=$currency:1.1&message=This%20should%20fail%20because%20bad%20name\"") + nexusCmd.run("ebics-submit $ebicsFlags") + Unit + }) + put("tx-dummy", suspend { + step("Submit new transaction to a dummy IBAN") + nexusCmd.run("initiate-payment $flags \"$dummyPayto&amount=$currency:1.1&message=This%20should%20fail%20because%20dummy\"") + nexusCmd.run("ebics-submit $ebicsFlags") + Unit + }) } while (true) { var clientKeys = loadClientKeys(clientKeysPath) |