exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

test_kyc_oauth2_forms.c (5374B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2026 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 testing/test_kyc_oauth2_forms.c
     21  * @brief testcase for an OAuth 2.0 KYC provider whose converter
     22  *        returns several attribute sets, one per form
     23  *
     24  * The converter (taler-exchange-kyc-oauth2-test-forms-converter.sh)
     25  * returns two sets.  The AML program of the measure
     26  * (taler-exchange-helper-measure-test-forms) raises the limits only if
     27  * the first set is the account's current attributes and the KYC
     28  * history lists both sets in their order; otherwise the account is
     29  * frozen.  So the withdrawal after the KYC process succeeds only if the
     30  * exchange stored both sets as it should.
     31  */
     32 #include "taler/taler_util.h"
     33 #include "taler/taler_json_lib.h"
     34 #include <gnunet/gnunet_util_lib.h>
     35 #include <microhttpd.h>
     36 #include "taler/taler_bank_service.h"
     37 #include "taler/taler_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_oauth2_forms.conf"
     45 
     46 /**
     47  * Our credentials.
     48  */
     49 static struct TALER_TESTING_Credentials cred;
     50 
     51 
     52 /**
     53  * Execute the taler-exchange-wirewatch command with
     54  * our configuration file.
     55  *
     56  * @param label label to use for the command.
     57  */
     58 #define CMD_EXEC_WIREWATCH(label)           \
     59         TALER_TESTING_cmd_exec_wirewatch2 ( \
     60           label,                            \
     61           CONFIG_FILE,                      \
     62           "exchange-account-2")
     63 
     64 /**
     65  * Run wire transfer of funds from some user's account to the
     66  * exchange.
     67  *
     68  * @param label label to use for the command.
     69  * @param amount amount to transfer, i.e. "EUR:1"
     70  */
     71 #define CMD_TRANSFER_TO_EXCHANGE(label,amount) \
     72         TALER_TESTING_cmd_admin_add_incoming ( \
     73           label,                               \
     74           amount,                              \
     75           &cred.ba,                            \
     76           cred.user42_payto)
     77 
     78 
     79 /**
     80  * Main function that will tell the interpreter what commands to
     81  * run.
     82  *
     83  * @param cls closure
     84  * @param is interpreter state
     85  */
     86 static void
     87 run (void *cls,
     88      struct TALER_TESTING_Interpreter *is)
     89 {
     90   struct TALER_TESTING_Command withdraw_kyc[] = {
     91     CMD_TRANSFER_TO_EXCHANGE (
     92       "create-reserve",
     93       "EUR:15.02"),
     94     TALER_TESTING_cmd_check_bank_admin_transfer (
     95       "check-create-reserve",
     96       "EUR:15.02",
     97       cred.user42_payto,
     98       cred.exchange_payto,
     99       "create-reserve"),
    100     CMD_EXEC_WIREWATCH ("wirewatch"),
    101     TALER_TESTING_cmd_withdraw_amount (
    102       "withdraw-lacking-kyc",
    103       "create-reserve",
    104       "EUR:10",
    105       0,    /* age restriction off */
    106       MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS),
    107     TALER_TESTING_cmd_admin_add_kycauth (
    108       "setup-account-key",
    109       "EUR:0.01",
    110       &cred.ba,
    111       cred.user42_payto,
    112       NULL /* create new key */),
    113     CMD_EXEC_WIREWATCH ("import-kyc-account"),
    114     TALER_TESTING_cmd_check_kyc_get (
    115       "check-kyc",
    116       "withdraw-lacking-kyc",
    117       "setup-account-key",
    118       TALER_EXCHANGE_KLPT_KYC_AUTH_TRANSFER,
    119       MHD_HTTP_ACCEPTED),
    120     TALER_TESTING_cmd_get_kyc_info (
    121       "get-kyc-info",
    122       "check-kyc",
    123       MHD_HTTP_OK),
    124     TALER_TESTING_cmd_post_kyc_start (
    125       "start-kyc-process",
    126       "get-kyc-info",
    127       0,
    128       MHD_HTTP_OK),
    129     /* An adult: the birthday does not restrict the withdrawal. */
    130     TALER_TESTING_cmd_oauth_with_birthdate (
    131       "start-oauth-service",
    132       "1980-00-00",
    133       6666),
    134     /* The converter returns two attribute sets. */
    135     TALER_TESTING_cmd_proof_kyc_oauth2 (
    136       "proof-kyc-oauth2-forms",
    137       "start-kyc-process",
    138       "test-oauth2",
    139       "pass",
    140       MHD_HTTP_SEE_OTHER),
    141     /* The AML program saw both sets and raised the limits. */
    142     TALER_TESTING_cmd_withdraw_amount (
    143       "withdraw-with-kyc",
    144       "create-reserve",
    145       "EUR:10",
    146       0,    /* age restriction off */
    147       MHD_HTTP_OK),
    148     TALER_TESTING_cmd_end ()
    149   };
    150   struct TALER_TESTING_Command commands[] = {
    151     TALER_TESTING_cmd_run_fakebank (
    152       "run-fakebank",
    153       cred.cfg,
    154       "exchange-account-2"),
    155     TALER_TESTING_cmd_system_start (
    156       "start-taler",
    157       CONFIG_FILE,
    158       "-e",
    159       NULL),
    160     TALER_TESTING_cmd_get_exchange (
    161       "get-exchange",
    162       cred.cfg,
    163       NULL,
    164       true,
    165       true),
    166     TALER_TESTING_cmd_batch (
    167       "withdraw-kyc",
    168       withdraw_kyc),
    169     TALER_TESTING_cmd_end ()
    170   };
    171 
    172   (void) cls;
    173   TALER_TESTING_run (is,
    174                      commands);
    175 }
    176 
    177 
    178 int
    179 main (int argc,
    180       char *const *argv)
    181 {
    182   (void) argc;
    183   return TALER_TESTING_main (
    184     argv,
    185     "INFO",
    186     CONFIG_FILE,
    187     "exchange-account-2",
    188     TALER_TESTING_BS_FAKEBANK,
    189     &cred,
    190     &run,
    191     NULL);
    192 }
    193 
    194 
    195 /* end of test_kyc_oauth2_forms.c */