test_anastasis_api.c (12357B)
1 /* 2 This file is part of Anastasis 3 Copyright (C) 2020, 2021 Anastasis SARL 4 5 Anastasis is free software; you can redistribute it and/or modify it under the 6 terms of the GNU General Public License as published by the Free Software 7 Foundation; either version 3, or (at your option) any later version. 8 9 Anastasis is distributed in the hope that it will be useful, but WITHOUT ANY 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License along with 14 Anastasis; see the file COPYING.GPL. If not, see <http://www.gnu.org/licenses/> 15 */ 16 /** 17 * @file testing/test_anastasis_api.c 18 * @brief testcase to test anastasis' HTTP API interface 19 * @author Christian Grothoff 20 * @author Dennis Neufeld 21 * @author Dominik Meister 22 */ 23 #include "platform.h" 24 #include "anastasis_testing_lib.h" 25 #include <taler/taler_merchant_testing_lib.h> 26 27 28 /** 29 * Configuration file we use. One (big) configuration is used 30 * for the various components for this test. 31 */ 32 #define CONFIG_FILE "test_anastasis_api.conf" 33 34 /** 35 * Exchange base URL. Could also be taken from config. 36 */ 37 #define EXCHANGE_URL "http://localhost:8081/" 38 39 /** 40 * IBAN of the account the merchant is paid into. Unlike the accounts of 41 * the payer and of the exchange, this one need not exist at the bank: the 42 * test never runs the aggregator, so nothing is ever transferred to it. 43 */ 44 #define MERCHANT_ACCOUNT_IBAN "DE89370400440532013000" 45 46 /** 47 * Test credentials. The bank accounts of the payer (@e user42_payto) and 48 * of the exchange (@e exchange_payto) are the ones 49 * `taler-unified-setup.sh' registers at libeufin-bank. 50 */ 51 static struct TALER_TESTING_Credentials cred; 52 53 /** 54 * Payto URI of the merchant (receiver). 55 */ 56 static struct TALER_FullPayto merchant_payto; 57 58 /** 59 * Merchant base URL. 60 */ 61 static const char *merchant_url; 62 63 /** 64 * Anastasis base URL. 65 */ 66 static char *anastasis_url; 67 68 /** 69 * Anastasis process. 70 */ 71 static struct GNUNET_Process *anastasisd; 72 73 /** 74 * Name of the file for exchanging the secret. 75 */ 76 static char *file_secret; 77 78 /** 79 * Execute the taler-exchange-wirewatch command with our configuration 80 * file. 81 * 82 * @param label label to use for the command. 83 */ 84 static struct TALER_TESTING_Command 85 cmd_exec_wirewatch (const char *label) 86 { 87 return TALER_TESTING_cmd_exec_wirewatch (label, 88 CONFIG_FILE); 89 } 90 91 92 /** 93 * Run wire transfer of funds from some user's account to the 94 * exchange. 95 * 96 * @param label label to use for the command. 97 * @param amount amount to transfer, i.e. "EUR:1" 98 * @param url exchange_url 99 */ 100 static struct TALER_TESTING_Command 101 cmd_transfer_to_exchange (const char *label, 102 const char *amount) 103 { 104 return TALER_TESTING_cmd_admin_add_incoming (label, 105 amount, 106 &cred.ba_admin, 107 cred.user42_payto); 108 } 109 110 111 /** 112 * Main function that will tell the interpreter what commands to run. 113 * 114 * @param cls closure 115 */ 116 static void 117 run (void *cls, 118 struct TALER_TESTING_Interpreter *is) 119 { 120 struct TALER_TESTING_Command withdraw[] = { 121 cmd_transfer_to_exchange ("create-reserve-1", 122 "EUR:10.02"), 123 cmd_exec_wirewatch ("wirewatch-1"), 124 TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-1", 125 "create-reserve-1", 126 "EUR:5", 127 0, /* age */ 128 MHD_HTTP_OK), 129 TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-2", 130 "create-reserve-1", 131 "EUR:5", 132 0, /* age */ 133 MHD_HTTP_OK), 134 TALER_TESTING_cmd_status ("withdraw-status-1", 135 "create-reserve-1", 136 "EUR:0", 137 MHD_HTTP_OK), 138 TALER_TESTING_cmd_end () 139 }; 140 141 struct TALER_TESTING_Command policy[] = { 142 ANASTASIS_TESTING_cmd_policy_store ("policy-store-1", 143 anastasis_url, 144 NULL /* prev upload */, 145 MHD_HTTP_PAYMENT_REQUIRED, 146 ANASTASIS_TESTING_PSO_NONE, 147 "Test-1", 148 strlen ("Test-1")), 149 /* what would we have to pay? */ 150 TALER_TESTING_cmd_merchant_claim_order ("fetch-proposal", 151 merchant_url, 152 MHD_HTTP_OK, 153 "policy-store-1", 154 NULL), 155 /* make the payment */ 156 TALER_TESTING_cmd_merchant_pay_order_choices ( 157 "pay-account", 158 merchant_url, 159 MHD_HTTP_OK, 160 "fetch-proposal", 161 "withdraw-coin-1", 162 "EUR:5", 163 "EUR:4.99", /* must match ANNUAL_FEE in config! */ 164 NULL, 165 /* Anastasis creates "v1" orders now; every configured currency 166 is a choice and the first one is the primary currency. */ 167 0, 168 NULL), 169 ANASTASIS_TESTING_cmd_policy_store ("policy-store-2", 170 anastasis_url, 171 "policy-store-1", 172 MHD_HTTP_NO_CONTENT, 173 ANASTASIS_TESTING_PSO_NONE, 174 "Test-1", 175 strlen ("Test-1")), 176 ANASTASIS_TESTING_cmd_policy_lookup ("policy-lookup-1", 177 anastasis_url, 178 MHD_HTTP_OK, 179 "policy-store-2"), 180 TALER_TESTING_cmd_end () 181 }; 182 183 struct TALER_TESTING_Command truth[] = { 184 ANASTASIS_TESTING_cmd_truth_question ( 185 "truth-store-1", 186 anastasis_url, 187 NULL, 188 "The-Answer", 189 ANASTASIS_TESTING_TSO_NONE, 190 MHD_HTTP_NO_CONTENT), 191 ANASTASIS_TESTING_cmd_truth_solve ( 192 "keyshare-lookup-1", 193 anastasis_url, 194 "The-Answer", 195 NULL, /* payment ref */ 196 "truth-store-1", 197 0, 198 MHD_HTTP_OK), 199 ANASTASIS_TESTING_cmd_truth_store ( 200 "truth-store-2", 201 anastasis_url, 202 NULL, 203 "file", 204 "text/plain", 205 strlen (file_secret), 206 file_secret, 207 ANASTASIS_TESTING_TSO_NONE, 208 MHD_HTTP_NO_CONTENT), 209 ANASTASIS_TESTING_cmd_truth_solve ( 210 "challenge-fail-1", 211 anastasis_url, 212 "Wrong-Answer", 213 NULL, /* payment ref */ 214 "truth-store-1", /* upload ref */ 215 0, /* security question mode */ 216 MHD_HTTP_FORBIDDEN), 217 ANASTASIS_TESTING_cmd_truth_challenge ( 218 "file-challenge-run-1", 219 anastasis_url, 220 NULL, /* payment ref */ 221 "truth-store-2", /* upload ref */ 222 MHD_HTTP_PAYMENT_REQUIRED), 223 /* what would we have to pay? */ 224 TALER_TESTING_cmd_merchant_claim_order ("fetch-proposal-2", 225 merchant_url, 226 MHD_HTTP_OK, 227 "file-challenge-run-1", 228 NULL), 229 /* make the payment */ 230 TALER_TESTING_cmd_merchant_pay_order_choices ( 231 "pay-account-2", 232 merchant_url, 233 MHD_HTTP_OK, 234 "fetch-proposal-2", 235 "withdraw-coin-2", 236 "EUR:1.01", 237 "EUR:1", 238 NULL, 239 /* Anastasis creates "v1" orders now; every configured currency 240 is a choice and the first one is the primary currency. */ 241 0, 242 NULL), 243 244 ANASTASIS_TESTING_cmd_truth_challenge ( 245 "file-challenge-run-2", 246 anastasis_url, 247 "file-challenge-run-1", /* payment ref */ 248 "truth-store-2", 249 MHD_HTTP_OK), 250 ANASTASIS_TESTING_cmd_truth_solve ( 251 "file-challenge-run-3", 252 anastasis_url, 253 "file-challenge-run-2", /* answer */ 254 "file-challenge-run-1", /* payment ref */ 255 "truth-store-2", 256 1, 257 MHD_HTTP_OK), 258 TALER_TESTING_cmd_end () 259 }; 260 261 struct TALER_TESTING_Command commands[] = { 262 /* general setup */ 263 TALER_TESTING_cmd_system_start ("start-taler", 264 CONFIG_FILE, 265 "-bem", 266 "-d", "iban", 267 "-u", "exchange-account-exchange", 268 NULL), 269 TALER_TESTING_cmd_get_exchange ("get-exchange", 270 cred.cfg, 271 NULL, 272 true, 273 true), 274 /* Not TALER_TESTING_cmd_merchant_post_instances(): that one gives the 275 instance a pay delay of two seconds, and the orders here are created 276 by anastasis-httpd, not by the test, so a slow order creation would 277 expire the offer before the test gets to pay it. */ 278 TALER_TESTING_cmd_merchant_post_instances2 ("instance-create-admin", 279 merchant_url, 280 "admin", 281 "admin", 282 json_pack ("{s:s}", 283 "city", 284 "shopcity"), 285 json_pack ("{s:s}", 286 "city", 287 "lawyercity"), 288 true, /* use STEFAN */ 289 GNUNET_TIME_UNIT_ZERO, 290 GNUNET_TIME_UNIT_MINUTES, 291 NULL, /* auth token */ 292 MHD_HTTP_NO_CONTENT), 293 TALER_TESTING_cmd_merchant_post_account ( 294 "instance-create-default-account", 295 merchant_url, 296 merchant_payto, 297 NULL, NULL, 298 MHD_HTTP_OK), 299 ANASTASIS_TESTING_cmd_config ("salt-request-1", 300 anastasis_url, 301 MHD_HTTP_OK), 302 TALER_TESTING_cmd_batch ("withdraw", 303 withdraw), 304 TALER_TESTING_cmd_batch ("policy", 305 policy), 306 TALER_TESTING_cmd_batch ("truth", 307 truth), 308 TALER_TESTING_cmd_end () 309 }; 310 311 TALER_TESTING_run (is, 312 commands); 313 } 314 315 316 int 317 main (int argc, 318 char *const *argv) 319 { 320 int ret; 321 322 file_secret = ANASTASIS_TESTING_make_file_challenge_name (CONFIG_FILE); 323 if (NULL == file_secret) 324 return 77; 325 merchant_payto.full_payto = 326 (char *) "payto://iban/SANDBOXX/" MERCHANT_ACCOUNT_IBAN 327 "?receiver-name=merchant"; 328 merchant_url = "http://localhost:8080/"; 329 330 if (NULL == 331 (anastasis_url = ANASTASIS_TESTING_prepare_anastasis (CONFIG_FILE))) 332 return 77; 333 if (NULL == (anastasisd = 334 ANASTASIS_TESTING_run_anastasis (CONFIG_FILE, 335 anastasis_url))) 336 { 337 GNUNET_break (0); 338 return 1; 339 } 340 ret = TALER_TESTING_main (argv, 341 "INFO", 342 CONFIG_FILE, 343 "exchange-account-exchange", 344 TALER_TESTING_BS_IBAN, 345 &cred, 346 &run, 347 NULL); 348 GNUNET_break (GNUNET_OK == 349 GNUNET_process_kill (anastasisd, 350 SIGTERM)); 351 GNUNET_break (GNUNET_OK == 352 GNUNET_process_wait (anastasisd, 353 true, 354 NULL, 355 NULL)); 356 GNUNET_process_destroy (anastasisd); 357 GNUNET_free (anastasis_url); 358 return ret; 359 } 360 361 362 /* end of test_anastasis_api.c */