commit c05a2ff6bf6d9d8067aaec6a23f411972295eabf
parent 4ebe7337a586779b7ae8414523188cdf7e768ed8
Author: MS <ms@taler.net>
Date: Tue, 26 May 2020 13:55:28 +0200
Custom DB for tests.
Plus fixing the conversion from dashed date
to Long timestamp.
Diffstat:
4 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/integration-tests/test-ebics-highlevel.py b/integration-tests/test-ebics-highlevel.py
@@ -58,6 +58,8 @@ SUBSCRIBER_BIC = "BUKBGB22"
SUBSCRIBER_NAME = "Oliver Smith"
BANK_ACCOUNT_LABEL = "savings"
+# Databases
+NEXUS_DB="test-nexus.sqlite3"
def fail(msg):
print(msg)
@@ -93,17 +95,17 @@ def assertResponse(response):
# -1 Clean databases and start services.
os.chdir("..")
assert 0 == call(["rm", "-f", "sandbox/libeufin-sandbox.sqlite3"])
-assert 0 == call(["rm", "-f", "nexus/libeufin-nexus.sqlite3"])
+assert 0 == call(["rm", "-f", "nexus/{}".format(NEXUS_DB)])
DEVNULL = open(os.devnull, "w")
assert 0 == call(
- ["./gradlew", "nexus:run", "--console=plain", "--args=superuser admin --password x"]
+ ["./gradlew", "nexus:run", "--console=plain", "--args=superuser admin --password x --db-name={}".format(NEXUS_DB)]
)
# Start nexus
checkPorts([5001])
nexus = Popen(
- ["./gradlew", "nexus:run", "--console=plain", "--args=serve"],
+ ["./gradlew", "nexus:run", "--console=plain", "--args=serve --db-name={}".format(NEXUS_DB)],
stdout=PIPE,
stderr=PIPE,
)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt
@@ -11,6 +11,7 @@ import tech.libeufin.util.*
import tech.libeufin.util.ebics_h004.EbicsTypes
import java.security.interfaces.RSAPublicKey
import java.time.Instant
+import java.time.LocalDateTime
import java.time.ZoneId
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
@@ -123,7 +124,7 @@ fun processCamtMessage(
currency = camt53doc.pickString("//*[local-name()='Ntry']//*[local-name()='Amt']/@Ccy")
amount = camt53doc.pickString("//*[local-name()='Ntry']//*[local-name()='Amt']")
status = camt53doc.pickString("//*[local-name()='Ntry']//*[local-name()='Sts']")
- this.bookingDate = bookingDate.millis()
+ this.bookingDate = LocalDateTime.from(bookingDate).millis()
counterpartIban =
camt53doc.pickString("//*[local-name()='${if (this.transactionType == "DBIT") "CdtrAcct" else "DbtrAcct"}']//*[local-name()='IBAN']")
counterpartName =
@@ -441,7 +442,7 @@ fun authenticateRequest(request: ApplicationRequest): NexusUserEntity {
NexusUsersTable.id eq username
}.firstOrNull()
if (user == null) {
- throw NexusError(HttpStatusCode.Unauthorized, "Unknown user")
+ throw NexusError(HttpStatusCode.Unauthorized, "Unknown user '$username'")
}
if (!CryptoUtil.checkpw(password, user.passwordHash)) {
throw NexusError(HttpStatusCode.Forbidden, "Wrong password")
diff --git a/util/src/main/kotlin/time.kt b/util/src/main/kotlin/time.kt
@@ -15,7 +15,8 @@ fun LocalDateTime.toDashedDate(): String {
fun parseDashedDate(date: String): LocalDateTime {
val dtf = DateTimeFormatter.ISO_LOCAL_DATE
- return LocalDateTime.from(LocalDate.parse(date, dtf))
+ val asDate = LocalDate.from(LocalDate.parse(date, dtf))
+ return asDate.atStartOfDay()
}
fun importDateFromMillis(millis: Long): LocalDateTime {
@@ -26,6 +27,6 @@ fun importDateFromMillis(millis: Long): LocalDateTime {
}
fun LocalDateTime.millis(): Long {
- val instant = Instant.from(this)
+ val instant = Instant.from(this.atZone(ZoneId.systemDefault()))
return instant.toEpochMilli()
}
\ No newline at end of file
diff --git a/util/src/test/kotlin/TimeTest.kt b/util/src/test/kotlin/TimeTest.kt
@@ -1,4 +1,5 @@
import org.junit.Test
+import tech.libeufin.util.parseDashedDate
import java.time.*
import java.time.format.DateTimeFormatter
import java.time.temporal.TemporalAccessor