test_kyc_api.c (15758B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2014-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, 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 test_kyc_api.c 21 * @brief testcase to test exchange's HTTP API interface 22 * @author Sree Harsha Totakura <sreeharsha@totakura.in> 23 * @author Christian Grothoff 24 * @author Marcello Stanisci 25 */ 26 #include "platform.h" 27 #include <taler/taler_util.h> 28 #include <taler/taler_signatures.h> 29 #include <taler/taler_exchange_service.h> 30 #include <taler/taler_json_lib.h> 31 #include <gnunet/gnunet_util_lib.h> 32 #include <microhttpd.h> 33 #include <taler/taler_bank_service.h> 34 #include <taler/taler_fakebank_lib.h> 35 #include <taler/taler_testing_lib.h> 36 #include <taler/taler_error_codes.h> 37 #include "taler_merchant_testing_lib.h" 38 39 40 /** 41 * Configuration file we use. One (big) configuration is used 42 * for the various components for this test. 43 */ 44 #define CONFIG_FILE "test_kyc_api.conf" 45 46 /** 47 * Exchange base URL. Could also be taken from config. 48 */ 49 #define EXCHANGE_URL "http://localhost:8081/" 50 51 /** 52 * Payto URI of the customer (payer). 53 */ 54 static struct TALER_FullPayto payer_payto; 55 56 /** 57 * Payto URI of the exchange (escrow account). 58 */ 59 static struct TALER_FullPayto exchange_payto; 60 61 /** 62 * Payto URI of the merchant (receiver). 63 */ 64 static struct TALER_FullPayto merchant_payto; 65 66 /** 67 * Credentials for the test. 68 */ 69 static struct TALER_TESTING_Credentials cred; 70 71 /** 72 * Merchant base URL. 73 */ 74 static const char *merchant_url; 75 76 /** 77 * Merchant instance "i1a" base URL. 78 */ 79 static char *merchant_url_i1a; 80 81 /** 82 * Account number of the exchange at the bank. 83 */ 84 #define EXCHANGE_ACCOUNT_NAME "2" 85 86 /** 87 * Account number of some user. 88 */ 89 #define USER_ACCOUNT_NAME "62" 90 91 /** 92 * Account number used by the merchant 93 */ 94 #define MERCHANT_ACCOUNT_NAME "3" 95 96 97 /** 98 * Execute the taler-exchange-aggregator and transfer commands with 99 * our configuration file. 100 * 101 * @param label label to use for the command. 102 */ 103 #define CMD_EXEC_AGGREGATOR(label) \ 104 TALER_TESTING_cmd_exec_aggregator_with_kyc (label "-aggregator", \ 105 CONFIG_FILE), \ 106 TALER_TESTING_cmd_exec_transfer (label "-transfer", CONFIG_FILE) 107 108 /** 109 * Execute the taler-exchange-wirewatch command with 110 * our configuration file. 111 * 112 * @param label label to use for the command. 113 */ 114 #define CMD_EXEC_WIREWATCH(label) \ 115 TALER_TESTING_cmd_exec_wirewatch2 ( \ 116 label, \ 117 CONFIG_FILE, \ 118 "exchange-account-exchange") 119 120 121 /** 122 * Run wire transfer of funds from some user's account to the 123 * exchange. 124 * 125 * @param label label to use for the command. 126 * @param amount amount to transfer, i.e. "EUR:1" 127 * @param url exchange_url 128 */ 129 static struct TALER_TESTING_Command 130 cmd_transfer_to_exchange (const char *label, 131 const char *amount) 132 { 133 return TALER_TESTING_cmd_admin_add_incoming (label, 134 amount, 135 &cred.ba, 136 payer_payto); 137 } 138 139 140 /** 141 * Main function that will tell the interpreter what commands to 142 * run. 143 * 144 * @param cls closure 145 */ 146 static void 147 run (void *cls, 148 struct TALER_TESTING_Interpreter *is) 149 { 150 struct TALER_TESTING_Command pay[] = { 151 /** 152 * Move money to the exchange's bank account. 153 */ 154 cmd_transfer_to_exchange ( 155 "create-reserve-1", 156 "EUR:10.02"), 157 /** 158 * Make a reserve exist, according to the previous transfer. 159 */ 160 TALER_TESTING_cmd_exec_wirewatch ( 161 "wirewatch-1", 162 CONFIG_FILE), 163 TALER_TESTING_cmd_check_bank_admin_transfer ( 164 "check_bank_transfer-2", 165 "EUR:10.02", 166 payer_payto, 167 exchange_payto, 168 "create-reserve-1"), 169 TALER_TESTING_cmd_withdraw_amount ( 170 "withdraw-coin-1", 171 "create-reserve-1", 172 "EUR:5", 173 0, 174 MHD_HTTP_OK), 175 TALER_TESTING_cmd_withdraw_amount ( 176 "withdraw-coin-2", 177 "create-reserve-1", 178 "EUR:5", 179 0, 180 MHD_HTTP_OK), 181 TALER_TESTING_cmd_merchant_get_orders ( 182 "get-orders-empty", 183 merchant_url, 184 MHD_HTTP_OK, 185 NULL), 186 /** 187 * Check the reserve is depleted. 188 */ 189 TALER_TESTING_cmd_status ( 190 "withdraw-status-1", 191 "create-reserve-1", 192 "EUR:0", 193 MHD_HTTP_OK), 194 195 /* KYC: we don't even know the legitimization UUID yet */ 196 TALER_TESTING_cmd_merchant_kyc_get ( 197 "kyc-pending-early", 198 merchant_url, 199 NULL, 200 NULL, 201 EXCHANGE_URL, 202 TALER_EXCHANGE_KLPT_NONE, 203 MHD_HTTP_OK, 204 true), 205 /* now we get the legi UUID by running taler-merchant-depositcheck */ 206 TALER_TESTING_cmd_depositcheck ( 207 "deposit-check", 208 CONFIG_FILE), 209 210 TALER_TESTING_cmd_merchant_get_instance ( 211 "get-default-instance", 212 merchant_url, 213 NULL, 214 MHD_HTTP_OK, 215 "instance-create-default-setup"), 216 TALER_TESTING_cmd_admin_add_kycauth ( 217 "merchant-kyc-auth-transfer", 218 "EUR:0.01", 219 &cred.ba, 220 merchant_payto, 221 "get-default-instance"), 222 CMD_EXEC_WIREWATCH ( 223 "import-kyc-account-withdraw"), 224 225 TALER_TESTING_cmd_merchant_kyc_get ( 226 "kyc-auth-done-check", 227 merchant_url, 228 NULL, /* admin instance */ 229 "instance-create-default-account", /* h_wire_ref: which account to query */ 230 EXCHANGE_URL, 231 TALER_EXCHANGE_KLPT_KYC_AUTH_TRANSFER, 232 MHD_HTTP_OK, 233 true), 234 235 236 TALER_TESTING_cmd_merchant_post_orders2 ( 237 "create-proposal-1", 238 cred.cfg, 239 merchant_url, 240 MHD_HTTP_OK, 241 "1", /* order ID */ 242 GNUNET_TIME_UNIT_ZERO_TS, 243 GNUNET_TIME_UNIT_FOREVER_TS, 244 true, 245 "EUR:5.0", 246 "x-taler-bank", 247 "", 248 "", 249 NULL), 250 TALER_TESTING_cmd_merchant_claim_order ( 251 "reclaim-1", 252 merchant_url, 253 MHD_HTTP_OK, 254 "create-proposal-1", 255 NULL), 256 257 TALER_TESTING_cmd_merchant_pay_order ( 258 "deposit-simple", 259 merchant_url, 260 MHD_HTTP_OK, 261 "create-proposal-1", 262 "withdraw-coin-1", 263 "EUR:5", 264 "EUR:4.99", 265 "session-0"), 266 TALER_TESTING_cmd_merchant_post_orders_paid ( 267 "verify-order-1-paid", 268 merchant_url, 269 "deposit-simple", 270 "session-1", 271 MHD_HTTP_OK), 272 TALER_TESTING_cmd_check_bank_empty ( 273 "check_bank_empty-1"), 274 CMD_EXEC_AGGREGATOR ( 275 "run-aggregator"), 276 /* KYC: hence nothing happened at the bank yet: */ 277 TALER_TESTING_cmd_check_bank_empty ( 278 "check_bank_empty-2"), 279 TALER_TESTING_cmd_merchant_kyc_get ( 280 "kyc-pending", 281 merchant_url, 282 NULL, /* admin instance */ 283 "instance-create-default-account", /* h_wire_ref: which account to query */ 284 EXCHANGE_URL, 285 TALER_EXCHANGE_KLPT_KYC_AUTH_TRANSFER, 286 MHD_HTTP_OK, 287 true), 288 TALER_TESTING_cmd_get_kyc_info ( 289 "get-kyc-info-deposit", 290 "kyc-pending", 291 MHD_HTTP_OK), 292 TALER_TESTING_cmd_post_kyc_start ( 293 "start-kyc-process-withdraw", 294 "get-kyc-info-deposit", 295 0, 296 MHD_HTTP_OK), 297 TALER_TESTING_cmd_proof_kyc_oauth2 ( 298 "kyc-do", 299 "kyc-pending", 300 "test-oauth2", 301 "pass", 302 MHD_HTTP_SEE_OTHER), 303 TALER_TESTING_cmd_sleep ( 304 "Wait for wire transfer deadline", 305 3), 306 CMD_EXEC_AGGREGATOR ("run-aggregator"), 307 TALER_TESTING_cmd_check_bank_transfer ( 308 "check_bank_transfer-498c", 309 EXCHANGE_URL, 310 "EUR:4.98", 311 exchange_payto, 312 merchant_payto), 313 TALER_TESTING_cmd_merchant_post_transfer ( 314 "post-transfer-1", 315 &cred.ba, 316 merchant_payto, 317 merchant_url, 318 "EUR:4.98", 319 MHD_HTTP_NO_CONTENT, 320 "deposit-simple", 321 NULL), 322 TALER_TESTING_cmd_run_tme ( 323 "run taler-merchant-reconciliation-1", 324 CONFIG_FILE), 325 TALER_TESTING_cmd_merchant_get_transfers ( 326 "get-transfers-1", 327 merchant_url, 328 merchant_payto, 329 MHD_HTTP_OK, 330 "post-transfer-1", 331 NULL), 332 TALER_TESTING_cmd_check_bank_empty ( 333 "check_bank_empty-3"), 334 TALER_TESTING_cmd_end () 335 }; 336 struct TALER_TESTING_Command aml[] = { 337 TALER_TESTING_cmd_set_officer ( 338 "aml-officer", 339 NULL, 340 "Ernest&Young", 341 true, 342 false), 343 cmd_transfer_to_exchange ( 344 "create-reserve-big", 345 "EUR:100.02"), 346 TALER_TESTING_cmd_exec_wirewatch ( 347 "wirewatch-big", 348 CONFIG_FILE), 349 TALER_TESTING_cmd_sleep ( 350 "sleep to de-collide AML timestamps", 351 1), 352 TALER_TESTING_cmd_take_aml_decision ( 353 "freeze", 354 "aml-officer", 355 "post-transfer-1", 356 true /* keep investigating */, 357 GNUNET_TIME_UNIT_HOURS /* expiration */, 358 NULL /* successor measure: default */, 359 "{\"rules\":" 360 "[" 361 " {" 362 " \"timeframe\":{\"d_us\":3600000000}" 363 " ,\"threshold\":\"EUR:1\"" 364 " ,\"operation_type\":\"WITHDRAW\"" 365 " ,\"verboten\":true" 366 " }" 367 " ,{" 368 " \"timeframe\":{\"d_us\":3600000000}" 369 " ,\"threshold\":\"EUR:1\"" 370 " ,\"operation_type\":\"AGGREGATE\"" 371 " ,\"display_priority\":65536" 372 " ,\"measures\":[\"form-measure\"]" 373 " ,\"verboten\":false" 374 " }" 375 "]" /* end rules */ 376 ",\"new_measure\":\"form-measure\"" 377 ",\"custom_measures\":" 378 " {" 379 " \"form-measure\":" 380 " {" 381 " \"check_name\":\"test-form\"" 382 " ,\"prog_name\":\"test-form-check\"" 383 " }" 384 " }" /* end custom measures */ 385 "}", 386 "{}" /* properties */, 387 "suspicious", 388 MHD_HTTP_NO_CONTENT), 389 TALER_TESTING_cmd_check_bank_admin_transfer ( 390 "check_bank_transfer-big", 391 "EUR:100.02", 392 payer_payto, 393 exchange_payto, 394 "create-reserve-big"), 395 TALER_TESTING_cmd_withdraw_amount ( 396 "withdraw-coin-aml", 397 "create-reserve-big", 398 "EUR:5", 399 0, 400 MHD_HTTP_OK), 401 TALER_TESTING_cmd_merchant_post_orders2 ( 402 "create-proposal-aml", 403 cred.cfg, 404 merchant_url, 405 MHD_HTTP_OK, 406 "10-aml", /* order ID */ 407 GNUNET_TIME_UNIT_ZERO_TS, 408 GNUNET_TIME_UNIT_FOREVER_TS, 409 true, 410 "EUR:5.0", 411 "x-taler-bank", 412 "", 413 "", 414 NULL), 415 TALER_TESTING_cmd_merchant_claim_order ( 416 "reclaim-aml", 417 merchant_url, 418 MHD_HTTP_OK, 419 "create-proposal-aml", 420 NULL), 421 TALER_TESTING_cmd_merchant_pay_order ( 422 "deposit-simple", 423 merchant_url, 424 MHD_HTTP_OK, 425 "create-proposal-aml", 426 "withdraw-coin-aml", 427 "EUR:5", 428 "EUR:4.99", 429 "session-aml"), 430 TALER_TESTING_cmd_merchant_post_orders_paid ( 431 "verify-order-aml-paid", 432 merchant_url, 433 "deposit-simple", 434 "session-aml", 435 MHD_HTTP_OK), 436 TALER_TESTING_cmd_check_bank_empty ( 437 "check_bank_empty-aml-1"), 438 TALER_TESTING_cmd_sleep ( 439 "Wait for wire transfer deadline", 440 3), 441 CMD_EXEC_AGGREGATOR ("run-aggregator-aml-frozen"), 442 /* AML-frozen: hence nothing happened at the bank yet: */ 443 TALER_TESTING_cmd_check_bank_empty ( 444 "check_bank_empty-aml-2"), 445 /* Now we should get a status of KYC required */ 446 TALER_TESTING_cmd_merchant_kyc_get ( 447 "aml-frozen-kyc-required", 448 merchant_url, 449 NULL, /* no instance ID */ 450 NULL, /* no wire ref */ 451 EXCHANGE_URL, 452 TALER_EXCHANGE_KLPT_KYC_AUTH_TRANSFER, 453 MHD_HTTP_OK, 454 true), 455 TALER_TESTING_cmd_sleep ( 456 "sleep to de-collide AML timestamps", 457 1), 458 TALER_TESTING_cmd_take_aml_decision ( 459 "unfreeze", 460 "aml-officer", 461 "post-transfer-1", 462 true /* keep investigating */, 463 GNUNET_TIME_UNIT_HOURS /* expiration */, 464 NULL /* new measure: none */, 465 "{\"rules\":[" 466 "{\"timeframe\":{\"d_us\":3600000000}," 467 " \"threshold\":\"EUR:100\"," 468 " \"operation_type\":\"WITHDRAW\"," 469 " \"verboten\":true" 470 "}" 471 "]}" /* new rules */, 472 "{}" /* properties */, 473 "fine", 474 MHD_HTTP_NO_CONTENT), 475 TALER_TESTING_cmd_merchant_kyc_get ( 476 "aml-unfrozen", 477 merchant_url, 478 NULL, /* no instance ID */ 479 NULL, /* no wire ref */ 480 EXCHANGE_URL, 481 TALER_EXCHANGE_KLPT_KYC_OK, 482 MHD_HTTP_OK, 483 true), 484 CMD_EXEC_AGGREGATOR ("run-aggregator-aml-normal"), 485 TALER_TESTING_cmd_check_bank_transfer ( 486 "check_bank_transfer-498c-post-unfreeze", 487 EXCHANGE_URL, 488 "EUR:4.98", 489 exchange_payto, 490 merchant_payto), 491 TALER_TESTING_cmd_merchant_post_transfer ( 492 "post-transfer-aml", 493 &cred.ba, 494 merchant_payto, 495 merchant_url, 496 "EUR:4.98", 497 MHD_HTTP_NO_CONTENT, 498 "deposit-simple", 499 NULL), 500 TALER_TESTING_cmd_run_tme ( 501 "run taler-merchant-reconciliation-2-aml", 502 CONFIG_FILE), 503 TALER_TESTING_cmd_merchant_get_transfers ( 504 "get-transfers-aml", 505 merchant_url, 506 merchant_payto, 507 MHD_HTTP_OK, 508 "post-transfer-1", 509 "post-transfer-aml", 510 NULL), 511 TALER_TESTING_cmd_end () 512 }; /* end of aml batch */ 513 514 struct TALER_TESTING_Command commands[] = { 515 /* general setup */ 516 TALER_TESTING_cmd_run_fakebank ( 517 "run-fakebank", 518 cred.cfg, 519 "exchange-account-exchange"), 520 TALER_TESTING_cmd_system_start ( 521 "start-taler", 522 CONFIG_FILE, 523 "-ema", 524 "-u", "exchange-account-exchange", 525 "-r", "merchant-exchange-test", 526 NULL), 527 TALER_TESTING_cmd_get_exchange ( 528 "get-exchange", 529 cred.cfg, 530 NULL, 531 true, 532 true), 533 TALER_TESTING_cmd_oauth_with_birthdate ( 534 "start-oauth-service", 535 "2005-00-00", 536 6666), 537 TALER_TESTING_cmd_merchant_post_instances ( 538 "instance-create-default-setup", 539 merchant_url, 540 "admin", 541 MHD_HTTP_NO_CONTENT), 542 TALER_TESTING_cmd_merchant_post_account ( 543 "instance-create-default-account", 544 merchant_url, 545 merchant_payto, 546 NULL, NULL, 547 MHD_HTTP_OK), 548 TALER_TESTING_cmd_batch ("pay", 549 pay), 550 TALER_TESTING_cmd_batch ("aml", 551 aml), 552 TALER_TESTING_cmd_end () 553 }; 554 555 TALER_TESTING_run (is, 556 commands); 557 } 558 559 560 int 561 main (int argc, 562 char *const *argv) 563 { 564 payer_payto.full_payto = 565 (char *) "payto://x-taler-bank/localhost/" USER_ACCOUNT_NAME 566 "?receiver-name=" USER_ACCOUNT_NAME; 567 exchange_payto.full_payto = 568 (char *) "payto://x-taler-bank/localhost/" EXCHANGE_ACCOUNT_NAME 569 "?receiver-name=" EXCHANGE_ACCOUNT_NAME; 570 merchant_payto.full_payto = 571 (char *) "payto://x-taler-bank/localhost/" MERCHANT_ACCOUNT_NAME 572 "?receiver-name=" MERCHANT_ACCOUNT_NAME; 573 merchant_url = "http://localhost:8080/"; 574 GNUNET_asprintf (&merchant_url_i1a, 575 "%sinstances/i1a/", 576 merchant_url); 577 return TALER_TESTING_main (argv, 578 "INFO", 579 CONFIG_FILE, 580 "exchange-account-exchange", 581 TALER_TESTING_BS_FAKEBANK, 582 &cred, 583 &run, 584 NULL); 585 } 586 587 588 /* end of test_kyc_api.c */