LCOV - code coverage report
Current view: top level - testing - testing_api_helpers_bank.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 102 292 34.9 %
Date: 2022-08-25 06:15:09 Functions: 5 8 62.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   Copyright (C) 2018-2021 Taler Systems SA
       4             : 
       5             :   TALER is free software; you can redistribute it and/or modify
       6             :   it under the terms of the GNU General Public License as
       7             :   published by the Free Software Foundation; either version 3, or
       8             :   (at your option) any later version.
       9             : 
      10             :   TALER is distributed in the hope that it will be useful, but
      11             :   WITHOUT ANY WARRANTY; without even the implied warranty of
      12             :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13             :   GNU General Public License for more details.
      14             : 
      15             :   You should have received a copy of the GNU General Public
      16             :   License along with TALER; see the file COPYING.  If not, see
      17             :   <http://www.gnu.org/licenses/>
      18             : */
      19             : /**
      20             :  * @file testing/testing_api_helpers_bank.c
      21             :  * @brief convenience functions for bank tests.
      22             :  * @author Marcello Stanisci
      23             :  * @author Christian Grothoff
      24             :  */
      25             : #include "platform.h"
      26             : #include <gnunet/gnunet_util_lib.h>
      27             : #include "taler_testing_lib.h"
      28             : #include "taler_fakebank_lib.h"
      29             : 
      30             : #define BANK_FAIL() \
      31             :   do {GNUNET_break (0); return NULL; } while (0)
      32             : 
      33             : 
      34             : struct TALER_FAKEBANK_Handle *
      35           2 : TALER_TESTING_run_fakebank (const char *bank_url,
      36             :                             const char *currency)
      37             : {
      38             :   const char *port;
      39             :   long pnum;
      40             :   struct TALER_FAKEBANK_Handle *fakebankd;
      41             : 
      42           2 :   port = strrchr (bank_url,
      43             :                   (unsigned char) ':');
      44           2 :   if (NULL == port)
      45           0 :     pnum = 80;
      46             :   else
      47           2 :     pnum = strtol (port + 1, NULL, 10);
      48           2 :   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
      49             :               "Starting Fakebank on port %u (%s)\n",
      50             :               (unsigned int) pnum,
      51             :               bank_url);
      52           2 :   fakebankd = TALER_FAKEBANK_start ((uint16_t) pnum,
      53             :                                     currency);
      54           2 :   if (NULL == fakebankd)
      55             :   {
      56           0 :     GNUNET_break (0);
      57           0 :     return NULL;
      58             :   }
      59           2 :   return fakebankd;
      60             : }
      61             : 
      62             : 
      63             : int
      64           5 : TALER_TESTING_has_in_name (const char *prog,
      65             :                            const char *marker)
      66             : {
      67             :   size_t name_pos;
      68             :   size_t pos;
      69             : 
      70           5 :   if (! prog || ! marker)
      71           0 :     return GNUNET_NO;
      72             : 
      73           5 :   pos = 0;
      74           5 :   name_pos = 0;
      75         399 :   while (prog[pos])
      76             :   {
      77         394 :     if ('/' == prog[pos])
      78          40 :       name_pos = pos + 1;
      79         394 :     pos++;
      80             :   }
      81           5 :   if (name_pos == pos)
      82           0 :     return GNUNET_YES;
      83           5 :   return (NULL != strstr (prog + name_pos, marker));
      84             : }
      85             : 
      86             : 
      87             : struct TALER_TESTING_LibeufinServices
      88           1 : TALER_TESTING_run_libeufin (const struct TALER_TESTING_BankConfiguration *bc)
      89             : {
      90             :   struct GNUNET_OS_Process *nexus_proc;
      91             :   struct GNUNET_OS_Process *sandbox_proc;
      92           1 :   struct TALER_TESTING_LibeufinServices ret = { 0 };
      93             :   unsigned int iter;
      94             :   char *curl_check_cmd;
      95           1 :   const char *db_conn = "jdbc:sqlite:/tmp/libeufin-exchange-test.sqlite3";
      96             : 
      97           1 :   setenv (
      98             :     "LIBEUFIN_NEXUS_DB_CONNECTION",
      99             :     db_conn,
     100             :     1); // not overwriting any potentially existing DB.
     101             : 
     102           1 :   nexus_proc = GNUNET_OS_start_process (
     103             :     GNUNET_OS_INHERIT_STD_ERR,
     104             :     NULL, NULL, NULL,
     105             :     "libeufin-nexus",
     106             :     "libeufin-nexus",
     107             :     "serve",
     108             :     NULL);
     109           1 :   if (NULL == nexus_proc)
     110             :   {
     111           0 :     GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
     112             :                               "exec",
     113             :                               "libeufin-nexus");
     114           0 :     return ret;
     115             :   }
     116           1 :   GNUNET_asprintf (&curl_check_cmd,
     117             :                    "curl -s %s",
     118             :                    bc->exchange_auth.wire_gateway_url);
     119             :   /* give child time to start and bind against the socket */
     120           1 :   fprintf (stderr,
     121             :            "Waiting for `nexus' to be ready (via %s)\n", curl_check_cmd);
     122           1 :   iter = 0;
     123             :   do
     124             :   {
     125           3 :     if (10 == iter)
     126             :     {
     127           0 :       fprintf (
     128             :         stderr,
     129             :         "Failed to launch `nexus'\n");
     130           0 :       GNUNET_OS_process_kill (nexus_proc,
     131             :                               SIGTERM);
     132           0 :       GNUNET_OS_process_wait (nexus_proc);
     133           0 :       GNUNET_OS_process_destroy (nexus_proc);
     134           0 :       GNUNET_free (curl_check_cmd);
     135           0 :       GNUNET_break (0);
     136           0 :       return ret;
     137             :     }
     138           3 :     fprintf (stderr, ".");
     139           3 :     sleep (1);
     140           3 :     iter++;
     141             :   }
     142           3 :   while (0 != system (curl_check_cmd));
     143             : 
     144             :   // start sandbox.
     145           1 :   GNUNET_free (curl_check_cmd);
     146           1 :   fprintf (stderr, "\n");
     147           1 :   setenv (
     148             :     "LIBEUFIN_SANDBOX_DB_CONNECTION",
     149             :     db_conn,
     150             :     1); // not overwriting existing any potentially existing DB.
     151           1 :   setenv (
     152             :     "LIBEUFIN_SANDBOX_ADMIN_PASSWORD",
     153             :     "secret",
     154             :     1);
     155           1 :   if (0 != system ("libeufin-sandbox config --currency=KUDOS default"))
     156             :   {
     157           0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     158             :                 "Could not create the default demobank.\n");
     159           0 :     return ret;
     160             :   }
     161           1 :   sandbox_proc = GNUNET_OS_start_process (
     162             :     GNUNET_OS_INHERIT_STD_ERR,
     163             :     NULL, NULL, NULL,
     164             :     "libeufin-sandbox",
     165             :     "libeufin-sandbox",
     166             :     "serve",
     167             :     NULL);
     168           1 :   if (NULL == sandbox_proc)
     169             :   {
     170           0 :     GNUNET_break (0);
     171           0 :     return ret;
     172             :   }
     173             : 
     174             :   /* give child time to start and bind against the socket */
     175           1 :   fprintf (stderr,
     176             :            "Waiting for `sandbox' to be ready.\n");
     177           1 :   iter = 0;
     178             :   do
     179             :   {
     180           2 :     if (10 == iter)
     181             :     {
     182           0 :       fprintf (
     183             :         stderr,
     184             :         "Failed to launch `sandbox'\n");
     185           0 :       GNUNET_OS_process_kill (sandbox_proc,
     186             :                               SIGTERM);
     187           0 :       GNUNET_OS_process_wait (sandbox_proc);
     188           0 :       GNUNET_OS_process_destroy (sandbox_proc);
     189           0 :       GNUNET_break (0);
     190           0 :       return ret;
     191             :     }
     192           2 :     fprintf (stderr, ".");
     193           2 :     sleep (1);
     194           2 :     iter++;
     195             :   }
     196           2 :   while (0 != system ("curl -s http://localhost:5000/"));
     197           1 :   fprintf (stderr, "\n");
     198             : 
     199             :   // Creates nexus user + bank loopback connection + Taler facade.
     200           1 :   if (0 != system ("taler-nexus-prepare"))
     201             :   {
     202           0 :     GNUNET_OS_process_kill (nexus_proc, SIGTERM);
     203           0 :     GNUNET_OS_process_wait (nexus_proc);
     204           0 :     GNUNET_OS_process_destroy (nexus_proc);
     205           0 :     GNUNET_OS_process_kill (sandbox_proc, SIGTERM);
     206           0 :     GNUNET_OS_process_wait (sandbox_proc);
     207           0 :     GNUNET_OS_process_destroy (sandbox_proc);
     208           0 :     TALER_LOG_ERROR ("Could not prepare nexus\n");
     209           0 :     GNUNET_break (0);
     210           0 :     return ret;
     211             :   }
     212           1 :   ret.nexus = nexus_proc;
     213           1 :   ret.sandbox = sandbox_proc;
     214           1 :   return ret;
     215             : }
     216             : 
     217             : 
     218             : struct GNUNET_OS_Process *
     219           0 : TALER_TESTING_run_bank (const char *config_filename,
     220             :                         const char *bank_url)
     221             : {
     222             :   struct GNUNET_OS_Process *bank_proc;
     223             :   unsigned int iter;
     224             :   char *wget_cmd;
     225             :   char *database;
     226             :   struct GNUNET_CONFIGURATION_Handle *cfg;
     227             : 
     228           0 :   cfg = GNUNET_CONFIGURATION_create ();
     229           0 :   if (GNUNET_OK !=
     230           0 :       GNUNET_CONFIGURATION_load (cfg,
     231             :                                  config_filename))
     232             :   {
     233           0 :     GNUNET_break (0);
     234           0 :     GNUNET_CONFIGURATION_destroy (cfg);
     235           0 :     exit (77);
     236             :   }
     237             : 
     238           0 :   if (GNUNET_OK !=
     239           0 :       GNUNET_CONFIGURATION_get_value_string (cfg,
     240             :                                              "bank",
     241             :                                              "database",
     242             :                                              &database))
     243             :   {
     244           0 :     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
     245             :                                "bank",
     246             :                                "database");
     247           0 :     GNUNET_break (0);
     248           0 :     GNUNET_CONFIGURATION_destroy (cfg);
     249           0 :     exit (77);
     250             :   }
     251           0 :   GNUNET_CONFIGURATION_destroy (cfg);
     252           0 :   bank_proc = GNUNET_OS_start_process (
     253             :     GNUNET_OS_INHERIT_STD_ERR,
     254             :     NULL, NULL, NULL,
     255             :     "taler-bank-manage-testing",
     256             :     "taler-bank-manage-testing",
     257             :     config_filename,
     258             :     database,
     259             :     "serve", NULL);
     260           0 :   GNUNET_free (database);
     261           0 :   if (NULL == bank_proc)
     262             :   {
     263           0 :     BANK_FAIL ();
     264             :   }
     265             : 
     266           0 :   GNUNET_asprintf (&wget_cmd,
     267             :                    "wget -q -t 2 -T 1 %s -o /dev/null -O /dev/null",
     268             :                    bank_url);
     269             : 
     270             :   /* give child time to start and bind against the socket */
     271           0 :   fprintf (stderr,
     272             :            "Waiting for `taler-bank-manage' to be ready (via %s)\n", wget_cmd);
     273           0 :   iter = 0;
     274             :   do
     275             :   {
     276           0 :     if (10 == iter)
     277             :     {
     278           0 :       fprintf (
     279             :         stderr,
     280             :         "Failed to launch `taler-bank-manage' (or `wget')\n");
     281           0 :       GNUNET_OS_process_kill (bank_proc,
     282             :                               SIGTERM);
     283           0 :       GNUNET_OS_process_wait (bank_proc);
     284           0 :       GNUNET_OS_process_destroy (bank_proc);
     285           0 :       GNUNET_free (wget_cmd);
     286           0 :       BANK_FAIL ();
     287             :     }
     288           0 :     fprintf (stderr, ".");
     289           0 :     sleep (1);
     290           0 :     iter++;
     291             :   }
     292           0 :   while (0 != system (wget_cmd));
     293           0 :   GNUNET_free (wget_cmd);
     294           0 :   fprintf (stderr, "\n");
     295             : 
     296           0 :   return bank_proc;
     297             : 
     298             : }
     299             : 
     300             : 
     301             : enum GNUNET_GenericReturnValue
     302           1 : TALER_TESTING_prepare_nexus (const char *config_filename,
     303             :                              int reset_db,
     304             :                              const char *config_section,
     305             :                              struct TALER_TESTING_BankConfiguration *bc)
     306             : {
     307             :   struct GNUNET_CONFIGURATION_Handle *cfg;
     308             :   unsigned long long port;
     309           1 :   char *database = NULL; // silence compiler
     310             :   char *exchange_payto_uri;
     311             : 
     312           1 :   GNUNET_assert (0 ==
     313             :                  strncasecmp (config_section,
     314             :                               "exchange-account-",
     315             :                               strlen ("exchange-account-")));
     316           1 :   cfg = GNUNET_CONFIGURATION_create ();
     317           1 :   if (GNUNET_OK !=
     318           1 :       GNUNET_CONFIGURATION_load (cfg,
     319             :                                  config_filename))
     320             :   {
     321           0 :     GNUNET_CONFIGURATION_destroy (cfg);
     322           0 :     GNUNET_break (0);
     323           0 :     return GNUNET_SYSERR;
     324             :   }
     325             : 
     326           1 :   if (GNUNET_OK !=
     327           1 :       GNUNET_CONFIGURATION_get_value_string (cfg,
     328             :                                              config_section,
     329             :                                              "PAYTO_URI",
     330             :                                              &exchange_payto_uri))
     331             :   {
     332           0 :     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
     333             :                                config_section,
     334             :                                "PAYTO_URI");
     335           0 :     GNUNET_CONFIGURATION_destroy (cfg);
     336           0 :     return GNUNET_SYSERR;
     337             :   }
     338             : 
     339           1 :   if (GNUNET_OK !=
     340           1 :       GNUNET_CONFIGURATION_get_value_number (cfg,
     341             :                                              "bank",
     342             :                                              "HTTP_PORT",
     343             :                                              &port))
     344             :   {
     345           0 :     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
     346             :                                "bank",
     347             :                                "HTTP_PORT");
     348           0 :     GNUNET_CONFIGURATION_destroy (cfg);
     349           0 :     GNUNET_free (database);
     350           0 :     GNUNET_break (0);
     351           0 :     return GNUNET_SYSERR;
     352             :   }
     353             : 
     354           1 :   if (GNUNET_OK !=
     355           1 :       GNUNET_NETWORK_test_port_free (IPPROTO_TCP,
     356           1 :                                      (uint16_t) port))
     357             :   {
     358           0 :     fprintf (stderr,
     359             :              "Required port %llu not available, skipping.\n",
     360             :              port);
     361           0 :     GNUNET_break (0);
     362           0 :     GNUNET_free (database);
     363           0 :     GNUNET_CONFIGURATION_destroy (cfg);
     364           0 :     return GNUNET_SYSERR;
     365             :   }
     366             : 
     367             :   /* DB preparation */
     368           1 :   if (GNUNET_YES == reset_db)
     369             :   {
     370           1 :     if (0 != system ("rm -f /tmp/libeufin-exchange-test.sqlite3"))
     371             :     {
     372           0 :       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     373             :                   "Failed to invoke db-removal command.\n");
     374           0 :       GNUNET_free (database);
     375           0 :       GNUNET_CONFIGURATION_destroy (cfg);
     376           0 :       return GNUNET_SYSERR;
     377             :     }
     378             :   }
     379             : 
     380             :   {
     381             :     char *csn;
     382             : 
     383           1 :     GNUNET_asprintf (&csn,
     384             :                      "exchange-accountcredentials-%s",
     385             :                      &config_section[strlen ("exchange-account-")]);
     386             : 
     387             : 
     388           1 :     if (GNUNET_OK !=
     389           1 :         TALER_BANK_auth_parse_cfg (cfg,
     390             :                                    csn,
     391             :                                    &bc->exchange_auth))
     392             :     {
     393           0 :       GNUNET_break (0);
     394           0 :       GNUNET_CONFIGURATION_destroy (cfg);
     395           0 :       GNUNET_free (csn);
     396           0 :       return GNUNET_SYSERR;
     397             :     }
     398           1 :     GNUNET_free (csn);
     399             :   }
     400           1 :   GNUNET_CONFIGURATION_destroy (cfg);
     401           1 :   bc->exchange_payto = exchange_payto_uri;
     402           1 :   bc->user42_payto =
     403             :     "payto://iban/SANDBOXX/FR7630006000011234567890189?receiver-name=User42";
     404           1 :   bc->user43_payto =
     405             :     "payto://iban/SANDBOXX/GB33BUKB20201555555555?receiver-name=User43";
     406           1 :   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
     407             :               "Relying on nexus %s on port %u\n",
     408             :               bc->exchange_auth.wire_gateway_url,
     409             :               (unsigned int) port);
     410           1 :   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "exchange payto: %s\n",
     411             :               bc->exchange_payto);
     412           1 :   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "user42_payto: %s\n",
     413             :               bc->user42_payto);
     414           1 :   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "user42_payto: %s\n",
     415             :               bc->user43_payto);
     416           1 :   return GNUNET_OK;
     417             : }
     418             : 
     419             : 
     420             : enum GNUNET_GenericReturnValue
     421           0 : TALER_TESTING_prepare_bank (const char *config_filename,
     422             :                             int reset_db,
     423             :                             const char *config_section,
     424             :                             struct TALER_TESTING_BankConfiguration *bc)
     425             : {
     426             :   struct GNUNET_CONFIGURATION_Handle *cfg;
     427             :   unsigned long long port;
     428             :   struct GNUNET_OS_Process *dbreset_proc;
     429             :   enum GNUNET_OS_ProcessStatusType type;
     430             :   unsigned long code;
     431             :   char *database;
     432             :   char *exchange_payto_uri;
     433             : 
     434           0 :   GNUNET_assert (0 ==
     435             :                  strncasecmp (config_section,
     436             :                               "exchange-account-",
     437             :                               strlen ("exchange-account-")));
     438           0 :   cfg = GNUNET_CONFIGURATION_create ();
     439             : 
     440           0 :   if (GNUNET_OK !=
     441           0 :       GNUNET_CONFIGURATION_load (cfg,
     442             :                                  config_filename))
     443             :   {
     444           0 :     GNUNET_CONFIGURATION_destroy (cfg);
     445           0 :     GNUNET_break (0);
     446           0 :     return GNUNET_SYSERR;
     447             :   }
     448           0 :   if (GNUNET_OK !=
     449           0 :       GNUNET_CONFIGURATION_get_value_string (cfg,
     450             :                                              "bank",
     451             :                                              "DATABASE",
     452             :                                              &database))
     453             :   {
     454           0 :     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
     455             :                                "bank",
     456             :                                "DATABASE");
     457           0 :     GNUNET_CONFIGURATION_destroy (cfg);
     458           0 :     GNUNET_break (0);
     459           0 :     return GNUNET_SYSERR;
     460             :   }
     461             : 
     462           0 :   if (GNUNET_OK !=
     463           0 :       GNUNET_CONFIGURATION_get_value_string (cfg,
     464             :                                              config_section,
     465             :                                              "PAYTO_URI",
     466             :                                              &exchange_payto_uri))
     467             :   {
     468           0 :     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
     469             :                                config_section,
     470             :                                "PAYTO_URI");
     471           0 :     GNUNET_CONFIGURATION_destroy (cfg);
     472           0 :     return GNUNET_SYSERR;
     473             :   }
     474             : 
     475           0 :   if (GNUNET_OK !=
     476           0 :       GNUNET_CONFIGURATION_get_value_number (cfg,
     477             :                                              "bank",
     478             :                                              "HTTP_PORT",
     479             :                                              &port))
     480             :   {
     481           0 :     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
     482             :                                "bank",
     483             :                                "HTTP_PORT");
     484           0 :     GNUNET_CONFIGURATION_destroy (cfg);
     485           0 :     GNUNET_free (database);
     486           0 :     GNUNET_break (0);
     487           0 :     return GNUNET_SYSERR;
     488             :   }
     489             : 
     490           0 :   if (GNUNET_OK !=
     491           0 :       GNUNET_NETWORK_test_port_free (IPPROTO_TCP,
     492           0 :                                      (uint16_t) port))
     493             :   {
     494           0 :     fprintf (stderr,
     495             :              "Required port %llu not available, skipping.\n",
     496             :              port);
     497           0 :     GNUNET_break (0);
     498           0 :     GNUNET_free (database);
     499           0 :     GNUNET_CONFIGURATION_destroy (cfg);
     500           0 :     return GNUNET_SYSERR;
     501             :   }
     502             : 
     503             :   /* DB preparation */
     504           0 :   if (GNUNET_YES == reset_db)
     505             :   {
     506           0 :     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
     507             :                 "Flushing bank database\n");
     508           0 :     if (NULL ==
     509           0 :         (dbreset_proc = GNUNET_OS_start_process (
     510             :            GNUNET_OS_INHERIT_STD_ERR,
     511             :            NULL, NULL, NULL,
     512             :            "taler-bank-manage",
     513             :            "taler-bank-manage",
     514             :            "-c", config_filename,
     515             :            "--with-db", database,
     516             :            "django",
     517             :            "flush",
     518             :            "--no-input", NULL)))
     519             :     {
     520           0 :       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     521             :                   "Failed to flush the bank db.\n");
     522           0 :       GNUNET_free (database);
     523           0 :       GNUNET_CONFIGURATION_destroy (cfg);
     524           0 :       return GNUNET_SYSERR;
     525             :     }
     526             : 
     527           0 :     if (GNUNET_SYSERR ==
     528           0 :         GNUNET_OS_process_wait_status (dbreset_proc,
     529             :                                        &type,
     530             :                                        &code))
     531             :     {
     532           0 :       GNUNET_OS_process_destroy (dbreset_proc);
     533           0 :       GNUNET_break (0);
     534           0 :       GNUNET_CONFIGURATION_destroy (cfg);
     535           0 :       GNUNET_free (database);
     536           0 :       return GNUNET_SYSERR;
     537             :     }
     538           0 :     if ( (type == GNUNET_OS_PROCESS_EXITED) &&
     539           0 :          (0 != code) )
     540             :     {
     541           0 :       fprintf (stderr,
     542             :                "Failed to setup database `%s'\n",
     543             :                database);
     544           0 :       GNUNET_break (0);
     545           0 :       GNUNET_CONFIGURATION_destroy (cfg);
     546           0 :       GNUNET_free (database);
     547           0 :       return GNUNET_SYSERR;
     548             :     }
     549           0 :     GNUNET_free (database);
     550           0 :     if ( (type != GNUNET_OS_PROCESS_EXITED) ||
     551           0 :          (0 != code) )
     552             :     {
     553           0 :       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     554             :                   "Unexpected error running `taler-bank-manage django flush'!\n");
     555           0 :       GNUNET_break (0);
     556           0 :       GNUNET_CONFIGURATION_destroy (cfg);
     557           0 :       return GNUNET_SYSERR;
     558             :     }
     559           0 :     GNUNET_OS_process_destroy (dbreset_proc);
     560             :   }
     561             :   {
     562             :     char *csn;
     563             : 
     564           0 :     GNUNET_asprintf (&csn,
     565             :                      "exchange-accountcredentials-%s",
     566             :                      &config_section[strlen ("exchange-account-")]);
     567             : 
     568           0 :     if (GNUNET_OK !=
     569           0 :         TALER_BANK_auth_parse_cfg (cfg,
     570             :                                    csn,
     571             :                                    &bc->exchange_auth))
     572             :     {
     573           0 :       GNUNET_break (0);
     574           0 :       GNUNET_free (csn);
     575           0 :       GNUNET_CONFIGURATION_destroy (cfg);
     576           0 :       return GNUNET_SYSERR;
     577             :     }
     578           0 :     GNUNET_free (csn);
     579             :   }
     580           0 :   GNUNET_CONFIGURATION_destroy (cfg);
     581           0 :   bc->exchange_payto = exchange_payto_uri;
     582           0 :   bc->user42_payto = "payto://x-taler-bank/localhost/42?receiver-name=42";
     583           0 :   bc->user43_payto = "payto://x-taler-bank/localhost/43?receiver-name=43";
     584           0 :   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
     585             :               "Using pybank %s on port %u\n",
     586             :               bc->exchange_auth.wire_gateway_url,
     587             :               (unsigned int) port);
     588           0 :   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
     589             :               "exchange payto: %s\n",
     590             :               bc->exchange_payto);
     591           0 :   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
     592             :               "user42_payto: %s\n",
     593             :               bc->user42_payto);
     594           0 :   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
     595             :               "user43_payto: %s\n",
     596             :               bc->user43_payto);
     597           0 :   return GNUNET_OK;
     598             : }
     599             : 
     600             : 
     601             : enum GNUNET_GenericReturnValue
     602          15 : TALER_TESTING_prepare_fakebank (const char *config_filename,
     603             :                                 const char *config_section,
     604             :                                 struct TALER_TESTING_BankConfiguration *bc)
     605             : {
     606             :   struct GNUNET_CONFIGURATION_Handle *cfg;
     607             :   unsigned long long fakebank_port;
     608             :   char *exchange_payto_uri;
     609             : 
     610          15 :   cfg = GNUNET_CONFIGURATION_create ();
     611          15 :   if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg,
     612             :                                               config_filename))
     613           0 :     return GNUNET_SYSERR;
     614             : 
     615          15 :   if (GNUNET_OK !=
     616          15 :       GNUNET_CONFIGURATION_get_value_number (cfg,
     617             :                                              "BANK",
     618             :                                              "HTTP_PORT",
     619             :                                              &fakebank_port))
     620             :   {
     621           0 :     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
     622             :                                "BANK",
     623             :                                "HTTP_PORT");
     624           0 :     GNUNET_CONFIGURATION_destroy (cfg);
     625           0 :     return GNUNET_SYSERR;
     626             :   }
     627          15 :   if (GNUNET_OK !=
     628          15 :       GNUNET_CONFIGURATION_get_value_string (cfg,
     629             :                                              config_section,
     630             :                                              "PAYTO_URI",
     631             :                                              &exchange_payto_uri))
     632             :   {
     633           0 :     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
     634             :                                config_section,
     635             :                                "PAYTO_URI");
     636           0 :     GNUNET_CONFIGURATION_destroy (cfg);
     637           0 :     return GNUNET_SYSERR;
     638             :   }
     639             :   {
     640             :     char *exchange_xtalerbank_account;
     641             : 
     642             :     exchange_xtalerbank_account
     643          15 :       = TALER_xtalerbank_account_from_payto (exchange_payto_uri);
     644          15 :     if (NULL == exchange_xtalerbank_account)
     645             :     {
     646           0 :       GNUNET_break (0);
     647           0 :       GNUNET_free (exchange_payto_uri);
     648           0 :       return GNUNET_SYSERR;
     649             :     }
     650          15 :     GNUNET_asprintf (&bc->exchange_auth.wire_gateway_url,
     651             :                      "http://localhost:%u/%s/",
     652             :                      (unsigned int) fakebank_port,
     653             :                      exchange_xtalerbank_account);
     654          15 :     GNUNET_free (exchange_xtalerbank_account);
     655             :   }
     656          15 :   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
     657             :               "Using fakebank %s on port %u\n",
     658             :               bc->exchange_auth.wire_gateway_url,
     659             :               (unsigned int) fakebank_port);
     660             : 
     661          15 :   GNUNET_CONFIGURATION_destroy (cfg);
     662          15 :   if (GNUNET_OK !=
     663          15 :       TALER_TESTING_url_port_free (bc->exchange_auth.wire_gateway_url))
     664             :   {
     665           0 :     GNUNET_free (bc->exchange_auth.wire_gateway_url);
     666           0 :     bc->exchange_auth.wire_gateway_url = NULL;
     667           0 :     GNUNET_free (exchange_payto_uri);
     668           0 :     return GNUNET_SYSERR;
     669             :   }
     670             :   /* Now we know it's the fake bank, for purpose of authentication, we
     671             :    * don't have any auth. */
     672          15 :   bc->exchange_auth.method = TALER_BANK_AUTH_NONE;
     673          15 :   bc->exchange_payto = exchange_payto_uri;
     674          15 :   bc->user42_payto = "payto://x-taler-bank/localhost/42?receiver-name=42";
     675          15 :   bc->user43_payto = "payto://x-taler-bank/localhost/43?receiver-name=43";
     676          15 :   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "exchange payto: %s\n",
     677             :               bc->exchange_payto);
     678          15 :   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "user42_payto: %s\n",
     679             :               bc->user42_payto);
     680          15 :   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "user43_payto: %s\n",
     681             :               bc->user43_payto);
     682          15 :   return GNUNET_OK;
     683             : }
     684             : 
     685             : 
     686             : json_t *
     687           0 : TALER_TESTING_make_wire_details (const char *payto)
     688             : {
     689             :   struct TALER_WireSaltP salt;
     690             : 
     691             :   /* salt must be constant for aggregation tests! */
     692           0 :   memset (&salt,
     693             :           47,
     694             :           sizeof (salt));
     695           0 :   return GNUNET_JSON_PACK (
     696             :     GNUNET_JSON_pack_string ("payto_uri",
     697             :                              payto),
     698             :     GNUNET_JSON_pack_data_auto ("salt",
     699             :                                 &salt));
     700             : }
     701             : 
     702             : 
     703             : /* end of testing_api_helpers_bank.c */

Generated by: LCOV version 1.14