libeufin

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

commit f1fead3a0ac70a218d510b5ef337c70b83b13136
parent 83f3fc7c27175af42943a3691f32db646b67a05f
Author: MS <ms@taler.net>
Date:   Mon, 12 Dec 2022 23:12:03 +0100

test IBAN conflict

Diffstat:
Mnexus/src/test/kotlin/MakeEnv.kt | 28+++++++++++++++++++++++-----
Anexus/src/test/kotlin/SandboxAccessApiTest.kt | 97+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mutil/src/main/kotlin/JSON.kt | 2+-
3 files changed, 121 insertions(+), 6 deletions(-)

diff --git a/nexus/src/test/kotlin/MakeEnv.kt b/nexus/src/test/kotlin/MakeEnv.kt @@ -36,20 +36,19 @@ val userKeys = EbicsKeys( * Cleans up the DB file afterwards. */ fun withTestDatabase(f: () -> Unit) { - val dbfile = TEST_DB_CONN - File(dbfile).also { + File(TEST_DB_FILE).also { if (it.exists()) { it.delete() } } - Database.connect("jdbc:sqlite:$dbfile") - dbDropTables(dbfile) + Database.connect("jdbc:sqlite:$TEST_DB_FILE") + dbDropTables(TEST_DB_CONN) tech.libeufin.sandbox.dbDropTables(TEST_DB_CONN) try { f() } finally { - File(dbfile).also { + File(TEST_DB_FILE).also { if (it.exists()) { it.delete() } @@ -189,4 +188,23 @@ fun withNexusAndSandboxUser(f: () -> Unit) { prepSandboxDb() f() } +} + +// Creates tables and the default demobank. +fun withSandboxTestDatabase(f: () -> Unit) { + withTestDatabase { + tech.libeufin.sandbox.dbCreateTables(TEST_DB_CONN) + transaction { + DemobankConfigEntity.new { + currency = "TESTKUDOS" + bankDebtLimit = 10000 + usersDebtLimit = 1000 + allowRegistrations = true + name = "default" + this.withSignupBonus = false + captchaUrl = "http://example.com/" // unused + } + } + f() + } } \ No newline at end of file diff --git a/nexus/src/test/kotlin/SandboxAccessApiTest.kt b/nexus/src/test/kotlin/SandboxAccessApiTest.kt @@ -0,0 +1,96 @@ +import com.fasterxml.jackson.databind.ObjectMapper +import io.ktor.client.features.* +import io.ktor.client.request.* +import io.ktor.client.statement.* +import io.ktor.client.utils.* +import io.ktor.http.* +import io.ktor.server.testing.* +import io.netty.handler.codec.http.HttpResponseStatus +import kotlinx.coroutines.runBlocking +import org.junit.Test +import tech.libeufin.sandbox.sandboxApp +import tech.libeufin.util.buildBasicAuthLine + +class SandboxAccessApiTest { + + val mapper = ObjectMapper() + @Test + fun registerTest() { + // Test IBAN conflict detection. + withSandboxTestDatabase { + withTestApplication(sandboxApp) { + runBlocking { + val bodyFoo = mapper.writeValueAsString(object { + val username = "x" + val password = "y" + val iban = FOO_USER_IBAN + }) + val bodyBar = mapper.writeValueAsString(object { + val username = "y" + val password = "y" + val iban = FOO_USER_IBAN // conflicts + }) + val bodyBaz = mapper.writeValueAsString(object { + val username = "y" + val password = "y" + val iban = BAR_USER_IBAN + }) + // The following block would allow to save many LOC, + // but gets somehow ignored. + /*client.config { + this.defaultRequest { + headers { + append( + HttpHeaders.ContentType, + ContentType.Application.Json + ) + } + expectSuccess = false + } + }*/ + // Succeeds. + client.post<HttpResponse>( + urlString = "/demobanks/default/access-api/testing/register", + ) { + this.body = bodyFoo + expectSuccess = true + headers { + append( + HttpHeaders.ContentType, + ContentType.Application.Json + ) + } + } + // Hits conflict, because of the same IBAN. + val r = client.post<HttpResponse>( + "/demobanks/default/access-api/testing/register" + ) { + this.body = bodyBar + expectSuccess = false + headers { + append( + HttpHeaders.ContentType, + ContentType.Application.Json + ) + } + } + assert(r.status.value == HttpResponseStatus.CONFLICT.code()) + // Succeeds, because of a new IBAN. + client.post<HttpResponse>( + "/demobanks/default/access-api/testing/register" + ) { + this.body = bodyBaz + expectSuccess = true + headers { + append( + HttpHeaders.ContentType, + ContentType.Application.Json + ) + } + } + } + } + + } + } +} +\ No newline at end of file diff --git a/util/src/main/kotlin/JSON.kt b/util/src/main/kotlin/JSON.kt @@ -36,7 +36,7 @@ data class RawPayment( val amount: String, val currency: String, val subject: String, - val date: String? = null, + val date: String, val uid: String, // FIXME: explain this value. val direction: String, // FIXME: this following value should be restricted to only DBIT/CRDT.