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

Generated by: LCOV version 1.14