diff options
Diffstat (limited to 'src/testing/testing_api_helpers_bank.c')
-rw-r--r-- | src/testing/testing_api_helpers_bank.c | 187 |
1 files changed, 91 insertions, 96 deletions
diff --git a/src/testing/testing_api_helpers_bank.c b/src/testing/testing_api_helpers_bank.c index e8476d30..ff5caa11 100644 --- a/src/testing/testing_api_helpers_bank.c +++ b/src/testing/testing_api_helpers_bank.c @@ -104,38 +104,37 @@ TALER_TESTING_has_in_name (const char *prog, * Start the (nexus) bank process. Assume the port * is available and the database is clean. Use the "prepare * bank" function to do such tasks. This function is also - * responsible to create the exchange EBICS subscriber at - * the nexus. + * responsible to create the exchange user at Nexus. * - * @param config_filename configuration filename. Used to - * @return the process, or NULL if the process could not - * be started. + * @return the pair of both service handles. In case of + * errors, each element of the pair will be set to NULL. */ -struct GNUNET_OS_Process * -TALER_TESTING_run_nexus (const struct TALER_TESTING_BankConfiguration *bc) +struct TALER_TESTING_LibeufinServices +TALER_TESTING_run_libeufin (const struct TALER_TESTING_BankConfiguration *bc) { - struct GNUNET_OS_Process *bank_proc; + struct GNUNET_OS_Process *nexus_proc; + struct GNUNET_OS_Process *sandbox_proc; + struct TALER_TESTING_LibeufinServices ret = { 0 }; unsigned int iter; char *curl_check_cmd; - char *curl_cmd; - char *post_body; - char *register_url; - bank_proc = GNUNET_OS_start_process - (GNUNET_NO, - GNUNET_OS_INHERIT_STD_NONE, - NULL, NULL, NULL, - "nexus", - "nexus", - NULL); - if (NULL == bank_proc) + nexus_proc = GNUNET_OS_start_process + (GNUNET_NO, + GNUNET_OS_INHERIT_STD_NONE, + NULL, NULL, NULL, + "libeufin-nexus", + "libeufin-nexus", + "serve", + "--db-name", "/tmp/nexus-exchange-test.sqlite3", + NULL); + if (NULL == nexus_proc) { - BANK_FAIL (); + GNUNET_break (0); + return ret; } GNUNET_asprintf (&curl_check_cmd, "curl -s %s", bc->exchange_auth.wire_gateway_url); - /* give child time to start and bind against the socket */ fprintf (stderr, "Waiting for `nexus' to be ready (via %s)\n", curl_check_cmd); @@ -147,12 +146,13 @@ TALER_TESTING_run_nexus (const struct TALER_TESTING_BankConfiguration *bc) fprintf ( stderr, "Failed to launch `nexus'\n"); - GNUNET_OS_process_kill (bank_proc, + GNUNET_OS_process_kill (nexus_proc, SIGTERM); - GNUNET_OS_process_wait (bank_proc); - GNUNET_OS_process_destroy (bank_proc); + GNUNET_OS_process_wait (nexus_proc); + GNUNET_OS_process_destroy (nexus_proc); GNUNET_free (curl_check_cmd); - BANK_FAIL (); + GNUNET_break (0); + return ret; } fprintf (stderr, "."); sleep (1); @@ -160,40 +160,69 @@ TALER_TESTING_run_nexus (const struct TALER_TESTING_BankConfiguration *bc) } while (0 != system (curl_check_cmd)); - GNUNET_asprintf (&post_body, - "{ \ - \"ebicsURL\": \"http://mock\", \ - \"userID\": \"mock\", \ - \"partnerID\": \"mock\", \ - \"hostID\": \"mock\", \ - \"password\": \"%s\"}", - bc->exchange_auth.details.basic.password); - GNUNET_asprintf (®ister_url, - "http://localhost:5001/ebics/%s/subscribers", - bc->exchange_auth.details.basic.username); - GNUNET_asprintf (&curl_cmd, - "curl -d'%s' -H'Content-Type: application/json' %s", - post_body, - register_url); - - if (0 != system (curl_cmd)) + // start sandbox. + GNUNET_free (curl_check_cmd); + fprintf (stderr, "\n"); + + sandbox_proc = GNUNET_OS_start_process + (GNUNET_NO, + GNUNET_OS_INHERIT_STD_NONE, + NULL, NULL, NULL, + "libeufin-sandbox", + "libeufin-sandbox", + "serve", + "--db-name", "/tmp/sandbox-exchange-test.sqlite3", + NULL); + if (NULL == sandbox_proc) { - GNUNET_free (curl_check_cmd); - GNUNET_free (curl_cmd); - GNUNET_free (post_body); - GNUNET_free (register_url); - BANK_FAIL (); // includes logging and return (!) + GNUNET_break (0); + return ret; } - GNUNET_free (curl_check_cmd); - GNUNET_free (curl_cmd); - GNUNET_free (post_body); - GNUNET_free (register_url); + /* give child time to start and bind against the socket */ + fprintf (stderr, + "Waiting for `sandbox' to be ready.\n"); + iter = 0; + do + { + if (10 == iter) + { + fprintf ( + stderr, + "Failed to launch `sandbox'\n"); + GNUNET_OS_process_kill (sandbox_proc, + SIGTERM); + GNUNET_OS_process_wait (sandbox_proc); + GNUNET_OS_process_destroy (sandbox_proc); + GNUNET_break (0); + return ret; + } + fprintf (stderr, "."); + sleep (1); + iter++; + } + while (0 != system ("curl -s http://localhost:5000/")); fprintf (stderr, "\n"); - return bank_proc; + // Creates nexus user + bank loopback connection + Taler facade. + if (0 != system ("taler-nexus-prepare")) + { + GNUNET_OS_process_kill (nexus_proc, SIGTERM); + GNUNET_OS_process_wait (nexus_proc); + GNUNET_OS_process_destroy (nexus_proc); + GNUNET_OS_process_kill (sandbox_proc, SIGTERM); + GNUNET_OS_process_wait (sandbox_proc); + GNUNET_OS_process_destroy (sandbox_proc); + TALER_LOG_ERROR ("Could not prepare nexus\n"); + GNUNET_break (0); + return ret; + } + ret.nexus = nexus_proc; + ret.sandbox = sandbox_proc; + return ret; } + /** * Start the (Python) bank process. Assume the port * is available and the database is clean. Use the "prepare @@ -310,6 +339,7 @@ TALER_TESTING_run_bank (const char *config_filename, } + /** * Prepare the Nexus execution. Check if the port is available * and delete old database. @@ -329,9 +359,6 @@ TALER_TESTING_prepare_nexus (const char *config_filename, { struct GNUNET_CONFIGURATION_Handle *cfg; unsigned long long port; - struct GNUNET_OS_Process *dbreset_proc; - enum GNUNET_OS_ProcessStatusType type; - unsigned long code; char *database = NULL; // silence compiler char *exchange_payto_uri; @@ -389,15 +416,8 @@ TALER_TESTING_prepare_nexus (const char *config_filename, /* DB preparation */ if (GNUNET_YES == reset_db) { - if (NULL == - (dbreset_proc = GNUNET_OS_start_process ( - GNUNET_NO, - GNUNET_OS_INHERIT_STD_NONE, - NULL, NULL, NULL, - "rm", - "rm", - "-f", - "libeufin-nexus.sqlite3", NULL))) + if (0 != system ( + "rm -f /tmp/nexus-exchange-test.sqlite3 && rm -f /tmp/sandbox-exchange-test.sqlite3")) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to invoke db-removal command.\n"); @@ -405,36 +425,8 @@ TALER_TESTING_prepare_nexus (const char *config_filename, GNUNET_CONFIGURATION_destroy (cfg); return GNUNET_SYSERR; } - if (GNUNET_SYSERR == - GNUNET_OS_process_wait_status (dbreset_proc, - &type, - &code)) - { - GNUNET_OS_process_destroy (dbreset_proc); - GNUNET_break (0); - GNUNET_CONFIGURATION_destroy (cfg); - return GNUNET_SYSERR; - } - if ( (type == GNUNET_OS_PROCESS_EXITED) && - (0 != code) ) - { - fprintf (stderr, - "db-removal command was unsuccessful\n"); - GNUNET_break (0); - GNUNET_CONFIGURATION_destroy (cfg); - return GNUNET_SYSERR; - } - if ( (type != GNUNET_OS_PROCESS_EXITED) || - (0 != code) ) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Unexpected error running `rm libeufin-nexus.sqlite3'!\n"); - GNUNET_break (0); - GNUNET_CONFIGURATION_destroy (cfg); - return GNUNET_SYSERR; - } - GNUNET_OS_process_destroy (dbreset_proc); } + if (GNUNET_OK != TALER_BANK_auth_parse_cfg (cfg, config_section, @@ -446,8 +438,10 @@ TALER_TESTING_prepare_nexus (const char *config_filename, } GNUNET_CONFIGURATION_destroy (cfg); bc->exchange_payto = exchange_payto_uri; - bc->user42_payto = "payto://x-taler-bank/localhost/42"; - bc->user43_payto = "payto://x-taler-bank/localhost/43"; + bc->user42_payto = + "payto://iban/BIC/FR7630006000011234567890189?receiver-name=User42"; + bc->user43_payto = + "payto://iban/BIC/GB33BUKB20201555555555?receiver-name=User43"; GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Relying on nexus %s on port %u\n", bc->exchange_auth.wire_gateway_url, @@ -461,6 +455,7 @@ TALER_TESTING_prepare_nexus (const char *config_filename, return GNUNET_OK; } + /** * Prepare the bank execution. Check if the port is available * and reset database. @@ -720,7 +715,7 @@ TALER_TESTING_prepare_fakebank (const char *config_filename, bc->exchange_payto); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "user42_payto: %s\n", bc->user42_payto); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "user42_payto: %s\n", + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "user43_payto: %s\n", bc->user43_payto); return GNUNET_OK; } |