merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

commit b55506b39509657aba64be1a4e22c5bf32c934f9
parent 4699510294ca53af9924abf34c06671b62ec6f5a
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date:   Thu, 15 Mar 2018 08:02:20 +0100

Double twister instance plus first coverage effort

The twisted tests now use two twister processes: one
to proxy the exchange, the other to proxy the merchant.

Additionally, it is now tested the reaction of /history
lib to a unexpected HTTP response code returned by the
merchant.

Diffstat:
Msrc/backend/taler-merchant-httpd_history.c | 2++
Asrc/lib/test_merchant_api_proxy_exchange.conf | 29+++++++++++++++++++++++++++++
Asrc/lib/test_merchant_api_proxy_merchant.conf | 30++++++++++++++++++++++++++++++
Msrc/lib/test_merchant_api_twisted.c | 84+++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------
Msrc/lib/test_merchant_api_twisted.conf | 31-------------------------------
Msrc/lib/testing_api_cmd_history.c | 14++++++++++++--
Msrc/lib/testing_api_helpers.c | 4++--
7 files changed, 134 insertions(+), 60 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_history.c b/src/backend/taler-merchant-httpd_history.c @@ -132,6 +132,7 @@ MH_handler_history (struct TMH_RequestHandler *rh, enum GNUNET_DB_QueryStatus qs; struct ProcessContractClosure pcc; + LOG_INFO ("Serving /history\n"); response = json_array (); str = MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, @@ -280,6 +281,7 @@ MH_handler_history (struct TMH_RequestHandler *rh, ret = TMH_RESPONSE_reply_json (connection, response, MHD_HTTP_OK); + LOG_INFO ("/history, http code: %d\n", MHD_HTTP_OK); json_decref (response); return ret; } diff --git a/src/lib/test_merchant_api_proxy_exchange.conf b/src/lib/test_merchant_api_proxy_exchange.conf @@ -0,0 +1,29 @@ +# This file is in the public domain. + +# Config to set up the twister between the +# merchant and the exchange. + +[twister] +# HTTP listen port for twister (the merchant +# will transparently use this URL as the "exchange") +HTTP_PORT = 8888 + +# HTTP Destination for twister, so the real exchange +# URL. Note: no trailing '/'! +DESTINATION_BASE_URL = "http://localhost:8081" + +# Control port for TCP +# PORT = 8889 +HOSTNAME = localhost +ACCEPT_FROM = 127.0.0.1; +ACCEPT_FROM6 = ::1; + +# Control port for UNIX +UNIXPATH = /tmp/taler-service-twister-exchange.sock +UNIX_MATCH_UID = NO +UNIX_MATCH_GID = YES + +# Launching of twister by ARM +# BINARY = taler-service-twister +# AUTOSTART = NO +# FORCESTART = NO diff --git a/src/lib/test_merchant_api_proxy_merchant.conf b/src/lib/test_merchant_api_proxy_merchant.conf @@ -0,0 +1,30 @@ +# This file is in the public domain. + +# Config to set up the twister between the +# HTTP client (= the "lib" code) and the +# merchant service. + +[twister] +# HTTP listen port for twister ("lib" code will +# transparently use this URL as the "merchant") +HTTP_PORT = 8889 + +# HTTP Destination for twister, so the real +# merchant URL. Note: no trailing '/'! +DESTINATION_BASE_URL = "http://localhost:8082" + +# Control port for TCP +# PORT = 8889 +HOSTNAME = localhost +ACCEPT_FROM = 127.0.0.1; +ACCEPT_FROM6 = ::1; + +# Control port for UNIX +UNIXPATH = /tmp/taler-service-twister-merchant.sock +UNIX_MATCH_UID = NO +UNIX_MATCH_GID = YES + +# Launching of twister by ARM +# BINARY = taler-service-twister +# AUTOSTART = NO +# FORCESTART = NO diff --git a/src/lib/test_merchant_api_twisted.c b/src/lib/test_merchant_api_twisted.c @@ -46,14 +46,33 @@ #define CONFIG_FILE "test_merchant_api_twisted.conf" /** + * Configuration file for the proxy between merchant and + * exchange. Not used directly here in the code (instead + * used in the merchant config), but kept around for consistency. + */ +#define PROXY_EXCHANGE_CONFIG_FILE \ + "test_merchant_api_proxy_exchange.conf" + +/** + * Configuration file for the proxy between "lib" and merchant. + */ +#define PROXY_MERCHANT_CONFIG_FILE \ + "test_merchant_api_proxy_merchant.conf" + +/** * Exchange base URL. Could also be taken from config. */ #define EXCHANGE_URL "http://localhost:8081/" /** - * (real) Twister URL. Used at startup time to check if it runs. + * Twister URL that proxies the exchange. */ -static char *twister_url; +static char *twister_exchange_url; + +/** + * Twister URL that proxies the merchant. + */ +static char *twister_merchant_url; /** * URL of the fakebank. Obtained from CONFIG_FILE's @@ -77,9 +96,14 @@ static char *exchange_url; static struct GNUNET_OS_Process *merchantd; /** - * Twister process. + * Twister process that proxies the exchange. + */ +static struct GNUNET_OS_Process *twisterexchanged; + +/** + * Twister process that proxies the merchant. */ -static struct GNUNET_OS_Process *twisterd; +static struct GNUNET_OS_Process *twistermerchantd; /** * Account number of the exchange at the bank. @@ -158,6 +182,7 @@ run (void *cls, struct TALER_TESTING_Command commands[] = { + #ifdef TEST_FAILED_DEPENDENCY /** * Move money to the exchange's bank account. */ @@ -269,17 +294,21 @@ run (void *cls, "deposit-simple", "EUR:0.01"), // ignored - - #if 0 - TALER_TESTING_cmd_merchant_track_transfer - ("track-transfer-1", - merchant_url, - is->ctx, - MHD_HTTP_OK, - "check_bank_transfer-1", - "deposit-simple"), #endif - + + TALER_TESTING_cmd_hack_response_code + ("twist-history", + PROXY_MERCHANT_CONFIG_FILE, + MHD_HTTP_GONE), + + TALER_TESTING_cmd_history ("history-0", + twister_merchant_url, + is->ctx, + MHD_HTTP_GONE, + GNUNET_TIME_UNIT_ZERO_ABS, + 1, // nresult + 10, // start + 10), // nrows /** * End the suite. Fixme: better to have a label for this * too, as it shows a "(null)" token on logs. @@ -324,8 +353,12 @@ main (int argc, (CONFIG_FILE))) return 77; - if (NULL == (twister_url = TALER_TESTING_prepare_twister - (CONFIG_FILE))) + if (NULL == (twister_exchange_url = TALER_TESTING_prepare_twister + (PROXY_EXCHANGE_CONFIG_FILE))) + return 77; + + if (NULL == (twister_merchant_url = TALER_TESTING_prepare_twister + (PROXY_MERCHANT_CONFIG_FILE))) return 77; TALER_TESTING_cleanup_files (CONFIG_FILE); @@ -343,21 +376,22 @@ main (int argc, if (NULL == (merchantd = TALER_TESTING_run_merchant (CONFIG_FILE))) - { - purge_process (twisterd); - return 1; // 1 is fine; after all is merchant test cases. - } + // 1 is fine; after all this is merchant test cases. + return 1; - if (NULL == (twisterd = TALER_TESTING_run_twister - (CONFIG_FILE))) + if (NULL == (twisterexchanged = TALER_TESTING_run_twister + (PROXY_EXCHANGE_CONFIG_FILE))) + return 77; + + if (NULL == (twistermerchantd = TALER_TESTING_run_twister + (PROXY_MERCHANT_CONFIG_FILE))) return 77; ret = TALER_TESTING_setup_with_exchange (&run, NULL, CONFIG_FILE); purge_process (merchantd); - purge_process (twisterd); - GNUNET_free (merchant_url); - GNUNET_free (twister_url); + purge_process (twisterexchanged); + purge_process (twistermerchantd); if (GNUNET_OK != ret) return 1; diff --git a/src/lib/test_merchant_api_twisted.conf b/src/lib/test_merchant_api_twisted.conf @@ -1,34 +1,5 @@ # This file is in the public domain. -######################### -# Twister configuration # -######################### - -[twister] -# HTTP listen port for twister -HTTP_PORT = 8888 - -# HTTP Destination for twister. The test-Webserver needs -# to listen on the port used here. Note: no trailing '/'! -DESTINATION_BASE_URL = "http://localhost:8081" - -# Control port for TCP -# PORT = 8889 -HOSTNAME = localhost -ACCEPT_FROM = 127.0.0.1; -ACCEPT_FROM6 = ::1; - -# Control port for UNIX -UNIXPATH = /tmp/taler-service-twister.sock -UNIX_MATCH_UID = NO -UNIX_MATCH_GID = YES - -# Launching of twister by ARM -# BINARY = taler-service-twister -# AUTOSTART = NO -# FORCESTART = NO - -# [PATHS] # Persistant data storage for the testcase TALER_TEST_HOME = test_merchant_api_home/ @@ -127,7 +98,6 @@ TIP_EXCHANGE = http://localhost:8088/ TIP_RESERVE_PRIV_FILENAME = reserve_dkey.priv NAME = Test Tipping Merchant 2 - [merchant-instance-wireformat-tor] TEST_RESPONSE_FILE = ${TALER_CONFIG_HOME}/merchant/wire/test.json @@ -163,7 +133,6 @@ BIC = GENODEF1SRL SALT = 17919252168512238964 ADDRESS = "Garching" - ########################## # Exchange configuration # ########################## diff --git a/src/lib/testing_api_cmd_history.c b/src/lib/testing_api_cmd_history.c @@ -157,8 +157,18 @@ history_cb (void *cls, struct GNUNET_TIME_Absolute entry_timestamp; hs->ho = NULL; - if (hs->http_status != http_status) - TALER_TESTING_FAIL (hs->is); + + /* 410 is a convenience status that is used to + * trigger the "unexpected response code" in the + * lib, that should then result in a 0 status code + * passed here to the callback. */ + if (MHD_HTTP_GONE == hs->http_status) + { + if (0 != http_status) + TALER_TESTING_FAIL (hs->is); + + TALER_TESTING_interpreter_next (hs->is); + } nresult = json_array_size (json); if (hs->nresult != nresult) diff --git a/src/lib/testing_api_helpers.c b/src/lib/testing_api_helpers.c @@ -59,7 +59,7 @@ TALER_TESTING_run_merchant (const char *config_filename) /* give child time to start and bind against the socket */ fprintf (stderr, - "Waiting for `taler-merchant-httpd' to be ready"); + "Waiting for `taler-merchant-httpd' to be ready\n"); iter = 0; do { @@ -74,7 +74,7 @@ TALER_TESTING_run_merchant (const char *config_filename) GNUNET_OS_process_destroy (merchant_proc); MERCHANT_FAIL (); } - fprintf (stderr, "."); + fprintf (stderr, ".\n"); sleep (1); iter++; }