diff options
author | Antoine A <> | 2024-01-25 09:47:46 +0100 |
---|---|---|
committer | Antoine A <> | 2024-01-25 09:47:46 +0100 |
commit | 18d9d91d049217f1de0514d274728198a2801005 (patch) | |
tree | 7e1ab14dd0cf0cf369e3dffc13b1ec47a10c37a7 | |
parent | 7723cf2b55bd8348577a1d228961985dcb02e9ff (diff) | |
download | libeufin-18d9d91d049217f1de0514d274728198a2801005.tar.gz libeufin-18d9d91d049217f1de0514d274728198a2801005.tar.bz2 libeufin-18d9d91d049217f1de0514d274728198a2801005.zip |
Improve ebics testbench adding support for Credit Suisse IsoTest
-rw-r--r-- | testbench/README.md | 32 | ||||
-rw-r--r-- | testbench/conf/netzbon.conf | 27 | ||||
-rw-r--r-- | testbench/conf/postfinance.conf | 26 | ||||
-rw-r--r-- | testbench/src/main/kotlin/Main.kt | 279 |
4 files changed, 179 insertions, 185 deletions
diff --git a/testbench/README.md b/testbench/README.md new file mode 100644 index 00000000..63cc81be --- /dev/null +++ b/testbench/README.md @@ -0,0 +1,32 @@ +# LibEuFin Test Bench + +## Interactive EBICS test + +To add a platform write a minimal configuration file at `testbench/test/PLATFORM/ebics.conf` such as : + + +``` ini +[nexus-ebics] +currency = CHF + +# Bank +HOST_BASE_URL = https://isotest.postfinance.ch/ebicsweb/ebicsweb +BANK_DIALECT = postfinance + +# EBICS IDs +HOST_ID = PFEBICS +USER_ID = PFC00563 +PARTNER_ID = PFC00563 + +IBAN = CH7789144474425692816 +``` + +To start the interactive EBICS test run : + +``` sh +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/ebics.edited.conf`. + +This minimal configuration will be augmented on start, you can find the full documentation at `testbench/test/PLATFORM/client-ebics-keys.json`.
\ No newline at end of file diff --git a/testbench/conf/netzbon.conf b/testbench/conf/netzbon.conf deleted file mode 100644 index 84aed7aa..00000000 --- a/testbench/conf/netzbon.conf +++ /dev/null @@ -1,27 +0,0 @@ -[paths] -LIBEUFIN_NEXUS_HOME = test/netzbon - -[nexus-ebics] -CURRENCY = CHF - -# Bank -HOST_BASE_URL = https://ebics.postfinance.ch/ebics/ebics.aspx -BANK_DIALECT = postfinance - -# EBICS IDs -HOST_ID = PFEBICS -USER_ID = 5183101 -PARTNER_ID = 51831 - -IBAN = CH4009000000160948810 -BIC = POFICHBEXXX -NAME = Genossenschaft Netz Soziale Oekonomie - -[nexus-fetch] -FREQUENCY = 5s - -[nexus-submit] -FREQUENCY = 5s - -[nexus-postgres] -CONFIG = postgres:///libeufincheck diff --git a/testbench/conf/postfinance.conf b/testbench/conf/postfinance.conf deleted file mode 100644 index 7799b13e..00000000 --- a/testbench/conf/postfinance.conf +++ /dev/null @@ -1,26 +0,0 @@ -[paths] -LIBEUFIN_NEXUS_HOME = test/postfinance - -[nexus-ebics] -currency = CHF - -# Bank -HOST_BASE_URL = https://isotest.postfinance.ch/ebicsweb/ebicsweb -BANK_DIALECT = postfinance - -# EBICS IDs -HOST_ID = PFEBICS -USER_ID = PFC00563 -PARTNER_ID = PFC00563 - -#IBAN = CH2989144971918294289 -IBAN = CH7789144474425692816 - -[nexus-fetch] -FREQUENCY = 5s - -[nexus-submit] -FREQUENCY = 5s - -[nexus-postgres] -CONFIG = postgres:///libeufincheck diff --git a/testbench/src/main/kotlin/Main.kt b/testbench/src/main/kotlin/Main.kt index 60055e42..204ffc00 100644 --- a/testbench/src/main/kotlin/Main.kt +++ b/testbench/src/main/kotlin/Main.kt @@ -64,161 +64,176 @@ fun CliktCommandTestResult.assertErr(msg: String? = null) { assertEquals(1, statusCode, msg) } -enum class Kind { - postfinance, - netzbon +data class Kind(val name: String, val settings: String?) { + val test get() = settings != null } class Cli : CliktCommand("Run integration tests on banks provider") { - val kind: Kind by argument().enum<Kind>() + val platform by argument() + override fun run() { - val name = kind.name - step("Test init $name") + // List available platform + val platforms = Path("test").listDirectoryEntries().filter { it.isDirectory() }.map { it.getFileName().toString() } + if (!platforms.contains(platform)) { + println("Unknown platform '$platform', expected one of $platforms") + throw ProgramResult(1) + } - runBlocking { - Path("test/$name").createDirectories() - val conf = "conf/$name.conf" - val log = "DEBUG" - val flags = " -c $conf -L $log" - val ebicsFlags = "$flags --transient --debug-ebics test/$name" - val cfg = loadConfig(conf) - - val clientKeysPath = cfg.requirePath("nexus-ebics", "client_private_keys_file") - val bankKeysPath = cfg.requirePath("nexus-ebics", "bank_public_keys_file") + // Augment config + val simpleCfg = Path("test/$platform/ebics.conf").readText() + val conf = "test/$platform/ebics.edited.conf" + Path(conf).writeText("""$simpleCfg + [paths] + LIBEUFIN_NEXUS_HOME = test/$platform + + [nexus-fetch] + FREQUENCY = 5s + + [nexus-submit] + FREQUENCY = 5s + + [nexus-postgres] + CONFIG = postgres:///libeufincheck + """) + val cfg = loadConfig(conf) + + // Check if paltform is known + val kind = when (cfg.requireString("nexus-ebics", "host_base_url")) { + "https://isotest.postfinance.ch/ebicsweb/ebicsweb" -> + Kind("PostFinance IsoTest", "https://isotest.postfinance.ch/corporates/user/settings/ebics") + "https://iso20022test.credit-suisse.com/ebicsweb/ebicsweb" -> + Kind("Credit Suisse isoTest", "https://iso20022test.credit-suisse.com/user/settings/ebics") + "https://ebics.postfinance.ch/ebics/ebics.aspx" -> + Kind("PostFinance", null) + else -> Kind("Unknown", null) + } + + // Prepare cmds + val log = "DEBUG" + val flags = " -c $conf -L $log" + val ebicsFlags = "$flags --transient --debug-ebics test/$platform" + val clientKeysPath = cfg.requirePath("nexus-ebics", "client_private_keys_file") + val bankKeysPath = cfg.requirePath("nexus-ebics", "bank_public_keys_file") + + var hasClientKeys = clientKeysPath.exists() + var hasBankKeys = bankKeysPath.exists() + + // Alternative payto ? + val payto = "payto://iban/CH6208704048981247126?receiver-name=Grothoff%20Hans" - var hasClientKeys = clientKeysPath.exists() - var hasBankKeys = bankKeysPath.exists() + runBlocking { + step("Test init ${kind.name}") if (ask("Reset DB ? y/n>") == "y") nexusCmd.test("dbinit -r $flags").assertOk() else nexusCmd.test("dbinit $flags").assertOk() val nexusDb = NexusDb("postgresql:///libeufincheck") - when (kind) { - Kind.postfinance -> { - if (hasClientKeys || hasBankKeys) { - if (ask("Reset keys ? y/n>") == "y") { - if (hasClientKeys) clientKeysPath.deleteIfExists() - if (hasBankKeys) bankKeysPath.deleteIfExists() - hasClientKeys = false - hasBankKeys = false + val cmds = buildMap<String, suspend () -> Unit> { + put("reset-db", suspend { + nexusCmd.test("dbinit -r $flags").assertOk() + }) + put("recover", suspend { + step("Recover old transactions") + nexusCmd.test("ebics-fetch $ebicsFlags --pinned-start 2022-01-01").assertOk() + }) + put("fetch", suspend { + step("Fetch new transactions") + nexusCmd.test("ebics-fetch $ebicsFlags").assertOk() + }) + put("submit", suspend { + step("Submit pending transactions") + nexusCmd.test("ebics-submit $ebicsFlags").assertOk() + }) + put("logs", suspend { + step("Fetch HAC logs") + nexusCmd.test("ebics-fetch $ebicsFlags --only-logs").assertOk() + }) + put("ack", suspend { + step("Fetch CustomerPaymentStatusReport") + nexusCmd.test("ebics-fetch $ebicsFlags --only-ack").assertOk() + }) + if (kind.test) { + put("reset-keys", suspend { + clientKeysPath.deleteIfExists() + bankKeysPath.deleteIfExists() + hasClientKeys = false + hasBankKeys = false + }) + put("tx", suspend { + step("Test submit one transaction") + nexusDb.initiatedPaymentCreate(InitiatedPayment( + amount = TalerAmount("CFH:42"), + creditPaytoUri = IbanPayto(payto).requireFull(), + wireTransferSubject = "single transaction test", + initiationTime = Instant.now(), + requestUid = Base32Crockford.encode(randBytes(16)) + )) + nexusCmd.test("ebics-submit $ebicsFlags").assertOk() + }) + put("txs", suspend { + step("Test submit many transaction") + repeat(4) { + nexusDb.initiatedPaymentCreate(InitiatedPayment( + amount = TalerAmount("CFH:${100L+it}"), + creditPaytoUri = IbanPayto(payto).requireFull(), + wireTransferSubject = "multi transaction test $it", + initiationTime = Instant.now(), + requestUid = Base32Crockford.encode(randBytes(16)) + )) } - } - - if (!hasClientKeys) { + nexusCmd.test("ebics-submit $ebicsFlags").assertOk() + }) + } else { + put("tx", suspend { + step("Submit new transaction") + // TODO interactive payment editor + nexusDb.initiatedPaymentCreate(InitiatedPayment( + amount = TalerAmount("CFH:1.1"), + creditPaytoUri = IbanPayto(payto).requireFull(), + wireTransferSubject = "single transaction test", + initiationTime = Instant.now(), + requestUid = Base32Crockford.encode(randBytes(16)) + )) + nexusCmd.test("ebics-submit $ebicsFlags").assertOk() + }) + } + } + + while (true) { + if (!hasClientKeys) { + if (kind.test) { step("Test INI order") - ask("Got to https://isotest.postfinance.ch/corporates/user/settings/ebics and click on 'Reset EBICS user'.\nPress Enter when done>") + ask("Got to ${kind.settings} and click on 'Reset EBICS user'.\nPress Enter when done>") nexusCmd.test("ebics-setup $flags") .assertErr("ebics-setup should failed the first time") - } - - if (!hasBankKeys) { - step("Test HIA order") - ask("Got to https://isotest.postfinance.ch/corporates/user/settings/ebics and click on 'Activate EBICS user'.\nPress Enter when done>") - nexusCmd.test("ebics-setup --auto-accept-keys $flags") - .assertOk("ebics-setup should succeed the second time") - } - - val payto = "payto://iban/CH2989144971918294289?receiver-name=Test" - - step("Test fetch transactions") - nexusCmd.test("ebics-fetch $ebicsFlags --pinned-start 2022-01-01").assertOk() - - while (true) { - when (ask("Run 'fetch', 'submit', 'tx', 'txs', 'logs', 'ack' or 'exit'>")) { - "fetch" -> { - step("Fetch new transactions") - nexusCmd.test("ebics-fetch $ebicsFlags").assertOk() - } - "tx" -> { - step("Test submit one transaction") - nexusDb.initiatedPaymentCreate(InitiatedPayment( - amount = TalerAmount("CFH:42"), - creditPaytoUri = IbanPayto(payto).requireFull(), - wireTransferSubject = "single transaction test", - initiationTime = Instant.now(), - requestUid = Base32Crockford.encode(randBytes(16)) - )) - nexusCmd.test("ebics-submit $ebicsFlags").assertOk() - } - "txs" -> { - step("Test submit many transaction") - repeat(4) { - nexusDb.initiatedPaymentCreate(InitiatedPayment( - amount = TalerAmount("CFH:${100L+it}"), - creditPaytoUri = IbanPayto(payto).requireFull(), - wireTransferSubject = "multi transaction test $it", - initiationTime = Instant.now(), - requestUid = Base32Crockford.encode(randBytes(16)) - )) - } - nexusCmd.test("ebics-submit $ebicsFlags").assertOk() - } - "submit" -> { - step("Submit pending transactions") - nexusCmd.test("ebics-submit $ebicsFlags").assertOk() - } - "logs" -> { - step("Fetch logs") - nexusCmd.test("ebics-fetch $ebicsFlags --only-logs").assertOk() - } - "ack" -> { - step("Fetch ack") - nexusCmd.test("ebics-fetch $ebicsFlags --only-ack").assertOk() - } - "exit" -> break - } - } - } - Kind.netzbon -> { - if (!hasClientKeys) + ask("Got to ${kind.settings} and click on 'Activate EBICS user'.\nPress Enter when done>") + } else { throw Exception("Clients keys are required to run netzbon tests") - - if (!hasBankKeys) { - step("Test HIA order") - nexusCmd.test("ebics-setup --auto-accept-keys $flags").assertOk("ebics-setup should succeed the second time") } + } - step("Test fetch transactions") - nexusCmd.test("ebics-fetch $ebicsFlags --pinned-start 2022-01-01").assertOk() + if (!hasBankKeys) { + step("Test HIA order") + nexusCmd.test("ebics-setup --auto-accept-keys $flags") + .assertOk("ebics-setup should succeed the second time") + } - while (true) { - when (ask("Run 'fetch', 'submit', 'logs', 'ack' or 'exit'>")) { - "fetch" -> { - step("Fetch new transactions") - nexusCmd.test("ebics-fetch $ebicsFlags").assertOk() - } - "submit" -> { - step("Submit pending transactions") - nexusCmd.test("ebics-submit $ebicsFlags").assertOk() - } - "tx" -> { - step("Submit new transaction") - // TODO interactive payment editor - nexusDb.initiatedPaymentCreate(InitiatedPayment( - amount = TalerAmount("CFH:1.1"), - creditPaytoUri = IbanPayto("payto://iban/CH6208704048981247126?receiver-name=Grothoff%20Hans").requireFull(), - wireTransferSubject = "single transaction test", - initiationTime = Instant.now(), - requestUid = Base32Crockford.encode(randBytes(16)) - )) - nexusCmd.test("ebics-submit $ebicsFlags").assertOk() - } - "logs" -> { - step("Fetch logs") - nexusCmd.test("ebics-fetch $ebicsFlags --only-logs").assertOk() - } - "ack" -> { - step("Fetch ack") - nexusCmd.test("ebics-fetch $ebicsFlags --only-ack").assertOk() - } - "exit" -> break - } + val arg = ask("testbench >")!!.trim() + if (arg == "exit") break + val cmd = cmds[arg] + if (cmd != null) { + cmd() + } else { + if (arg != "?" && arg != "help") { + println("Unknown command '$arg'") + } + println("Commands:") + for ((name, _) in cmds) { + println(" $name") } } } } - - step("Test succeed") } } |