test_bank_api.c (6134B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2016-2023 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, 8 or (at your option) any later version. 9 10 TALER is distributed in the hope that it will be useful, 11 but 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, 17 see <http://www.gnu.org/licenses/> 18 */ 19 /** 20 * @file testing/test_bank_api.c 21 * @brief testcase to test bank's HTTP API 22 * interface against the fakebank 23 * @author Marcello Stanisci 24 * @author Christian Grothoff 25 */ 26 #include "taler/platform.h" 27 #include "taler/taler_util.h" 28 #include "taler/taler_signatures.h" 29 #include "taler/taler_bank_service.h" 30 #include "taler/taler_exchange_service.h" 31 #include <gnunet/gnunet_util_lib.h> 32 #include <gnunet/gnunet_curl_lib.h> 33 #include <microhttpd.h> 34 #include "taler/taler_testing_lib.h" 35 36 #define CONFIG_FILE_FAKEBANK "test_bank_api_fakebank.conf" 37 38 #define CONFIG_FILE_NEXUS "test_bank_api_nexus.conf" 39 40 41 /** 42 * Configuration file. It changes based on 43 * whether Nexus or Fakebank are used. 44 */ 45 static const char *cfgfile; 46 47 /** 48 * Our credentials. 49 */ 50 static struct TALER_TESTING_Credentials cred; 51 52 /** 53 * Which bank is the test running against? 54 * Set up at runtime. 55 */ 56 static enum TALER_TESTING_BankSystem bs; 57 58 59 /** 60 * Main function that will tell the interpreter what commands to 61 * run. 62 * 63 * @param cls closure 64 */ 65 static void 66 run (void *cls, 67 struct TALER_TESTING_Interpreter *is) 68 { 69 struct TALER_WireTransferIdentifierRawP wtid; 70 const char *ssoptions; 71 72 (void) cls; 73 switch (bs) 74 { 75 case TALER_TESTING_BS_FAKEBANK: 76 ssoptions = "-f"; 77 break; 78 case TALER_TESTING_BS_IBAN: 79 ssoptions = "-b"; 80 break; 81 default: 82 ssoptions = NULL; 83 break; 84 } 85 memset (&wtid, 86 42, 87 sizeof (wtid)); 88 89 { 90 struct TALER_TESTING_Command commands[] = { 91 TALER_TESTING_cmd_system_start ("start-taler", 92 cfgfile, 93 ssoptions, 94 NULL), 95 TALER_TESTING_cmd_bank_credits ("history-0", 96 &cred.ba, 97 NULL, 98 1), 99 TALER_TESTING_cmd_admin_add_incoming ("credit-1", 100 "EUR:5.01", 101 &cred.ba_admin, 102 cred.user42_payto), 103 /** 104 * This CMD doesn't care about the HTTP response code; that's 105 * because Fakebank and euFin behaves differently when a reserve 106 * pub is duplicate. Fakebank responds with 409, whereas euFin 107 * with 200 but it bounces the payment back to the customer. 108 */ 109 TALER_TESTING_cmd_admin_add_incoming_with_ref ("credit-1-fail", 110 "EUR:2.01", 111 &cred.ba_admin, 112 cred.user42_payto, 113 "credit-1", 114 -1), 115 /** 116 * Check that the incoming payment with a duplicate 117 * reserve public key didn't make it to the exchange. 118 */ 119 TALER_TESTING_cmd_bank_credits ("history-1c", 120 &cred.ba, 121 NULL, 122 5), 123 TALER_TESTING_cmd_bank_debits ("history-1d", 124 &cred.ba, 125 NULL, 126 5), 127 TALER_TESTING_cmd_admin_add_incoming ("credit-2", 128 "EUR:3.21", 129 &cred.ba_admin, 130 cred.user42_payto), 131 TALER_TESTING_cmd_transfer ("debit-1", 132 "EUR:3.22", 133 &cred.ba, 134 cred.exchange_payto, 135 cred.user42_payto, 136 &wtid, 137 "http://exchange.example.com/"), 138 TALER_TESTING_cmd_bank_debits ("history-2b", 139 &cred.ba, 140 NULL, 141 5), 142 TALER_TESTING_cmd_end () 143 }; 144 145 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 146 "Bank serves at `%s'\n", 147 cred.ba.wire_gateway_url); 148 TALER_TESTING_run (is, 149 commands); 150 } 151 } 152 153 154 int 155 main (int argc, 156 char *const *argv) 157 { 158 (void) argc; 159 if (TALER_TESTING_has_in_name (argv[0], 160 "_with_fakebank")) 161 { 162 bs = TALER_TESTING_BS_FAKEBANK; 163 cfgfile = CONFIG_FILE_FAKEBANK; 164 } 165 else if (TALER_TESTING_has_in_name (argv[0], 166 "_with_nexus")) 167 { 168 bs = TALER_TESTING_BS_FAKEBANK; 169 cfgfile = CONFIG_FILE_NEXUS; 170 if (GNUNET_SYSERR == 171 GNUNET_OS_check_helper_binary ("libeufin-bank", 172 false, 173 NULL)) 174 { 175 fprintf (stderr, 176 "libeufin-bank not found. Skipping test.\n"); 177 return 77; 178 } 179 } 180 else 181 { 182 /* no bank service was specified. */ 183 GNUNET_break (0); 184 return 77; 185 } 186 return TALER_TESTING_main (argv, 187 "INFO", 188 cfgfile, 189 "exchange-account-2", 190 bs, 191 &cred, 192 &run, 193 NULL); 194 } 195 196 197 /* end of test_bank_api.c */