[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libeufin] 02/02: spa captcha url
From: |
gnunet |
Subject: |
[libeufin] 02/02: spa captcha url |
Date: |
Sun, 24 Sep 2023 21:02:38 +0200 |
This is an automated email from the git hooks/post-receive script.
sebasjm pushed a commit to branch master
in repository libeufin.
commit 57073eaed927873b2ba0e50f7c7b2b422258071f
Author: Sebastian <sebasjm@gmail.com>
AuthorDate: Sun Sep 24 16:02:27 2023 -0300
spa captcha url
---
.../tech/libeufin/bank/IntegrationApiHandlers.kt | 22 ++++++++--------------
bank/src/main/kotlin/tech/libeufin/bank/Main.kt | 5 +++++
bank/src/main/kotlin/tech/libeufin/bank/helpers.kt | 14 +++-----------
bank/src/test/kotlin/Common.kt | 1 +
contrib/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
index 502d8746..51db01f2 100644
--- 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
index 025ff5e8..8d4c4a2f 100644
--- 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
index 9969f32c..04d334c3 100644
--- 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
index 01a36985..ad65c14a 100644
--- 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
index 04be761f..3d84c20e 100644
--- 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
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.