LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_kyc_check_get.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 62.3 % 77 48
Test Date: 2026-04-14 15:39:31 Functions: 100.0 % 5 5

            Line data    Source code
       1              : /*
       2              :   This file is part of TALER
       3              :   Copyright (C) 2021-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              : /**
      21              :  * @file testing/testing_api_cmd_kyc_check_get.c
      22              :  * @brief Implement the testing CMDs for the /kyc_check/ GET operations.
      23              :  * @author Christian Grothoff
      24              :  */
      25              : #include "taler/taler_json_lib.h"
      26              : #include <gnunet/gnunet_curl_lib.h>
      27              : 
      28              : /**
      29              :  * State for a "track transaction" CMD.
      30              :  */
      31              : struct KycCheckGetState;
      32              : 
      33              : #define TALER_EXCHANGE_GET_KYC_CHECK_RESULT_CLOSURE \
      34              :         struct KycCheckGetState
      35              : #include "taler/exchange/get-kyc-check-H_NORMALIZED_PAYTO.h"
      36              : #include "taler/taler_testing_lib.h"
      37              : 
      38              : /**
      39              :  * State for a "track transaction" CMD.
      40              :  */
      41              : struct KycCheckGetState
      42              : {
      43              : 
      44              :   /**
      45              :    * Set to the KYC URL *if* the exchange replied with
      46              :    * a request for KYC (#MHD_HTTP_ACCEPTED or #MHD_HTTP_OK).
      47              :    */
      48              :   struct TALER_AccountAccessTokenP access_token;
      49              : 
      50              :   /**
      51              :    * Handle to the "track transaction" pending operation.
      52              :    */
      53              :   struct TALER_EXCHANGE_GetKycCheckHandle *kwh;
      54              : 
      55              :   /**
      56              :    * Interpreter state.
      57              :    */
      58              :   struct TALER_TESTING_Interpreter *is;
      59              : 
      60              :   /**
      61              :    * Command to get a reserve private key from.
      62              :    */
      63              :   const char *payment_target_reference;
      64              : 
      65              :   /**
      66              :    * Command to get an account private key from.
      67              :    */
      68              :   const char *account_reference;
      69              : 
      70              :   /**
      71              :    * Expected HTTP response code.
      72              :    */
      73              :   unsigned int expected_response_code;
      74              : 
      75              :   /**
      76              :    * What are we waiting for when long-polling?
      77              :    */
      78              :   enum TALER_EXCHANGE_KycLongPollTarget lpt;
      79              : 
      80              : };
      81              : 
      82              : 
      83              : /**
      84              :  * Handle response to the command.
      85              :  *
      86              :  * @param kcg our state
      87              :  * @param ks GET KYC status response details
      88              :  */
      89              : static void
      90           14 : check_kyc_cb (
      91              :   TALER_EXCHANGE_GET_KYC_CHECK_RESULT_CLOSURE *kcg,
      92              :   const struct TALER_EXCHANGE_GetKycCheckResponse *ks)
      93              : {
      94           14 :   struct TALER_TESTING_Interpreter *is = kcg->is;
      95              : 
      96           14 :   kcg->kwh = NULL;
      97           14 :   if (kcg->expected_response_code != ks->hr.http_status)
      98              :   {
      99            0 :     TALER_TESTING_unexpected_status (is,
     100              :                                      ks->hr.http_status,
     101              :                                      kcg->expected_response_code);
     102            0 :     return;
     103              :   }
     104           14 :   switch (ks->hr.http_status)
     105              :   {
     106            3 :   case MHD_HTTP_OK:
     107            3 :     kcg->access_token = ks->details.ok.access_token;
     108            3 :     break;
     109           11 :   case MHD_HTTP_ACCEPTED:
     110           11 :     kcg->access_token = ks->details.accepted.access_token;
     111           11 :     break;
     112            0 :   case MHD_HTTP_NO_CONTENT:
     113            0 :     break;
     114            0 :   default:
     115            0 :     GNUNET_break (0);
     116            0 :     break;
     117              :   }
     118           14 :   TALER_TESTING_interpreter_next (kcg->is);
     119              : }
     120              : 
     121              : 
     122              : /**
     123              :  * Run the command.
     124              :  *
     125              :  * @param cls closure.
     126              :  * @param cmd the command to execute.
     127              :  * @param is the interpreter state.
     128              :  */
     129              : static void
     130           14 : check_kyc_run (void *cls,
     131              :                const struct TALER_TESTING_Command *cmd,
     132              :                struct TALER_TESTING_Interpreter *is)
     133              : {
     134           14 :   struct KycCheckGetState *kcg = cls;
     135              :   const struct TALER_TESTING_Command *res_cmd;
     136              :   const struct TALER_TESTING_Command *acc_cmd;
     137              :   const struct TALER_NormalizedPaytoHashP *h_payto;
     138              :   const union TALER_AccountPrivateKeyP *account_priv;
     139              : 
     140              :   (void) cmd;
     141           14 :   kcg->is = is;
     142           14 :   res_cmd = TALER_TESTING_interpreter_lookup_command (
     143              :     kcg->is,
     144              :     kcg->payment_target_reference);
     145           14 :   if (NULL == res_cmd)
     146              :   {
     147            0 :     GNUNET_break (0);
     148            0 :     TALER_TESTING_interpreter_fail (kcg->is);
     149            0 :     return;
     150              :   }
     151           14 :   acc_cmd = TALER_TESTING_interpreter_lookup_command (
     152              :     kcg->is,
     153              :     kcg->account_reference);
     154           14 :   if (NULL == acc_cmd)
     155              :   {
     156            0 :     GNUNET_break (0);
     157            0 :     TALER_TESTING_interpreter_fail (kcg->is);
     158            0 :     return;
     159              :   }
     160           14 :   if (GNUNET_OK !=
     161           14 :       TALER_TESTING_get_trait_h_normalized_payto (
     162              :         res_cmd,
     163              :         &h_payto))
     164              :   {
     165            0 :     GNUNET_break (0);
     166            0 :     TALER_TESTING_interpreter_fail (kcg->is);
     167            0 :     return;
     168              :   }
     169           14 :   if (GNUNET_OK !=
     170           14 :       TALER_TESTING_get_trait_account_priv (acc_cmd,
     171              :                                             &account_priv))
     172              :   {
     173            0 :     GNUNET_break (0);
     174            0 :     TALER_TESTING_interpreter_fail (kcg->is);
     175            0 :     return;
     176              :   }
     177           14 :   if (0 == h_payto)
     178              :   {
     179            0 :     GNUNET_break (0);
     180            0 :     TALER_TESTING_interpreter_fail (kcg->is);
     181            0 :     return;
     182              :   }
     183           14 :   kcg->kwh = TALER_EXCHANGE_get_kyc_check_create (
     184              :     TALER_TESTING_interpreter_get_context (is),
     185              :     TALER_TESTING_get_exchange_url (is),
     186              :     h_payto,
     187              :     account_priv);
     188           14 :   GNUNET_assert (NULL != kcg->kwh);
     189           14 :   if (TALER_EXCHANGE_KLPT_NONE != kcg->lpt)
     190           14 :     TALER_EXCHANGE_get_kyc_check_set_options (
     191              :       kcg->kwh,
     192              :       TALER_EXCHANGE_get_kyc_check_option_lpt (kcg->lpt),
     193              :       TALER_EXCHANGE_get_kyc_check_option_timeout (GNUNET_TIME_UNIT_MINUTES));
     194              :   {
     195              :     enum TALER_ErrorCode ec;
     196              : 
     197           14 :     ec = TALER_EXCHANGE_get_kyc_check_start (kcg->kwh,
     198              :                                              &check_kyc_cb,
     199              :                                              kcg);
     200           14 :     if (TALER_EC_NONE != ec)
     201              :     {
     202            0 :       GNUNET_break (0);
     203            0 :       kcg->kwh = NULL;
     204            0 :       TALER_TESTING_interpreter_fail (kcg->is);
     205            0 :       return;
     206              :     }
     207              :   }
     208              : }
     209              : 
     210              : 
     211              : /**
     212              :  * Cleanup the state from a "track transaction" CMD, and possibly
     213              :  * cancel a operation thereof.
     214              :  *
     215              :  * @param cls closure.
     216              :  * @param cmd the command which is being cleaned up.
     217              :  */
     218              : static void
     219           14 : check_kyc_cleanup (void *cls,
     220              :                    const struct TALER_TESTING_Command *cmd)
     221              : {
     222           14 :   struct KycCheckGetState *kcg = cls;
     223              : 
     224           14 :   if (NULL != kcg->kwh)
     225              :   {
     226            0 :     TALER_TESTING_command_incomplete (kcg->is,
     227              :                                       cmd->label);
     228            0 :     TALER_EXCHANGE_get_kyc_check_cancel (kcg->kwh);
     229            0 :     kcg->kwh = NULL;
     230              :   }
     231           14 :   GNUNET_free (kcg);
     232           14 : }
     233              : 
     234              : 
     235              : /**
     236              :  * Offer internal data from a "check KYC" CMD.
     237              :  *
     238              :  * @param cls closure.
     239              :  * @param[out] ret result (could be anything).
     240              :  * @param trait name of the trait.
     241              :  * @param index index number of the object to offer.
     242              :  * @return #GNUNET_OK on success.
     243              :  */
     244              : static enum GNUNET_GenericReturnValue
     245           36 : check_kyc_traits (void *cls,
     246              :                   const void **ret,
     247              :                   const char *trait,
     248              :                   unsigned int index)
     249              : {
     250           36 :   struct KycCheckGetState *kcg = cls;
     251              :   struct TALER_TESTING_Trait traits[] = {
     252           36 :     TALER_TESTING_make_trait_account_access_token (&kcg->access_token),
     253           36 :     TALER_TESTING_trait_end ()
     254              :   };
     255              : 
     256           36 :   return TALER_TESTING_get_trait (traits,
     257              :                                   ret,
     258              :                                   trait,
     259              :                                   index);
     260              : }
     261              : 
     262              : 
     263              : struct TALER_TESTING_Command
     264           14 : TALER_TESTING_cmd_check_kyc_get (
     265              :   const char *label,
     266              :   const char *payment_target_reference,
     267              :   const char *account_reference,
     268              :   enum TALER_EXCHANGE_KycLongPollTarget lpt,
     269              :   unsigned int expected_response_code)
     270              : {
     271              :   struct KycCheckGetState *kcg;
     272              : 
     273           14 :   kcg = GNUNET_new (struct KycCheckGetState);
     274           14 :   kcg->payment_target_reference = payment_target_reference;
     275           14 :   kcg->account_reference = account_reference;
     276           14 :   kcg->expected_response_code = expected_response_code;
     277           14 :   kcg->lpt = lpt;
     278              :   {
     279           14 :     struct TALER_TESTING_Command cmd = {
     280              :       .cls = kcg,
     281              :       .label = label,
     282              :       .run = &check_kyc_run,
     283              :       .cleanup = &check_kyc_cleanup,
     284              :       .traits = &check_kyc_traits
     285              :     };
     286              : 
     287           14 :     return cmd;
     288              :   }
     289              : }
     290              : 
     291              : 
     292              : /* end of testing_api_cmd_kyc_check_get.c */
        

Generated by: LCOV version 2.0-1