commit 8a5ccfa9b95da1582d7720e6e2862b64bd8040f4
parent 7bfe53c69a5c7a1335f9fcb431f430043bc1c793
Author: MS <ms@taler.net>
Date: Wed, 5 Apr 2023 17:17:45 +0200
CAPTCHA URL with {wopid} placeholder.
Diffstat:
3 files changed, 38 insertions(+), 3 deletions(-)
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -176,6 +176,14 @@ class Config : CliktCommand("Insert one configuration (a.k.a. demobank) into the
System.err.println("Debt numbers can't be negative.")
exitProcess(1)
}
+ /*
+ Warning if the CAPTCHA URL does not include the {wopid} placeholder.
+ Not a reason to fail because the bank may be run WITHOUT providing Taler.
+ */
+ if (!hasWopidPlaceholder(captchaUrlOption))
+ logger.warn("CAPTCHA URL doesn't have the WOPID placeholder." +
+ " Taler withdrawals decrease usability")
+
// The user asks to _set_ values, regardless of overriding or creating.
val config = DemobankConfig(
currency = currencyOption,
@@ -1296,15 +1304,16 @@ val sandboxApp: Application.() -> Unit = {
)
}
val demobank = ensureDemobank(call)
- if (demobank.config.captchaUrl == null) logger.warn("CAPTCHA URL not found")
- val captcha_page = if (arg == null) demobank.config.captchaUrl else demobank.config.captchaUrl?.replace("{wopid}",arg)
+ val captchaPage: String? = demobank.config.captchaUrl?.replace("{wopid}",arg)
+ if (captchaPage == null)
+ throw internalServerError("demobank ${demobank.name} lacks the CAPTCHA URL from the configuration.")
val ret = TalerWithdrawalStatus(
selection_done = maybeWithdrawalOp.selectionDone,
transfer_done = maybeWithdrawalOp.confirmationDone,
amount = maybeWithdrawalOp.amount,
suggested_exchange = demobank.config.suggestedExchangeBaseUrl,
aborted = maybeWithdrawalOp.aborted,
- confirm_transfer_url = captcha_page
+ confirm_transfer_url = captchaPage
)
call.respond(ret)
return@get
diff --git a/sandbox/src/test/kotlin/StringsTest.kt b/sandbox/src/test/kotlin/StringsTest.kt
@@ -1,9 +1,29 @@
import org.junit.Test
+import tech.libeufin.util.hasWopidPlaceholder
import tech.libeufin.util.validateBic
class StringsTest {
@Test
+ fun hasWopidTest() {
+ assert(hasWopidPlaceholder("http://example.com/#/{wopid}"))
+ assert(!hasWopidPlaceholder("http://example.com"))
+ assert(hasWopidPlaceholder("http://example.com/#/{WOPID}"))
+ assert(!hasWopidPlaceholder("{ W O P I D }"))
+ }
+
+ @Test
+ fun replaceWopidPlaceholderTest() {
+ assert(
+ "http://example.com/#/operation/{wopid}".replace("{wopid}", "987")
+ == "http://example.com/#/operation/987"
+ )
+ assert("http://example.com".replace("{wopid}", "not-replaced")
+ == "http://example.com"
+ )
+ }
+
+ @Test
fun bicTest() {
assert(validateBic("GENODEM1GLS"))
assert(validateBic("AUTOATW1XXX"))
diff --git a/util/src/main/kotlin/strings.kt b/util/src/main/kotlin/strings.kt
@@ -189,4 +189,10 @@ fun parseUuid(maybeUuid: String): UUID {
throw badRequest("'$maybeUuid' is an invalid UUID.")
}
return uuid
+}
+
+fun hasWopidPlaceholder(captchaUrl: String): Boolean {
+ if (captchaUrl.contains("{wopid}", ignoreCase = true))
+ return true
+ return false
}
\ No newline at end of file