libeufin

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

commit 026f81a2a78095de57241fa0a0a178c290449b29
parent 38df40387fe8a3f2925dc84165fe07ade1d8726f
Author: Florian Dold <florian@dold.me>
Date:   Sun, 24 Sep 2023 21:40:41 +0200

iban normalization in tests

Diffstat:
Mbank/src/main/kotlin/tech/libeufin/bank/CorebankApiHandlers.kt | 20+++++++++++---------
Mbank/src/main/kotlin/tech/libeufin/bank/IntegrationApiHandlers.kt | 4+++-
Mbank/src/test/kotlin/LibeuFinApiTest.kt | 29++++++++++++++++-------------
Mbank/src/test/kotlin/TalerApiTest.kt | 8++++----
4 files changed, 34 insertions(+), 27 deletions(-)

diff --git a/bank/src/main/kotlin/tech/libeufin/bank/CorebankApiHandlers.kt b/bank/src/main/kotlin/tech/libeufin/bank/CorebankApiHandlers.kt @@ -106,16 +106,22 @@ fun Routing.accountsMgmtHandlers(db: Database, ctx: BankApplicationContext) { if (this == null) return@run null db.bankAccountGetFromOwnerId(this.expectRowId()) } + val internalPayto: String = if (req.internal_payto_uri != null) { + stripIbanPayto(req.internal_payto_uri) + } else { + stripIbanPayto(genIbanPaytoUri()) + } if (maybeCustomerExists != null && maybeHasBankAccount != null) { logger.debug("Registering username was found: ${maybeCustomerExists.login}") // Checking _all_ the details are the same. val isIdentic = maybeCustomerExists.name == req.name && maybeCustomerExists.email == req.challenge_contact_data?.email && maybeCustomerExists.phone == req.challenge_contact_data?.phone && - maybeCustomerExists.cashoutPayto == - req.cashout_payto_uri && CryptoUtil.checkpw( - req.password, maybeCustomerExists.passwordHash - ) && maybeHasBankAccount.isPublic == req.is_public && maybeHasBankAccount.isTalerExchange == req.is_taler_exchange && maybeHasBankAccount.internalPaytoUri == req.internal_payto_uri + maybeCustomerExists.cashoutPayto == req.cashout_payto_uri && + CryptoUtil.checkpw(req.password, maybeCustomerExists.passwordHash) + && maybeHasBankAccount.isPublic == req.is_public && + maybeHasBankAccount.isTalerExchange == req.is_taler_exchange && + maybeHasBankAccount.internalPaytoUri == internalPayto if (isIdentic) { call.respond(HttpStatusCode.Created) return@post @@ -139,11 +145,6 @@ fun Routing.accountsMgmtHandlers(db: Database, ctx: BankApplicationContext) { val newCustomerRowId = db.customerCreate(newCustomer) ?: throw internalServerError("New customer INSERT failed despite the previous checks") // Crashing here won't break data consistency between customers // and bank accounts, because of the idempotency. Client will // just have to retry. val maxDebt = ctx.defaultCustomerDebtLimit - val internalPayto: String = if (req.internal_payto_uri != null) { - stripIbanPayto(req.internal_payto_uri) - } else { - stripIbanPayto(genIbanPaytoUri()) - } val newBankAccount = BankAccount( hasDebt = false, internalPaytoUri = internalPayto, @@ -368,6 +369,7 @@ fun Routing.accountsMgmtHandlers(db: Database, ctx: BankApplicationContext) { val subject = payto.message ?: throw badRequest("Wire transfer lacks subject") val debtorId = c.dbRowId ?: throw internalServerError("Debtor database ID not found") // This performs already a SELECT on the bank account, // like the wire transfer will do as well later! + logger.info("creditor payto: $paytoWithoutParams") val creditorCustomerData = db.bankAccountGetFromInternalPayto(paytoWithoutParams) ?: throw notFound( "Creditor account not found", TalerErrorCode.TALER_EC_END // FIXME: define this EC. ) diff --git a/bank/src/main/kotlin/tech/libeufin/bank/IntegrationApiHandlers.kt b/bank/src/main/kotlin/tech/libeufin/bank/IntegrationApiHandlers.kt @@ -33,7 +33,9 @@ fun Routing.talerIntegrationHandlers(db: Database, ctx: BankApplicationContext) val internalCurrency: String = ctx.currency call.respond(TalerIntegrationConfigResponse(currency = internalCurrency)) return@get - } // Note: wopid acts as an authentication token. + } + + // Note: wopid acts as an authentication token. get("/taler-integration/withdrawal-operation/{wopid}") { val wopid = call.expectUriComponent("wopid") val op = getWithdrawal(db, wopid) // throws 404 if not found. diff --git a/bank/src/test/kotlin/LibeuFinApiTest.kt b/bank/src/test/kotlin/LibeuFinApiTest.kt @@ -34,7 +34,7 @@ class LibeuFinApiTest { private fun genBankAccount(rowId: Long) = BankAccount( hasDebt = false, - internalPaytoUri = "payto://iban/SANDBOXX/${rowId}-IBAN", + internalPaytoUri = "payto://iban/ac${rowId}", maxDebt = TalerAmount(100, 0, "KUDOS"), owningCustomerId = rowId ) @@ -96,10 +96,12 @@ class LibeuFinApiTest { val db = initDb() val ctx = getTestContext() // foo account - val fooId = db.customerCreate(customerFoo); assert(fooId != null) + val fooId = db.customerCreate(customerFoo); + assert(fooId != null) assert(db.bankAccountCreate(genBankAccount(fooId!!)) != null) // bar account - val barId = db.customerCreate(customerBar); assert(barId != null) + val barId = db.customerCreate(customerBar); + assert(barId != null) assert(db.bankAccountCreate(genBankAccount(barId!!)) != null) // accounts exist, now create one transaction. testApplication { @@ -113,7 +115,7 @@ class LibeuFinApiTest { // expectSuccess = true setBody( """{ - "payto_uri": "payto://iban/SANDBOXX/${barId}-IBAN?message=payout", + "payto_uri": "payto://iban/AC${barId}?message=payout", "amount": "KUDOS:3.3" } """.trimIndent() @@ -201,7 +203,7 @@ class LibeuFinApiTest { db.bankAccountCreate( BankAccount( hasDebt = false, - internalPaytoUri = "payto://iban/SANDBOXX/FOO-IBAN", + internalPaytoUri = "payto://iban/DE1234", maxDebt = TalerAmount(100, 0, "KUDOS"), owningCustomerId = customerRowId!! ) @@ -298,7 +300,6 @@ class LibeuFinApiTest { testApplication { val db = initDb() val ctx = getTestContext() - val ibanPayto = genIbanPaytoUri() application { corebankWebApp(db, ctx) } @@ -359,13 +360,15 @@ class LibeuFinApiTest { } assert(resp.status == HttpStatusCode.Unauthorized) // Creating the administrator. - assert(db.customerCreate( - Customer( - "admin", - CryptoUtil.hashpw("pass"), - "CFO" - ) - ) != null) + assert( + db.customerCreate( + Customer( + "admin", + CryptoUtil.hashpw("pass"), + "CFO" + ) + ) != null + ) // customer exists, this makes only the bank account: assert(maybeCreateAdminAccount(db, ctx)) resp = client.post("/accounts") { diff --git a/bank/src/test/kotlin/TalerApiTest.kt b/bank/src/test/kotlin/TalerApiTest.kt @@ -189,11 +189,11 @@ class TalerApiTest { } } } - // Selecting withdrawal details from the Integrtion API endpoint. + // Selecting withdrawal details from the Integration API endpoint. @Test fun intSelect() { val db = initDb() - val ctx = getTestContext(suggestedExchange = "payto://suggested-exchange") + val ctx = getTestContext(suggestedExchange = "payto://iban/ABC123") val uuid = UUID.randomUUID() assert(db.customerCreate(customerFoo) != null) assert(db.bankAccountCreate(bankAccountFoo) != null) @@ -212,7 +212,7 @@ class TalerApiTest { contentType(ContentType.Application.Json) setBody(""" {"reserve_pub": "RESERVE-FOO", - "selected_exchange": "payto://selected/foo/exchange" } + "selected_exchange": "payto://iban/ABC123" } """.trimIndent()) } println(r.bodyAsText()) @@ -225,7 +225,7 @@ class TalerApiTest { val uuid = UUID.randomUUID() assert(db.customerCreate(customerFoo) != null) assert(db.bankAccountCreate(bankAccountFoo) != null) - val ctx = getTestContext(suggestedExchange = "payto://suggested-exchange") + val ctx = getTestContext(suggestedExchange = "payto://iban/ABC123") // insert new. assert(db.talerWithdrawalCreate( opUUID = uuid,