libeufin

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

commit b56753b146c79b11a9f879b53b5f4403708b1c10
parent 9c86e8f57969e6f1f57ff6417ffd0ec110fd2246
Author: MS <ms@taler.net>
Date:   Mon, 25 Sep 2023 16:39:53 +0200

Fixing token handler.

Fixed items:

- token creation time in the database.
- testcase still mentioning the wrong token prefix.

Diffstat:
Mbank/src/main/kotlin/tech/libeufin/bank/BankMessages.kt | 2+-
Mbank/src/main/kotlin/tech/libeufin/bank/CorebankApiHandlers.kt | 9+++++----
Mbank/src/test/kotlin/LibeuFinApiTest.kt | 2+-
3 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/bank/src/main/kotlin/tech/libeufin/bank/BankMessages.kt b/bank/src/main/kotlin/tech/libeufin/bank/BankMessages.kt @@ -392,7 +392,7 @@ data class BankAccountTransactionInfo( val direction: TransactionDirection, val subject: String, val row_id: Long, // is T_ID - val date: Long + val date: TalerProtocolTimestamp ) // Response type for histories, namely GET /transactions diff --git a/bank/src/main/kotlin/tech/libeufin/bank/CorebankApiHandlers.kt b/bank/src/main/kotlin/tech/libeufin/bank/CorebankApiHandlers.kt @@ -59,7 +59,8 @@ fun Routing.accountsMgmtHandlers(db: Database, ctx: BankApplicationContext) { val customerDbRow = customer.dbRowId ?: throw internalServerError( "Could not get customer '${customer.login}' database row ID" ) - val expirationTimestampUs: Long = getNowUs() + tokenDurationUs + val creationTime = getNowUs() + val expirationTimestampUs: Long = creationTime + tokenDurationUs if (expirationTimestampUs < tokenDurationUs) throw badRequest( "Token duration caused arithmetic overflow", // FIXME: need dedicate EC (?) talerErrorCode = TalerErrorCode.TALER_EC_END @@ -67,7 +68,7 @@ fun Routing.accountsMgmtHandlers(db: Database, ctx: BankApplicationContext) { val token = BearerToken( bankCustomer = customerDbRow, content = tokenBytes, - creationTime = expirationTimestampUs, + creationTime = creationTime, expirationTime = expirationTimestampUs, scope = req.scope, isRefreshable = req.refreshable @@ -349,7 +350,7 @@ fun Routing.accountsMgmtHandlers(db: Database, ctx: BankApplicationContext) { subject = it.subject, amount = it.amount.toString(), direction = it.direction, - date = it.transactionDate, + date = TalerProtocolTimestamp.fromMicroseconds(it.transactionDate), row_id = it.dbRowId ?: throw internalServerError( "Transaction timestamped with '${it.transactionDate}' did not have row ID" ) @@ -424,7 +425,7 @@ fun Routing.accountsMgmtHandlers(db: Database, ctx: BankApplicationContext) { amount = "${tx.amount.currency}:${tx.amount.value}.${tx.amount.frac}", creditor_payto_uri = tx.creditorPaytoUri, debtor_payto_uri = tx.debtorPaytoUri, - date = tx.transactionDate, + date = TalerProtocolTimestamp.fromMicroseconds(tx.transactionDate), direction = tx.direction, subject = tx.subject, row_id = txRowId diff --git a/bank/src/test/kotlin/LibeuFinApiTest.kt b/bank/src/test/kotlin/LibeuFinApiTest.kt @@ -173,7 +173,7 @@ class LibeuFinApiTest { ) // Testing the bearer-token:-scheme. client.post("/accounts/foo/token") { - headers.set("Authorization", "Bearer bearer-token:${Base32Crockford.encode(fooTok)}") + headers.set("Authorization", "Bearer secret-token:${Base32Crockford.encode(fooTok)}") contentType(ContentType.Application.Json) setBody("{\"scope\": \"readonly\"}") expectSuccess = true