[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libeufin] 02/02: test IBAN conflict
From: |
gnunet |
Subject: |
[libeufin] 02/02: test IBAN conflict |
Date: |
Mon, 12 Dec 2022 23:12:24 +0100 |
This is an automated email from the git hooks/post-receive script.
ms pushed a commit to branch master
in repository libeufin.
commit f1fead3a0ac70a218d510b5ef337c70b83b13136
Author: MS <ms@taler.net>
AuthorDate: Mon Dec 12 23:12:03 2022 +0100
test IBAN conflict
---
nexus/src/test/kotlin/MakeEnv.kt | 28 ++++++--
nexus/src/test/kotlin/SandboxAccessApiTest.kt | 96 +++++++++++++++++++++++++++
util/src/main/kotlin/JSON.kt | 2 +-
3 files changed, 120 insertions(+), 6 deletions(-)
diff --git a/nexus/src/test/kotlin/MakeEnv.kt b/nexus/src/test/kotlin/MakeEnv.kt
index b4a11254..58b2affb 100644
--- 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
new file mode 100644
index 00000000..ac230203
--- /dev/null
+++ 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
index c4a97fcb..e54cdd77 100644
--- 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.
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.