LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_post_kyc_start.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 62.9 % 62 39
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) 2024, 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_post_kyc_start.c
      22              :  * @brief Implement the testing CMDs for a POST /kyc-start operation.
      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 POST /kyc-start CMD.
      30              :  */
      31              : struct PostKycStartState;
      32              : 
      33              : #define TALER_EXCHANGE_POST_KYC_START_RESULT_CLOSURE \
      34              :         struct PostKycStartState
      35              : #include "taler/exchange/post-kyc-start-ID.h"
      36              : #include "taler/taler_testing_lib.h"
      37              : 
      38              : /**
      39              :  * State for a POST /kyc-start CMD.
      40              :  */
      41              : struct PostKycStartState
      42              : {
      43              : 
      44              :   /**
      45              :    * Command that did a GET on /kyc-info
      46              :    */
      47              :   const char *kyc_info_reference;
      48              : 
      49              :   /**
      50              :    * Index of the requirement to start.
      51              :    */
      52              :   unsigned int requirement_index;
      53              : 
      54              :   /**
      55              :    * Expected HTTP response code.
      56              :    */
      57              :   unsigned int expected_response_code;
      58              : 
      59              :   /**
      60              :    * Redirect URL returned by the request on success.
      61              :    */
      62              :   char *redirect_url;
      63              : 
      64              :   /**
      65              :    * Handle to the KYC start pending operation.
      66              :    */
      67              :   struct TALER_EXCHANGE_PostKycStartHandle *kwh;
      68              : 
      69              :   /**
      70              :    * Interpreter state.
      71              :    */
      72              :   struct TALER_TESTING_Interpreter *is;
      73              : };
      74              : 
      75              : 
      76              : /**
      77              :  * Handle response to the command.
      78              :  *
      79              :  * @param kcg our state
      80              :  * @param ks GET KYC status response details
      81              :  */
      82              : static void
      83           10 : post_kyc_start_cb (
      84              :   struct PostKycStartState *kcg,
      85              :   const struct TALER_EXCHANGE_PostKycStartResponse *ks)
      86              : {
      87           10 :   struct TALER_TESTING_Interpreter *is = kcg->is;
      88              : 
      89           10 :   kcg->kwh = NULL;
      90           10 :   if (kcg->expected_response_code != ks->hr.http_status)
      91              :   {
      92            0 :     TALER_TESTING_unexpected_status (is,
      93              :                                      ks->hr.http_status,
      94              :                                      kcg->expected_response_code);
      95            0 :     return;
      96              :   }
      97           10 :   switch (ks->hr.http_status)
      98              :   {
      99           10 :   case MHD_HTTP_OK:
     100              :     kcg->redirect_url
     101           10 :       = GNUNET_strdup (ks->details.ok.redirect_url);
     102           10 :     break;
     103            0 :   case MHD_HTTP_NO_CONTENT:
     104            0 :     break;
     105            0 :   default:
     106            0 :     GNUNET_break (0);
     107            0 :     break;
     108              :   }
     109           10 :   TALER_TESTING_interpreter_next (kcg->is);
     110              : }
     111              : 
     112              : 
     113              : /**
     114              :  * Run the command.
     115              :  *
     116              :  * @param cls closure.
     117              :  * @param cmd the command to execute.
     118              :  * @param is the interpreter state.
     119              :  */
     120              : static void
     121           10 : post_kyc_start_run (void *cls,
     122              :                     const struct TALER_TESTING_Command *cmd,
     123              :                     struct TALER_TESTING_Interpreter *is)
     124              : {
     125           10 :   struct PostKycStartState *kcg = cls;
     126              :   const struct TALER_TESTING_Command *res_cmd;
     127              :   const char *id;
     128              : 
     129              :   (void) cmd;
     130           10 :   kcg->is = is;
     131           10 :   res_cmd = TALER_TESTING_interpreter_lookup_command (
     132              :     kcg->is,
     133              :     kcg->kyc_info_reference);
     134           10 :   if (NULL == res_cmd)
     135              :   {
     136            0 :     GNUNET_break (0);
     137            0 :     TALER_TESTING_interpreter_fail (kcg->is);
     138            0 :     return;
     139              :   }
     140           10 :   if (GNUNET_OK !=
     141           10 :       TALER_TESTING_get_trait_kyc_id (
     142              :         res_cmd,
     143              :         kcg->requirement_index,
     144              :         &id))
     145              :   {
     146            0 :     GNUNET_break (0);
     147            0 :     TALER_TESTING_interpreter_fail (kcg->is);
     148            0 :     return;
     149              :   }
     150           10 :   if (NULL == id)
     151              :   {
     152            0 :     GNUNET_break (0);
     153            0 :     TALER_TESTING_interpreter_fail (kcg->is);
     154            0 :     return;
     155              :   }
     156           10 :   kcg->kwh = TALER_EXCHANGE_post_kyc_start_create (
     157              :     TALER_TESTING_interpreter_get_context (is),
     158              :     TALER_TESTING_get_exchange_url (is),
     159              :     id);
     160           10 :   GNUNET_assert (NULL != kcg->kwh);
     161              :   {
     162              :     enum TALER_ErrorCode ec;
     163              : 
     164           10 :     ec = TALER_EXCHANGE_post_kyc_start_start (kcg->kwh,
     165              :                                               &post_kyc_start_cb,
     166              :                                               kcg);
     167           10 :     if (TALER_EC_NONE != ec)
     168              :     {
     169            0 :       GNUNET_break (0);
     170            0 :       kcg->kwh = NULL;
     171            0 :       TALER_TESTING_interpreter_fail (kcg->is);
     172            0 :       return;
     173              :     }
     174              :   }
     175              : }
     176              : 
     177              : 
     178              : /**
     179              :  * Cleanup the state from a "track transaction" CMD, and possibly
     180              :  * cancel a operation thereof.
     181              :  *
     182              :  * @param cls closure.
     183              :  * @param cmd the command which is being cleaned up.
     184              :  */
     185              : static void
     186           10 : post_kyc_start_cleanup (void *cls,
     187              :                         const struct TALER_TESTING_Command *cmd)
     188              : {
     189           10 :   struct PostKycStartState *kcg = cls;
     190              : 
     191           10 :   if (NULL != kcg->kwh)
     192              :   {
     193            0 :     TALER_TESTING_command_incomplete (kcg->is,
     194              :                                       cmd->label);
     195            0 :     TALER_EXCHANGE_post_kyc_start_cancel (kcg->kwh);
     196            0 :     kcg->kwh = NULL;
     197              :   }
     198           10 :   GNUNET_free (kcg->redirect_url);
     199           10 :   GNUNET_free (kcg);
     200           10 : }
     201              : 
     202              : 
     203              : /**
     204              :  * Offer internal data from a "check KYC" CMD.
     205              :  *
     206              :  * @param cls closure.
     207              :  * @param[out] ret result (could be anything).
     208              :  * @param trait name of the trait.
     209              :  * @param index index number of the object to offer.
     210              :  * @return #GNUNET_OK on success.
     211              :  */
     212              : static enum GNUNET_GenericReturnValue
     213           21 : post_kyc_start_traits (void *cls,
     214              :                        const void **ret,
     215              :                        const char *trait,
     216              :                        unsigned int index)
     217              : {
     218           21 :   struct PostKycStartState *kcg = cls;
     219              :   struct TALER_TESTING_Trait traits[] = {
     220           21 :     TALER_TESTING_make_trait_kyc_url (kcg->redirect_url),
     221           21 :     TALER_TESTING_trait_end ()
     222              :   };
     223              : 
     224           21 :   return TALER_TESTING_get_trait (traits,
     225              :                                   ret,
     226              :                                   trait,
     227              :                                   index);
     228              : }
     229              : 
     230              : 
     231              : struct TALER_TESTING_Command
     232           10 : TALER_TESTING_cmd_post_kyc_start (
     233              :   const char *label,
     234              :   const char *kyc_info_reference,
     235              :   unsigned int requirement_index,
     236              :   unsigned int expected_response_code)
     237              : {
     238              :   struct PostKycStartState *kcg;
     239              : 
     240           10 :   kcg = GNUNET_new (struct PostKycStartState);
     241           10 :   kcg->kyc_info_reference = kyc_info_reference;
     242           10 :   kcg->requirement_index = requirement_index;
     243           10 :   kcg->expected_response_code = expected_response_code;
     244              :   {
     245           10 :     struct TALER_TESTING_Command cmd = {
     246              :       .cls = kcg,
     247              :       .label = label,
     248              :       .run = &post_kyc_start_run,
     249              :       .cleanup = &post_kyc_start_cleanup,
     250              :       .traits = &post_kyc_start_traits
     251              :     };
     252              : 
     253           10 :     return cmd;
     254              :   }
     255              : }
     256              : 
     257              : 
     258              : /* end of testing_api_cmd_post_kyc_start.c */
        

Generated by: LCOV version 2.0-1