libeufin

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

commit ee9b262ffeafe5f5af78d5382e5033b386d78f1d
parent e86798ed6bdaa0817dd0057f090488e3fc28f36d
Author: Antoine A <>
Date:   Mon, 30 Oct 2023 08:45:25 +0000

Improve bonus failure hint

Diffstat:
Mbank/conf/test_bonus.conf | 4++--
Mbank/src/main/kotlin/tech/libeufin/bank/Authentication.kt | 1-
Mbank/src/main/kotlin/tech/libeufin/bank/CoreBankApi.kt | 2+-
Mbank/src/test/kotlin/CoreBankApiTest.kt | 24++++++++++++++++++------
4 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/bank/conf/test_bonus.conf b/bank/conf/test_bonus.conf @@ -1,8 +1,8 @@ [libeufin-bank] CURRENCY = KUDOS -DEFAULT_ADMIN_DEBT_LIMIT = KUDOS:10 +DEFAULT_ADMIN_DEBT_LIMIT = KUDOS:10000 REGISTRATION_BONUS_ENABLED = yes -REGISTRATION_BONUS = KUDOS:10 +REGISTRATION_BONUS = KUDOS:100 [libeufin-bankdb-postgres] SQL_DIR = $DATADIR/sql/ diff --git a/bank/src/main/kotlin/tech/libeufin/bank/Authentication.kt b/bank/src/main/kotlin/tech/libeufin/bank/Authentication.kt @@ -54,7 +54,6 @@ fun Route.auth(db: Database, scope: TokenScope, allowAdmin: Boolean = false, req throw unauthorized("Only administrator allowed") } } else { - println("$allowAdmin, $authLogin") val hasRight = authLogin == username || (allowAdmin && authLogin == "admin"); if (!hasRight) { throw unauthorized("Customer $authLogin have no right on $username account") diff --git a/bank/src/main/kotlin/tech/libeufin/bank/CoreBankApi.kt b/bank/src/main/kotlin/tech/libeufin/bank/CoreBankApi.kt @@ -166,7 +166,7 @@ private fun Routing.coreBankAccountsMgmtApi(db: Database, ctx: BankConfig) { when (result) { CustomerCreationResult.BALANCE_INSUFFICIENT -> throw conflict( - "Insufficient funds", + "Insufficient admin funds to grant bonus", TalerErrorCode.TALER_EC_BANK_UNALLOWED_DEBIT ) CustomerCreationResult.CONFLICT_LOGIN -> throw conflict( diff --git a/bank/src/test/kotlin/CoreBankApiTest.kt b/bank/src/test/kotlin/CoreBankApiTest.kt @@ -232,15 +232,27 @@ class CoreBankAccountsMgmtApiTest { } // Check ok - client.post("/accounts") { - basicAuth("admin", "admin-password") - jsonBody(req) - }.assertCreated() - client.get("/accounts/foo") { + repeat(100) { + client.post("/accounts") { + basicAuth("admin", "admin-password") + jsonBody(json(req) { + "username" to "foo$it" + }) + }.assertCreated() + client.get("/accounts/foo$it") { + basicAuth("admin", "admin-password") + }.assertOk().run { + val obj: AccountData = Json.decodeFromString(bodyAsText()) + assertEquals(TalerAmount("KUDOS:100"), obj.balance.amount) + assertEquals(CorebankCreditDebitInfo.credit, obj.balance.credit_debit_indicator) + } + } + client.get("/accounts/admin") { basicAuth("admin", "admin-password") }.assertOk().run { val obj: AccountData = Json.decodeFromString(bodyAsText()) - assertEquals(TalerAmount("KUDOS:10"), obj.balance.amount) + assertEquals(TalerAmount("KUDOS:10000"), obj.balance.amount) + assertEquals(CorebankCreditDebitInfo.debit, obj.balance.credit_debit_indicator) } // Check unsufficient funs