gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] branch master updated: add test for #6545


From: gnunet
Subject: [taler-merchant] branch master updated: add test for #6545
Date: Wed, 14 Oct 2020 21:18:18 +0200

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

grothoff pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new bf9641e  add test for #6545
bf9641e is described below

commit bf9641e1512338edd48624f23e6be356cf251ef4
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Wed Oct 14 21:17:57 2020 +0200

    add test for #6545
---
 src/lib/.gitignore                 |   1 +
 src/lib/Makefile.am                |  12 +++
 src/lib/merchant_api_common.c      |  28 +++----
 src/lib/test_merchant_api_common.c | 163 +++++++++++++++++++++++++++++++++++++
 4 files changed, 188 insertions(+), 16 deletions(-)

diff --git a/src/lib/.gitignore b/src/lib/.gitignore
new file mode 100644
index 0000000..3319de7
--- /dev/null
+++ b/src/lib/.gitignore
@@ -0,0 +1 @@
+test_merchant_api_common
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 8b93870..57e4090 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -70,3 +70,15 @@ if HAVE_LIBGNURL
 libtalermerchant_la_LIBADD += -lgnurl
 endif
 endif
+
+check_PROGRAMS = \
+  test_merchant_api_common
+
+TESTS = \
+  $(check_PROGRAMS)
+
+test_merchant_api_common_SOURCES = \
+  test_merchant_api_common.c
+test_merchant_api_common_LDADD = \
+  $(top_srcdir)/src/lib/libtalermerchant.la \
+  -lgnunetutil
diff --git a/src/lib/merchant_api_common.c b/src/lib/merchant_api_common.c
index 031e0f1..a06a672 100644
--- a/src/lib/merchant_api_common.c
+++ b/src/lib/merchant_api_common.c
@@ -172,6 +172,7 @@ TALER_MERCHANT_parse_pay_uri (const char *pay_uri,
 
   {
     char *order_id;
+    char *mpp;
     char *session_id = strrchr (u.path,
                                 '/');
     struct TALER_ClaimTokenP *claim_token = NULL;
@@ -195,6 +196,13 @@ TALER_MERCHANT_parse_pay_uri (const char *pay_uri,
     }
     *order_id = '\0';
     ++order_id;
+    mpp = strchr (u.path,
+                  '/');
+    if (NULL != mpp)
+    {
+      *mpp = '\0';
+      ++mpp;
+    }
 
     {
       char *ct_str = u.query;
@@ -229,21 +237,10 @@ TALER_MERCHANT_parse_pay_uri (const char *pay_uri,
       }
     }
 
-    {
-      char *mpp;
-
-      mpp = strchr (u.path,
-                    '/');
-      if (NULL != mpp)
-      {
-        *mpp = '\0';
-        ++mpp;
-      }
-      parse_data->merchant_prefix_path
-        = (NULL == mpp)
-          ? NULL
-          : GNUNET_strdup (mpp);
-    }
+    parse_data->merchant_prefix_path
+      = (NULL == mpp)
+        ? NULL
+        : GNUNET_strdup (mpp);
     parse_data->merchant_host = GNUNET_strdup (u.path);
     parse_data->order_id = GNUNET_strdup (order_id);
     parse_data->session_id
@@ -310,7 +307,6 @@ TALER_MERCHANT_parse_refund_uri (
     return GNUNET_SYSERR;
   }
 
-
   {
     char *order_id;
     char *last_seg = strrchr (u.path,
diff --git a/src/lib/test_merchant_api_common.c 
b/src/lib/test_merchant_api_common.c
new file mode 100644
index 0000000..821e04a
--- /dev/null
+++ b/src/lib/test_merchant_api_common.c
@@ -0,0 +1,163 @@
+/*
+  This file is part of TALER
+  (C) 2020 Taler Systems SA
+
+  TALER is free software; you can redistribute it and/or modify it under the
+  terms of the GNU General Public License as published by the Free Software
+  Foundation; either version 3, or (at your option) any later version.
+
+  TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+  A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License along with
+  TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+*/
+
+/**
+ * @file util/test_merchant_api_common.c
+ * @brief Unit test for test_merchant_api_common.c
+ * @author Florian Dold
+ */
+#include "platform.h"
+#include "taler_merchant_service.h"
+
+
+int
+main (int argc,
+      const char *const argv[])
+{
+  (void) argc;
+  (void) argv;
+  struct TALER_MERCHANT_PayUriData pd;
+  struct TALER_MERCHANT_RefundUriData rd;
+
+  GNUNET_log_setup ("test_merchant_api_common",
+                    "WARNING",
+                    NULL);
+  /* test pay parser */
+  GNUNET_assert (GNUNET_SYSERR ==
+                 TALER_MERCHANT_parse_pay_uri (
+                   "http://pay/localhost/my-order";,
+                   &pd));
+  GNUNET_assert (GNUNET_SYSERR ==
+                 TALER_MERCHANT_parse_pay_uri (
+                   "taler://pay/localhost/my-order",
+                   &pd));
+  GNUNET_assert (GNUNET_SYSERR ==
+                 TALER_MERCHANT_parse_pay_uri (
+                   "taler://refund/localhost/my-order/",
+                   &pd));
+  GNUNET_assert (GNUNET_OK ==
+                 TALER_MERCHANT_parse_pay_uri (
+                   "taler://PAY/localhost/my-order/",
+                   &pd));
+  GNUNET_assert (0 == strcmp (pd.merchant_host,
+                              "localhost"));
+  GNUNET_assert (NULL == pd.merchant_prefix_path);
+  GNUNET_assert (0 == strcmp (pd.order_id,
+                              "my-order"));
+  GNUNET_assert (NULL == pd.session_id);
+  GNUNET_assert (NULL == pd.claim_token);
+  GNUNET_assert (NULL == pd.ssid);
+  GNUNET_assert (! pd.use_http);
+  TALER_MERCHANT_parse_pay_uri_free (&pd);
+
+  GNUNET_assert (GNUNET_OK ==
+                 TALER_MERCHANT_parse_pay_uri (
+                   "taler://pay/localhost/my-order/#myssid",
+                   &pd));
+  GNUNET_assert (0 == strcmp (pd.merchant_host,
+                              "localhost"));
+  GNUNET_assert (0 == strcmp (pd.order_id,
+                              "my-order"));
+  GNUNET_assert (NULL == pd.session_id);
+  GNUNET_assert (NULL == pd.claim_token);
+  GNUNET_assert (0 == strcmp (pd.ssid,
+                              "myssid"));
+  GNUNET_assert (! pd.use_http);
+  TALER_MERCHANT_parse_pay_uri_free (&pd);
+
+  GNUNET_assert (GNUNET_OK ==
+                 TALER_MERCHANT_parse_pay_uri (
+                   
"taler+http://pay/localhost/instance/foo/my-order/my-session#myssid";,
+                   &pd));
+  GNUNET_assert (0 == strcmp (pd.merchant_host,
+                              "localhost"));
+  GNUNET_assert (0 == strcmp (pd.merchant_prefix_path,
+                              "instance/foo"));
+  GNUNET_assert (0 == strcmp (pd.order_id,
+                              "my-order"));
+  GNUNET_assert (0 == strcmp (pd.session_id,
+                              "my-session"));
+  GNUNET_assert (NULL == pd.claim_token);
+  GNUNET_assert (0 == strcmp (pd.ssid,
+                              "myssid"));
+  GNUNET_assert (pd.use_http);
+  TALER_MERCHANT_parse_pay_uri_free (&pd);
+
+  GNUNET_assert (GNUNET_OK ==
+                 TALER_MERCHANT_parse_pay_uri (
+                   
"taler+http://pay/localhost/my-order/my-session?c=3QV8F3W34Y1FX6R8P2JZNMQ2JQ#myssid";,
+                   &pd));
+  GNUNET_assert (0 == strcmp (pd.merchant_host,
+                              "localhost"));
+  GNUNET_assert (NULL == pd.merchant_prefix_path);
+  GNUNET_assert (0 == strcmp (pd.order_id,
+                              "my-order"));
+  GNUNET_assert (0 == strcmp (pd.session_id,
+                              "my-session"));
+  GNUNET_assert (NULL != pd.claim_token);
+  GNUNET_assert (0 == strcmp (pd.ssid,
+                              "myssid"));
+  GNUNET_assert (pd.use_http);
+  TALER_MERCHANT_parse_pay_uri_free (&pd);
+
+
+  /* test refund parser */
+  GNUNET_assert (GNUNET_SYSERR ==
+                 TALER_MERCHANT_parse_refund_uri (
+                   "http://refund/localhost/my-order/";,
+                   &rd));
+  GNUNET_assert (GNUNET_SYSERR ==
+                 TALER_MERCHANT_parse_refund_uri (
+                   "taler://refund/localhost/my-order",
+                   &rd));
+  GNUNET_assert (GNUNET_SYSERR ==
+                 TALER_MERCHANT_parse_refund_uri (
+                   "taler://pay/localhost/my-order/",
+                   &rd));
+
+  GNUNET_assert (GNUNET_OK ==
+                 TALER_MERCHANT_parse_refund_uri (
+                   "taler://refund/localhost/my-order/#myssid",
+                   &rd));
+  GNUNET_assert (0 == strcmp (rd.merchant_host,
+                              "localhost"));
+  GNUNET_assert (NULL == pd.merchant_prefix_path);
+  GNUNET_assert (0 == strcmp (rd.order_id,
+                              "my-order"));
+  GNUNET_assert (0 == strcmp (rd.ssid,
+                              "myssid"));
+  GNUNET_assert (! rd.use_http);
+  TALER_MERCHANT_parse_refund_uri_free (&rd);
+
+  GNUNET_assert (GNUNET_OK ==
+                 TALER_MERCHANT_parse_refund_uri (
+                   "taler+http://REFUND/localhost/instance/foo/my-order/";,
+                   &rd));
+  GNUNET_assert (0 == strcmp (rd.merchant_host,
+                              "localhost"));
+  GNUNET_assert (0 == strcmp ("instance/foo",
+                              rd.merchant_prefix_path));
+  GNUNET_assert (0 == strcmp (rd.order_id,
+                              "my-order"));
+  GNUNET_assert (NULL == rd.ssid);
+  GNUNET_assert (rd.use_http);
+  TALER_MERCHANT_parse_refund_uri_free (&rd);
+
+  return 0;
+}
+
+
+/* end of test_merchant_api_common.c */

-- 
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]