libeufin

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

commit 57073eaed927873b2ba0e50f7c7b2b422258071f
parent f31085043f87376878dda724915c4405c7ce89e9
Author: Sebastian <sebasjm@gmail.com>
Date:   Sun, 24 Sep 2023 16:02:27 -0300

spa captcha url

Diffstat:
Mbank/src/main/kotlin/tech/libeufin/bank/IntegrationApiHandlers.kt | 22++++++++--------------
Mbank/src/main/kotlin/tech/libeufin/bank/Main.kt | 5+++++
Mbank/src/main/kotlin/tech/libeufin/bank/helpers.kt | 14+++-----------
Mbank/src/test/kotlin/Common.kt | 1+
Mcontrib/libeufin-bank.conf | 1+
5 files changed, 18 insertions(+), 25 deletions(-)

diff --git a/bank/src/main/kotlin/tech/libeufin/bank/IntegrationApiHandlers.kt b/bank/src/main/kotlin/tech/libeufin/bank/IntegrationApiHandlers.kt @@ -45,11 +45,11 @@ fun Routing.talerIntegrationHandlers(db: Database, ctx: BankApplicationContext) val walletCustomer = db.customerGetFromRowId(relatedBankAccount.owningCustomerId) if (walletCustomer == null) throw internalServerError("Could not get the username that owns this withdrawal") - val confirmUrl = getWithdrawalConfirmUrl( - baseUrl = call.request.getBaseUrl() ?: throw internalServerError("Could not get bank own base URL."), - wopId = wopid, - username = walletCustomer.login - ) + val confirmUrl = if (ctx.spaCaptchaURL == null) null else + getWithdrawalConfirmUrl( + baseUrl = ctx.spaCaptchaURL, + wopId = wopid + ) call.respond(BankWithdrawalOperationStatus( aborted = op.aborted, selection_done = op.selectionDone, @@ -94,16 +94,10 @@ fun Routing.talerIntegrationHandlers(db: Database, ctx: BankApplicationContext) // Whatever the problem, the bank missed it: respond 500. throw internalServerError("Bank failed at selecting the withdrawal.") // Getting user details that MIGHT be used later. - val confirmUrl: String? = if (!op.confirmationDone) { - val walletBankAccount = db.bankAccountGetFromOwnerId(op.walletBankAccount) - ?: throw internalServerError("Could not get the bank account owning this withdrawal") - val walletCustomer = db.customerGetFromRowId(walletBankAccount.owningCustomerId) - ?: throw internalServerError("Could not get the username owning this withdrawal") + val confirmUrl: String? = if (ctx.spaCaptchaURL !== null && !op.confirmationDone) { getWithdrawalConfirmUrl( - baseUrl = call.request.getBaseUrl() - ?: throw internalServerError("Could not get bank own base URL."), - wopId = wopid, - username = walletCustomer.login + baseUrl = ctx.spaCaptchaURL, + wopId = wopid ) } else diff --git a/bank/src/main/kotlin/tech/libeufin/bank/Main.kt b/bank/src/main/kotlin/tech/libeufin/bank/Main.kt @@ -104,6 +104,10 @@ data class BankApplicationContext( * Max token duration in microseconds. */ val maxAuthTokenDurationUs: Long, + /** + * Max token duration in microseconds. + */ + val spaCaptchaURL: String?, ) /** @@ -372,6 +376,7 @@ fun readBankApplicationContextFromConfig(cfg: TalerConfig): BankApplicationConte suggestedWithdrawalExchange = cfg.lookupValueString("libeufin-bank", "suggested_withdrawal_exchange"), defaultAdminDebtLimit = cfg.requireValueAmount("libeufin-bank", "default_admin_debt_limit", currency), maxAuthTokenDurationUs = cfg.requireValueDuration("libeufin-bank", "max_auth_token_duration"), + spaCaptchaURL = cfg.lookupValueString("libeufin-bank", "spa_captcha_url"), ) } diff --git a/bank/src/main/kotlin/tech/libeufin/bank/helpers.kt b/bank/src/main/kotlin/tech/libeufin/bank/helpers.kt @@ -335,17 +335,9 @@ fun getTalerWithdrawUri(baseUrl: String, woId: String) = url { // Builds a withdrawal confirm URL. fun getWithdrawalConfirmUrl( - baseUrl: String, wopId: String, username: String -) = url { - val baseUrlObj = URL(baseUrl) - protocol = URLProtocol(name = baseUrlObj.protocol, defaultPort = -1) - host = baseUrlObj.host - // Removing potential double slashes: - baseUrlObj.path.split("/").forEach { - this.appendPathSegments(it) - } - // Completing the endpoint: - this.appendPathSegments("accounts/${username}/withdrawals/${wopId}/confirm") + baseUrl: String, wopId: String +): String { + return baseUrl.replace("{woid}", wopId) } diff --git a/bank/src/test/kotlin/Common.kt b/bank/src/test/kotlin/Common.kt @@ -46,5 +46,6 @@ fun getTestContext( registrationBonus = null, suggestedWithdrawalExchange = suggestedExchange, maxAuthTokenDurationUs = 200 * 1000000, + spaCaptchaURL = null, ) } \ No newline at end of file diff --git a/contrib/libeufin-bank.conf b/contrib/libeufin-bank.conf @@ -5,6 +5,7 @@ DEFAULT_ADMIN_DEBT_LIMIT = KUDOS:2000 REGISTRATION_BONUS = KUDOS:100 REGISTRATION_BONUS_ENABLED = yes MAX_AUTH_TOKEN_DURATION = 1d +SPA_CAPTCHA_URL = http://bank.spa/#/operation/{woip} SERVE = tcp PORT = 8080