test_anastasis.c (16882B)
1 /* 2 This file is part of Anastasis 3 Copyright (C) 2020-2023 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.c 18 * @brief testcase to test anastasis 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 * Credentials for the test. The bank accounts of the payer 48 * (@e user42_payto) and 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 * Name of the file for exchanging the secret. 70 */ 71 static char *file_secret; 72 73 /** 74 * Anastasis process. 75 */ 76 static struct GNUNET_Process *anastasisd; 77 78 /** 79 * Identity to use for testing. 80 */ 81 static json_t *id_data; 82 83 84 /** 85 * Execute the taler-exchange-wirewatch command with 86 * our configuration file. 87 * 88 * @param label label to use for the command. 89 */ 90 static struct TALER_TESTING_Command 91 cmd_exec_wirewatch (const char *label) 92 { 93 return TALER_TESTING_cmd_exec_wirewatch (label, 94 CONFIG_FILE); 95 } 96 97 98 /** 99 * Run wire transfer of funds from some user's account to the 100 * exchange. 101 * 102 * @param label label to use for the command. 103 * @param amount amount to transfer, i.e. "EUR:1" 104 * @param url exchange_url 105 */ 106 static struct TALER_TESTING_Command 107 cmd_transfer_to_exchange (const char *label, 108 const char *amount) 109 { 110 return TALER_TESTING_cmd_admin_add_incoming (label, 111 amount, 112 &cred.ba_admin, 113 cred.user42_payto); 114 } 115 116 117 /** 118 * Main function that will tell the interpreter what commands to 119 * run. 120 * 121 * @param cls closure 122 */ 123 static void 124 run (void *cls, 125 struct TALER_TESTING_Interpreter *is) 126 { 127 struct TALER_TESTING_Command pay[] = { 128 /** 129 * Move money to the exchange's bank account. 130 */ 131 cmd_transfer_to_exchange ("create-reserve-1", 132 "EUR:10.02"), 133 /** 134 * Make a reserve exist, according to the previous 135 * transfer. 136 */ 137 cmd_exec_wirewatch ("wirewatch-1"), 138 TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-1", 139 "create-reserve-1", 140 "EUR:5", 141 0, /* age */ 142 MHD_HTTP_OK), 143 TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-2", 144 "create-reserve-1", 145 "EUR:5", 146 0, /* age */ 147 MHD_HTTP_OK), 148 /** 149 * Check the reserve is depleted. 150 */ 151 TALER_TESTING_cmd_status ("withdraw-status-1", 152 "create-reserve-1", 153 "EUR:0", 154 MHD_HTTP_OK), 155 TALER_TESTING_cmd_end () 156 }; 157 158 struct TALER_TESTING_Command anastasis[] = { 159 ANASTASIS_TESTING_cmd_config ("salt-request-1", 160 anastasis_url, 161 MHD_HTTP_OK), 162 ANASTASIS_TESTING_cmd_truth_upload_question ("truth-create-1", 163 anastasis_url, 164 id_data, 165 "answer the question", 166 "text/plain", 167 "SomeTruth1", 168 MHD_HTTP_NO_CONTENT, 169 ANASTASIS_TESTING_TSO_NONE, 170 "salt-request-1"), 171 ANASTASIS_TESTING_cmd_truth_upload_question ("truth-create-2", 172 anastasis_url, 173 id_data, 174 "answer the question", 175 "text/plain", 176 "SomeTruth2", 177 MHD_HTTP_NO_CONTENT, 178 ANASTASIS_TESTING_TSO_NONE, 179 "salt-request-1"), 180 ANASTASIS_TESTING_cmd_truth_upload ("truth-create-3", 181 anastasis_url, 182 id_data, 183 "file", 184 "read the file", 185 "text/plain", 186 file_secret, 187 strlen (file_secret), 188 MHD_HTTP_NO_CONTENT, 189 ANASTASIS_TESTING_TSO_NONE, 190 "salt-request-1"), 191 ANASTASIS_TESTING_cmd_policy_create ("policy-create-1", 192 "truth-create-1", 193 "truth-create-2", 194 NULL), 195 ANASTASIS_TESTING_cmd_policy_create ("policy-create-2", 196 "truth-create-1", 197 "truth-create-3", 198 NULL), 199 ANASTASIS_TESTING_cmd_policy_create ("policy-create-3", 200 "truth-create-2", 201 "truth-create-3", 202 NULL), 203 ANASTASIS_TESTING_cmd_secret_share ("secret-share-1", 204 anastasis_url, 205 "salt-request-1", 206 NULL, 207 id_data, 208 "core secret", 209 strlen ("core secret"), 210 ANASTASIS_SHARE_STATUS_PAYMENT_REQUIRED, 211 ANASTASIS_TESTING_SSO_NONE, 212 "policy-create-1", 213 "policy-create-2", 214 "policy-create-3", 215 NULL), 216 /* what would we have to pay? */ 217 TALER_TESTING_cmd_merchant_claim_order ("fetch-proposal", 218 merchant_url, 219 MHD_HTTP_OK, 220 "secret-share-1", 221 NULL), 222 /* make the payment */ 223 TALER_TESTING_cmd_merchant_pay_order_choices ( 224 "pay-account", 225 merchant_url, 226 MHD_HTTP_OK, 227 "fetch-proposal", 228 "withdraw-coin-1", 229 "EUR:5", 230 "EUR:4.99", /* must match ANNUAL_FEE in config! */ 231 NULL, 232 /* Anastasis creates "v1" orders now; every configured currency 233 is a choice and the first one is the primary currency. */ 234 0, 235 NULL), 236 ANASTASIS_TESTING_cmd_secret_share ("secret-share-2", 237 anastasis_url, 238 "salt-request-1", 239 "secret-share-1", 240 id_data, 241 "core secret", 242 strlen ("core secret"), 243 ANASTASIS_SHARE_STATUS_SUCCESS, 244 ANASTASIS_TESTING_SSO_NONE, 245 "policy-create-1", 246 "policy-create-2", 247 "policy-create-3", 248 NULL), 249 ANASTASIS_TESTING_cmd_recover_secret ("recover-secret-1", 250 anastasis_url, 251 id_data, 252 0, /* version */ 253 ANASTASIS_TESTING_RSO_NONE, 254 "salt-request-1", 255 "secret-share-2"), 256 ANASTASIS_TESTING_cmd_challenge_answer ("challenge-answer-1", 257 NULL, /* payment ref */ 258 "recover-secret-1", /* challenge ref */ 259 0, /* challenge index */ 260 "SomeTruth1", 261 0, /* mode */ 262 ANASTASIS_CHALLENGE_ANSWER_STATUS_SOLVED), 263 #if 0 264 ANASTASIS_TESTING_cmd_challenge_answer ("challenge-answer-2", 265 NULL, /* payment ref */ 266 "recover-secret-1", 267 1, /* challenge index */ 268 "SomeTruth2", 269 0, /* mode */ 270 ANASTASIS_CHALLENGE_ANSWER_STATUS_SOLVED), 271 #endif 272 ANASTASIS_TESTING_cmd_challenge_start ("challenge-start-3-pay", 273 NULL, /* payment ref */ 274 "recover-secret-1", 275 2, /* challenge index */ 276 ANASTASIS_CHALLENGE_START_STATUS_PAYMENT_REQUIRED), 277 TALER_TESTING_cmd_merchant_claim_order ("fetch-challenge-pay-proposal", 278 merchant_url, 279 MHD_HTTP_OK, 280 "challenge-start-3-pay", 281 NULL), 282 TALER_TESTING_cmd_merchant_pay_order_choices ( 283 "pay-file-challenge", 284 merchant_url, 285 MHD_HTTP_OK, 286 "fetch-challenge-pay-proposal", 287 "withdraw-coin-2", 288 "EUR:1", 289 "EUR:1", /* must match COST in config! */ 290 NULL, 291 /* Anastasis creates "v1" orders now; every configured currency 292 is a choice and the first one is the primary currency. */ 293 0, 294 NULL), 295 ANASTASIS_TESTING_cmd_challenge_start ("challenge-start-3-paid", 296 "challenge-start-3-pay", /* payment ref */ 297 "recover-secret-1", 298 2, /* challenge index */ 299 ANASTASIS_CHALLENGE_START_STATUS_FILENAME_PROVIDED), 300 ANASTASIS_TESTING_cmd_challenge_answer ("challenge-answer-3", 301 "challenge-start-3-pay", /* payment ref */ 302 "recover-secret-1", 303 2, /* challenge index */ 304 "challenge-start-3-paid", /* answer */ 305 1, /* mode */ 306 ANASTASIS_CHALLENGE_ANSWER_STATUS_SOLVED), 307 ANASTASIS_TESTING_cmd_recover_secret_finish ("recover-finish-1", 308 "recover-secret-1", 309 GNUNET_TIME_UNIT_SECONDS), 310 TALER_TESTING_cmd_end () 311 }; 312 313 struct TALER_TESTING_Command commands[] = { 314 /* general setup */ 315 TALER_TESTING_cmd_system_start ("start-taler", 316 CONFIG_FILE, 317 "-bem", 318 "-d", "iban", 319 "-u", "exchange-account-exchange", 320 NULL), 321 TALER_TESTING_cmd_get_exchange ("get-exchange", 322 cred.cfg, 323 NULL, 324 true, 325 true), 326 /* Not TALER_TESTING_cmd_merchant_post_instances(): that one gives the 327 instance a pay delay of two seconds, and the orders here are created 328 by anastasis-httpd, not by the test, so a slow order creation would 329 expire the offer before the test gets to pay it. */ 330 TALER_TESTING_cmd_merchant_post_instances2 ("instance-create-admin", 331 merchant_url, 332 "admin", 333 "admin", 334 json_pack ("{s:s}", 335 "city", 336 "shopcity"), 337 json_pack ("{s:s}", 338 "city", 339 "lawyercity"), 340 true, /* use STEFAN */ 341 GNUNET_TIME_UNIT_ZERO, 342 GNUNET_TIME_UNIT_MINUTES, 343 NULL, /* auth token */ 344 MHD_HTTP_NO_CONTENT), 345 TALER_TESTING_cmd_merchant_post_account ( 346 "instance-create-default-account", 347 merchant_url, 348 merchant_payto, 349 NULL, NULL, 350 MHD_HTTP_OK), 351 TALER_TESTING_cmd_batch ("pay", 352 pay), 353 TALER_TESTING_cmd_batch ("anastasis", 354 anastasis), 355 TALER_TESTING_cmd_end () 356 }; 357 358 TALER_TESTING_run (is, 359 commands); 360 } 361 362 363 int 364 main (int argc, 365 char *const *argv) 366 { 367 int ret; 368 file_secret = ANASTASIS_TESTING_make_file_challenge_name (CONFIG_FILE); 369 if (NULL == file_secret) 370 return 77; 371 id_data = ANASTASIS_TESTING_make_id_data_example ("MaxMuster123456789"); 372 merchant_payto.full_payto = 373 (char *) "payto://iban/SANDBOXX/" MERCHANT_ACCOUNT_IBAN 374 "?receiver-name=merchant"; 375 merchant_url = "http://localhost:8080/"; 376 377 if (NULL == 378 (anastasis_url = ANASTASIS_TESTING_prepare_anastasis (CONFIG_FILE))) 379 return 77; 380 if (NULL == (anastasisd = 381 ANASTASIS_TESTING_run_anastasis (CONFIG_FILE, 382 anastasis_url))) 383 { 384 GNUNET_break (0); 385 return 1; 386 } 387 ret = TALER_TESTING_main (argv, 388 "INFO", 389 CONFIG_FILE, 390 "exchange-account-exchange", 391 TALER_TESTING_BS_IBAN, 392 &cred, 393 &run, 394 NULL); 395 GNUNET_break (GNUNET_OK == 396 GNUNET_process_kill (anastasisd, 397 SIGTERM)); 398 GNUNET_break (GNUNET_OK == 399 GNUNET_process_wait (anastasisd, 400 true, 401 NULL, 402 NULL)); 403 GNUNET_process_destroy (anastasisd); 404 GNUNET_free (anastasis_url); 405 return ret; 406 } 407 408 409 /* end of test_anastasis.c */