libeufin

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

commit b181be75916448fbe4378e3de13fbc2944279cce
parent c6bb7d4efbe1e915bf62db4a60fc032209085ffb
Author: Antoine A <>
Date:   Fri,  5 Sep 2025 16:14:35 +0200

bank: check base_url and x_taler_bank_payto_hostname are coherent

Diffstat:
Mbank/src/main/kotlin/tech/libeufin/bank/Config.kt | 24++++++++++++++++++++----
Mcommon/src/main/kotlin/TalerConfig.kt | 2+-
2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/bank/src/main/kotlin/tech/libeufin/bank/Config.kt b/bank/src/main/kotlin/tech/libeufin/bank/Config.kt @@ -124,7 +124,23 @@ private fun TalerConfig.loadBankConfig(): BankConfig = section("libeufin-bank"). } } } - + + val (baseUrl, hostname) = run { + val baseUrl = baseURL("base_url").orNull() + val hostname = string("x_taler_bank_payto_hostname").orNull() + if (baseUrl != null && hostname != null) { + if (baseUrl.url.host != hostname) { + throw TalerConfigError.generic("x_taler_bank_payto_hostname must match base_url hostname when both are specified") + } else { + Pair(baseUrl, hostname) + } + } else if (baseUrl != null) { + Pair(baseUrl, baseUrl.url.host) + } else { + Pair(baseUrl, null) + } + } + val method = map("wire_type", "payment target type", mapOf( "iban" to WireMethod.IBAN, "x-taler-bank" to WireMethod.X_TALER_BANK, @@ -132,11 +148,11 @@ private fun TalerConfig.loadBankConfig(): BankConfig = section("libeufin-bank"). val payto = when (method) { WireMethod.IBAN -> BankPaytoCtx( bic = string("iban_payto_bic").orNull(logger, " will fail in a future update"), - hostname = string("x_taler_bank_payto_hostname").orNull() + hostname = hostname ) WireMethod.X_TALER_BANK -> BankPaytoCtx( bic = string("iban_payto_bic").orNull(), - hostname = string("x_taler_bank_payto_hostname").orNull(logger, " will fail in a future update") + hostname = hostname ?: string("x_taler_bank_payto_hostname").orNull(logger, " will fail in a future update") ) } @@ -163,7 +179,7 @@ private fun TalerConfig.loadBankConfig(): BankConfig = section("libeufin-bank"). maxAmount = amount("max_wire_transfer_amount", regionalCurrency).default(MAX), suggestedWithdrawalExchange = string("suggested_withdrawal_exchange").orNull(), spaPath = path("spa").orNull(), - baseUrl = baseURL("base_url").orNull(), + baseUrl = baseUrl, fiatCurrency = fiatCurrency, fiatCurrencySpec = fiatCurrencySpec, tanChannels = tanChannels, diff --git a/common/src/main/kotlin/TalerConfig.kt b/common/src/main/kotlin/TalerConfig.kt @@ -45,7 +45,7 @@ class TalerConfigError private constructor (m: String, cause: Throwable? = null) TalerConfigError("Expected $type option '$option' in section '$section': $err") /** Generic error not linked to a specific option value */ - internal fun generic(msg: String, cause: Throwable? = null): TalerConfigError = + fun generic(msg: String, cause: Throwable? = null): TalerConfigError = TalerConfigError(msg, cause) } }