gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] branch master updated: CAPTCHA URL with {wopid} placeholder.


From: gnunet
Subject: [libeufin] branch master updated: CAPTCHA URL with {wopid} placeholder.
Date: Wed, 05 Apr 2023 17:18:37 +0200

This is an automated email from the git hooks/post-receive script.

ms pushed a commit to branch master
in repository libeufin.

The following commit(s) were added to refs/heads/master by this push:
     new 8a5ccfa9 CAPTCHA URL with {wopid} placeholder.
8a5ccfa9 is described below

commit 8a5ccfa9b95da1582d7720e6e2862b64bd8040f4
Author: MS <ms@taler.net>
AuthorDate: Wed Apr 5 17:17:45 2023 +0200

    CAPTCHA URL with {wopid} placeholder.
---
 .../src/main/kotlin/tech/libeufin/sandbox/Main.kt    | 15 ++++++++++++---
 sandbox/src/test/kotlin/StringsTest.kt               | 20 ++++++++++++++++++++
 util/src/main/kotlin/strings.kt                      |  6 ++++++
 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
index 4aedf41c..31856c09 100644
--- 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
index a29ed15e..892a419c 100644
--- a/sandbox/src/test/kotlin/StringsTest.kt
+++ b/sandbox/src/test/kotlin/StringsTest.kt
@@ -1,8 +1,28 @@
 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"))
diff --git a/util/src/main/kotlin/strings.kt b/util/src/main/kotlin/strings.kt
index 19e1a927..abfa0184 100644
--- 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

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]