diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-10-14 21:17:57 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-10-14 21:17:57 +0200 |
commit | bf9641e1512338edd48624f23e6be356cf251ef4 (patch) | |
tree | 1b04e4e50a05c9516927cc5b846ae101d57702c6 /src/lib | |
parent | 45580502df428587e1aa4b79dfc2d07658b82899 (diff) | |
download | merchant-bf9641e1512338edd48624f23e6be356cf251ef4.tar.gz merchant-bf9641e1512338edd48624f23e6be356cf251ef4.tar.bz2 merchant-bf9641e1512338edd48624f23e6be356cf251ef4.zip |
add test for #6545
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/.gitignore | 1 | ||||
-rw-r--r-- | src/lib/Makefile.am | 12 | ||||
-rw-r--r-- | src/lib/merchant_api_common.c | 28 | ||||
-rw-r--r-- | 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 00000000..3319de77 --- /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 8b938706..57e40902 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 031e0f16..a06a6722 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 00000000..821e04a8 --- /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 */ |