libeufin

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

commit de07e380ac52dc162f9844a730b3a8aff61267ae
parent 39889ac1ebff9b654186ec3d3e974b87f66fc1b6
Author: MS <ms@taler.net>
Date:   Thu, 21 Sep 2023 22:03:32 +0200

TWG POST /transfer, handling wrong currency.

Diffstat:
Mbank/src/main/kotlin/tech/libeufin/bank/talerWireGatewayHandlers.kt | 4++++
Mbank/src/test/kotlin/TalerApiTest.kt | 17+++++++++++++++++
2 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/bank/src/main/kotlin/tech/libeufin/bank/talerWireGatewayHandlers.kt b/bank/src/main/kotlin/tech/libeufin/bank/talerWireGatewayHandlers.kt @@ -93,6 +93,10 @@ fun Routing.talerWireGatewayHandlers() { ) } // Legitimate request, go on. + val internalCurrency = db.configGet("internal_currency") + ?: throw internalServerError("Bank did not find own internal currency.") + if (internalCurrency != req.amount.currency) + throw badRequest("Currency mismatch: $internalCurrency vs ${req.amount.currency}") val exchangeBankAccount = db.bankAccountGetFromOwnerId(c.expectRowId()) ?: throw internalServerError("Exchange does not have a bank account") val transferTimestamp = getNowUs() diff --git a/bank/src/test/kotlin/TalerApiTest.kt b/bank/src/test/kotlin/TalerApiTest.kt @@ -101,6 +101,23 @@ class TalerApiTest { """.trimIndent()) } assert(r.status == HttpStatusCode.Conflict) + /* Triggering currency mismatch. This mainly tests + * the TalerAmount "@Contextual" parser. */ + val currencyMismatchResp = client.post("/accounts/foo/taler-wire-gateway/transfer") { + basicAuth("foo", "pw") + contentType(ContentType.Application.Json) + expectSuccess = false + setBody(""" + { + "request_uid": "entropic 3", + "wtid": "entropic 4", + "exchange_base_url": "http://different-exchange.example.com/", + "amount": "EUR:33", + "credit_account": "BAR-IBAN-ABC" + } + """.trimIndent()) + } + assert(currencyMismatchResp.status == HttpStatusCode.BadRequest) } } // Testing the /history/incoming call from the TWG API.