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