merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

test_kyc_api.c (16062B)


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