Line data Source code
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 2 : cmd_transfer_to_exchange (const char *label,
131 : const char *amount)
132 : {
133 2 : 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 1 : 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 1 : 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 1 : TALER_TESTING_cmd_exec_wirewatch (
161 : "wirewatch-1",
162 : CONFIG_FILE),
163 1 : 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 1 : TALER_TESTING_cmd_withdraw_amount (
170 : "withdraw-coin-1",
171 : "create-reserve-1",
172 : "EUR:5",
173 : 0,
174 : MHD_HTTP_OK),
175 1 : TALER_TESTING_cmd_withdraw_amount (
176 : "withdraw-coin-2",
177 : "create-reserve-1",
178 : "EUR:5",
179 : 0,
180 : MHD_HTTP_OK),
181 1 : 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 1 : 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 1 : 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 1 : TALER_TESTING_cmd_depositcheck (
207 : "deposit-check",
208 : CONFIG_FILE),
209 :
210 1 : 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 1 : 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 1 : CMD_EXEC_WIREWATCH (
223 : "import-kyc-account-withdraw"),
224 :
225 1 : 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 1 : TALER_TESTING_cmd_merchant_post_orders2 (
237 : "create-proposal-1",
238 1 : cred.cfg,
239 : merchant_url,
240 : MHD_HTTP_OK,
241 : "1", /* order ID */
242 1 : GNUNET_TIME_UNIT_ZERO_TS,
243 1 : GNUNET_TIME_UNIT_FOREVER_TS,
244 : true,
245 : "EUR:5.0",
246 : "x-taler-bank",
247 : "",
248 : "",
249 : NULL),
250 1 : TALER_TESTING_cmd_merchant_claim_order (
251 : "reclaim-1",
252 : merchant_url,
253 : MHD_HTTP_OK,
254 : "create-proposal-1",
255 : NULL),
256 :
257 1 : 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 1 : 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 1 : TALER_TESTING_cmd_check_bank_empty (
273 : "check_bank_empty-1"),
274 1 : CMD_EXEC_AGGREGATOR (
275 : "run-aggregator"),
276 : /* KYC: hence nothing happened at the bank yet: */
277 1 : TALER_TESTING_cmd_check_bank_empty (
278 : "check_bank_empty-2"),
279 1 : 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 1 : TALER_TESTING_cmd_get_kyc_info (
289 : "get-kyc-info-deposit",
290 : "kyc-pending",
291 : MHD_HTTP_OK),
292 1 : TALER_TESTING_cmd_post_kyc_start (
293 : "start-kyc-process-withdraw",
294 : "get-kyc-info-deposit",
295 : 0,
296 : MHD_HTTP_OK),
297 1 : TALER_TESTING_cmd_proof_kyc_oauth2 (
298 : "kyc-do",
299 : "kyc-pending",
300 : "test-oauth2",
301 : "pass",
302 : MHD_HTTP_SEE_OTHER),
303 1 : CMD_EXEC_AGGREGATOR ("run-aggregator"),
304 1 : TALER_TESTING_cmd_check_bank_transfer (
305 : "check_bank_transfer-498c",
306 : EXCHANGE_URL,
307 : "EUR:4.98",
308 : exchange_payto,
309 : merchant_payto),
310 1 : TALER_TESTING_cmd_merchant_post_transfer (
311 : "post-transfer-1",
312 : &cred.ba,
313 : merchant_payto,
314 : merchant_url,
315 : "EUR:4.98",
316 : MHD_HTTP_NO_CONTENT,
317 : "deposit-simple",
318 : NULL),
319 1 : TALER_TESTING_cmd_run_tme (
320 : "run taler-merchant-reconciliation-1",
321 : CONFIG_FILE),
322 1 : TALER_TESTING_cmd_merchant_get_transfers (
323 : "get-transfers-1",
324 : merchant_url,
325 : merchant_payto,
326 : MHD_HTTP_OK,
327 : "post-transfer-1",
328 : NULL),
329 1 : TALER_TESTING_cmd_check_bank_empty (
330 : "check_bank_empty-3"),
331 1 : TALER_TESTING_cmd_end ()
332 : };
333 : struct TALER_TESTING_Command aml[] = {
334 1 : TALER_TESTING_cmd_set_officer (
335 : "aml-officer",
336 : NULL,
337 : "Ernest&Young",
338 : true,
339 : false),
340 1 : cmd_transfer_to_exchange (
341 : "create-reserve-big",
342 : "EUR:100.02"),
343 1 : TALER_TESTING_cmd_exec_wirewatch (
344 : "wirewatch-big",
345 : CONFIG_FILE),
346 1 : TALER_TESTING_cmd_sleep (
347 : "sleep to de-collide AML timestamps",
348 : 1),
349 1 : TALER_TESTING_cmd_take_aml_decision (
350 : "freeze",
351 : "aml-officer",
352 : "post-transfer-1",
353 : true /* keep investigating */,
354 : GNUNET_TIME_UNIT_HOURS /* expiration */,
355 : NULL /* successor measure: default */,
356 : "{\"rules\":"
357 : "["
358 : " {"
359 : " \"timeframe\":{\"d_us\":3600000000}"
360 : " ,\"threshold\":\"EUR:1\""
361 : " ,\"operation_type\":\"WITHDRAW\""
362 : " ,\"verboten\":true"
363 : " }"
364 : " ,{"
365 : " \"timeframe\":{\"d_us\":3600000000}"
366 : " ,\"threshold\":\"EUR:1\""
367 : " ,\"operation_type\":\"AGGREGATE\""
368 : " ,\"display_priority\":65536"
369 : " ,\"measures\":[\"form-measure\"]"
370 : " ,\"verboten\":false"
371 : " }"
372 : "]" /* end rules */
373 : ",\"new_measure\":\"form-measure\""
374 : ",\"custom_measures\":"
375 : " {"
376 : " \"form-measure\":"
377 : " {"
378 : " \"check_name\":\"test-form\""
379 : " ,\"prog_name\":\"test-form-check\""
380 : " }"
381 : " }" /* end custom measures */
382 : "}",
383 : "{}" /* properties */,
384 : "suspicious",
385 : MHD_HTTP_NO_CONTENT),
386 1 : TALER_TESTING_cmd_check_bank_admin_transfer (
387 : "check_bank_transfer-big",
388 : "EUR:100.02",
389 : payer_payto,
390 : exchange_payto,
391 : "create-reserve-big"),
392 1 : TALER_TESTING_cmd_withdraw_amount (
393 : "withdraw-coin-aml",
394 : "create-reserve-big",
395 : "EUR:5",
396 : 0,
397 : MHD_HTTP_OK),
398 1 : TALER_TESTING_cmd_merchant_post_orders2 (
399 : "create-proposal-aml",
400 1 : cred.cfg,
401 : merchant_url,
402 : MHD_HTTP_OK,
403 : "10-aml", /* order ID */
404 1 : GNUNET_TIME_UNIT_ZERO_TS,
405 1 : GNUNET_TIME_UNIT_FOREVER_TS,
406 : true,
407 : "EUR:5.0",
408 : "x-taler-bank",
409 : "",
410 : "",
411 : NULL),
412 1 : TALER_TESTING_cmd_merchant_claim_order (
413 : "reclaim-aml",
414 : merchant_url,
415 : MHD_HTTP_OK,
416 : "create-proposal-aml",
417 : NULL),
418 1 : TALER_TESTING_cmd_merchant_pay_order (
419 : "deposit-simple",
420 : merchant_url,
421 : MHD_HTTP_OK,
422 : "create-proposal-aml",
423 : "withdraw-coin-aml",
424 : "EUR:5",
425 : "EUR:4.99",
426 : "session-aml"),
427 1 : TALER_TESTING_cmd_merchant_post_orders_paid (
428 : "verify-order-aml-paid",
429 : merchant_url,
430 : "deposit-simple",
431 : "session-aml",
432 : MHD_HTTP_OK),
433 1 : TALER_TESTING_cmd_check_bank_empty (
434 : "check_bank_empty-aml-1"),
435 1 : CMD_EXEC_AGGREGATOR ("run-aggregator-aml-frozen"),
436 : /* AML-frozen: hence nothing happened at the bank yet: */
437 1 : TALER_TESTING_cmd_check_bank_empty (
438 : "check_bank_empty-aml-2"),
439 : /* Now we should get a status of KYC required */
440 1 : TALER_TESTING_cmd_merchant_kyc_get (
441 : "aml-frozen-kyc-required",
442 : merchant_url,
443 : NULL, /* no instance ID */
444 : NULL, /* no wire ref */
445 : EXCHANGE_URL,
446 : TALER_EXCHANGE_KLPT_KYC_AUTH_TRANSFER,
447 : MHD_HTTP_OK,
448 : true),
449 1 : TALER_TESTING_cmd_sleep (
450 : "sleep to de-collide AML timestamps",
451 : 1),
452 1 : TALER_TESTING_cmd_take_aml_decision (
453 : "unfreeze",
454 : "aml-officer",
455 : "post-transfer-1",
456 : true /* keep investigating */,
457 : GNUNET_TIME_UNIT_HOURS /* expiration */,
458 : NULL /* new measure: none */,
459 : "{\"rules\":["
460 : "{\"timeframe\":{\"d_us\":3600000000},"
461 : " \"threshold\":\"EUR:100\","
462 : " \"operation_type\":\"WITHDRAW\","
463 : " \"verboten\":true"
464 : "}"
465 : "]}" /* new rules */,
466 : "{}" /* properties */,
467 : "fine",
468 : MHD_HTTP_NO_CONTENT),
469 1 : TALER_TESTING_cmd_merchant_kyc_get (
470 : "aml-unfrozen",
471 : merchant_url,
472 : NULL, /* no instance ID */
473 : NULL, /* no wire ref */
474 : EXCHANGE_URL,
475 : TALER_EXCHANGE_KLPT_KYC_OK,
476 : MHD_HTTP_OK,
477 : true),
478 1 : CMD_EXEC_AGGREGATOR ("run-aggregator-aml-normal"),
479 1 : TALER_TESTING_cmd_check_bank_transfer (
480 : "check_bank_transfer-498c-post-unfreeze",
481 : EXCHANGE_URL,
482 : "EUR:4.98",
483 : exchange_payto,
484 : merchant_payto),
485 1 : TALER_TESTING_cmd_merchant_post_transfer (
486 : "post-transfer-aml",
487 : &cred.ba,
488 : merchant_payto,
489 : merchant_url,
490 : "EUR:4.98",
491 : MHD_HTTP_NO_CONTENT,
492 : "deposit-simple",
493 : NULL),
494 1 : TALER_TESTING_cmd_run_tme (
495 : "run taler-merchant-reconciliation-2-aml",
496 : CONFIG_FILE),
497 1 : TALER_TESTING_cmd_merchant_get_transfers (
498 : "get-transfers-aml",
499 : merchant_url,
500 : merchant_payto,
501 : MHD_HTTP_OK,
502 : "post-transfer-1",
503 : "post-transfer-aml",
504 : NULL),
505 1 : TALER_TESTING_cmd_end ()
506 : }; /* end of aml batch */
507 :
508 : struct TALER_TESTING_Command commands[] = {
509 : /* general setup */
510 1 : TALER_TESTING_cmd_run_fakebank (
511 : "run-fakebank",
512 1 : cred.cfg,
513 : "exchange-account-exchange"),
514 1 : TALER_TESTING_cmd_system_start (
515 : "start-taler",
516 : CONFIG_FILE,
517 : "-ema",
518 : "-u", "exchange-account-exchange",
519 : "-r", "merchant-exchange-test",
520 : NULL),
521 1 : TALER_TESTING_cmd_get_exchange (
522 : "get-exchange",
523 1 : cred.cfg,
524 : NULL,
525 : true,
526 : true),
527 1 : TALER_TESTING_cmd_oauth_with_birthdate (
528 : "start-oauth-service",
529 : "2005-00-00",
530 : 6666),
531 1 : TALER_TESTING_cmd_merchant_post_instances (
532 : "instance-create-default-setup",
533 : merchant_url,
534 : "admin",
535 : MHD_HTTP_NO_CONTENT),
536 1 : TALER_TESTING_cmd_merchant_post_account (
537 : "instance-create-default-account",
538 : merchant_url,
539 : merchant_payto,
540 : NULL, NULL,
541 : MHD_HTTP_OK),
542 1 : TALER_TESTING_cmd_batch ("pay",
543 : pay),
544 1 : TALER_TESTING_cmd_batch ("aml",
545 : aml),
546 1 : TALER_TESTING_cmd_end ()
547 : };
548 :
549 1 : TALER_TESTING_run (is,
550 : commands);
551 1 : }
552 :
553 :
554 : int
555 1 : main (int argc,
556 : char *const *argv)
557 : {
558 1 : payer_payto.full_payto =
559 : (char *) "payto://x-taler-bank/localhost/" USER_ACCOUNT_NAME
560 : "?receiver-name=" USER_ACCOUNT_NAME;
561 1 : exchange_payto.full_payto =
562 : (char *) "payto://x-taler-bank/localhost/" EXCHANGE_ACCOUNT_NAME
563 : "?receiver-name=" EXCHANGE_ACCOUNT_NAME;
564 1 : merchant_payto.full_payto =
565 : (char *) "payto://x-taler-bank/localhost/" MERCHANT_ACCOUNT_NAME
566 : "?receiver-name=" MERCHANT_ACCOUNT_NAME;
567 1 : merchant_url = "http://localhost:8080/";
568 1 : GNUNET_asprintf (&merchant_url_i1a,
569 : "%sinstances/i1a/",
570 : merchant_url);
571 1 : return TALER_TESTING_main (argv,
572 : "INFO",
573 : CONFIG_FILE,
574 : "exchange-account-exchange",
575 : TALER_TESTING_BS_FAKEBANK,
576 : &cred,
577 : &run,
578 : NULL);
579 : }
580 :
581 :
582 : /* end of test_kyc_api.c */
|