LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_kyc_proof.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 0 63 0.0 %
Date: 2022-08-25 06:15:09 Functions: 0 5 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   Copyright (C) 2021 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_proof.c
      22             :  * @brief Implement the testing CMDs for the /kyc-proof/ operation.
      23             :  * @author Christian Grothoff
      24             :  */
      25             : #include "platform.h"
      26             : #include "taler_json_lib.h"
      27             : #include <gnunet/gnunet_curl_lib.h>
      28             : #include "taler_testing_lib.h"
      29             : 
      30             : /**
      31             :  * State for a "track transaction" CMD.
      32             :  */
      33             : struct KycProofGetState
      34             : {
      35             : 
      36             :   /**
      37             :    * Command to get a reserve private key from.
      38             :    */
      39             :   const char *payment_target_reference;
      40             : 
      41             :   /**
      42             :    * Code to pass.
      43             :    */
      44             :   const char *code;
      45             : 
      46             :   /**
      47             :    * State to pass.
      48             :    */
      49             :   const char *state;
      50             : 
      51             :   /**
      52             :    * Logic section name to pass to `/kyc-proof/` handler.
      53             :    */
      54             :   const char *logic;
      55             : 
      56             :   /**
      57             :    * Expected HTTP response code.
      58             :    */
      59             :   unsigned int expected_response_code;
      60             : 
      61             :   /**
      62             :    * Set to the KYC REDIRECT *if* the exchange replied with
      63             :    * success (#MHD_HTTP_OK).
      64             :    */
      65             :   char *redirect_url;
      66             : 
      67             :   /**
      68             :    * Handle to the "track transaction" pending operation.
      69             :    */
      70             :   struct TALER_EXCHANGE_KycProofHandle *kph;
      71             : 
      72             :   /**
      73             :    * Interpreter state.
      74             :    */
      75             :   struct TALER_TESTING_Interpreter *is;
      76             : };
      77             : 
      78             : 
      79             : /**
      80             :  * Handle response to the command.
      81             :  *
      82             :  * @param cls closure.
      83             :  * @param kpr KYC proof response details
      84             :  */
      85             : static void
      86           0 : proof_kyc_cb (void *cls,
      87             :               const struct TALER_EXCHANGE_KycProofResponse *kpr)
      88             : {
      89           0 :   struct KycProofGetState *kcg = cls;
      90           0 :   struct TALER_TESTING_Interpreter *is = kcg->is;
      91           0 :   struct TALER_TESTING_Command *cmd = &is->commands[is->ip];
      92             : 
      93           0 :   kcg->kph = NULL;
      94           0 :   if (kcg->expected_response_code != kpr->http_status)
      95             :   {
      96           0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
      97             :                 "Unexpected response code %u to command %s in %s:%u\n",
      98             :                 kpr->http_status,
      99             :                 cmd->label,
     100             :                 __FILE__,
     101             :                 __LINE__);
     102           0 :     TALER_TESTING_interpreter_fail (is);
     103           0 :     return;
     104             :   }
     105           0 :   switch (kpr->http_status)
     106             :   {
     107           0 :   case MHD_HTTP_SEE_OTHER:
     108           0 :     kcg->redirect_url = GNUNET_strdup (kpr->details.found.redirect_url);
     109           0 :     break;
     110           0 :   case MHD_HTTP_FORBIDDEN:
     111           0 :     break;
     112           0 :   case MHD_HTTP_BAD_GATEWAY:
     113           0 :     break;
     114           0 :   default:
     115           0 :     GNUNET_break (0);
     116           0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     117             :                 "Unexpected response code %u to /kyc-proof\n",
     118             :                 kpr->http_status);
     119           0 :     break;
     120             :   }
     121           0 :   TALER_TESTING_interpreter_next (kcg->is);
     122             : }
     123             : 
     124             : 
     125             : /**
     126             :  * Run the command.
     127             :  *
     128             :  * @param cls closure.
     129             :  * @param cmd the command to execute.
     130             :  * @param is the interpreter state.
     131             :  */
     132             : static void
     133           0 : proof_kyc_run (void *cls,
     134             :                const struct TALER_TESTING_Command *cmd,
     135             :                struct TALER_TESTING_Interpreter *is)
     136             : {
     137           0 :   struct KycProofGetState *kps = cls;
     138             :   const struct TALER_TESTING_Command *res_cmd;
     139             :   const struct TALER_PaytoHashP *h_payto;
     140             :   char *uargs;
     141             : 
     142             :   (void) cmd;
     143           0 :   kps->is = is;
     144           0 :   res_cmd = TALER_TESTING_interpreter_lookup_command (
     145             :     kps->is,
     146             :     kps->payment_target_reference);
     147           0 :   if (NULL == res_cmd)
     148             :   {
     149           0 :     GNUNET_break (0);
     150           0 :     TALER_TESTING_interpreter_fail (kps->is);
     151           0 :     return;
     152             :   }
     153           0 :   if (GNUNET_OK !=
     154           0 :       TALER_TESTING_get_trait_h_payto (res_cmd,
     155             :                                        &h_payto))
     156             :   {
     157           0 :     GNUNET_break (0);
     158           0 :     TALER_TESTING_interpreter_fail (kps->is);
     159           0 :     return;
     160             :   }
     161           0 :   GNUNET_asprintf (&uargs,
     162             :                    "?code=%s&state=%s",
     163             :                    kps->code,
     164             :                    kps->state);
     165           0 :   kps->kph = TALER_EXCHANGE_kyc_proof (is->exchange,
     166             :                                        h_payto,
     167             :                                        kps->logic,
     168             :                                        uargs,
     169             :                                        &proof_kyc_cb,
     170             :                                        kps);
     171           0 :   GNUNET_free (uargs);
     172           0 :   GNUNET_assert (NULL != kps->kph);
     173             : }
     174             : 
     175             : 
     176             : /**
     177             :  * Cleanup the state from a "track transaction" CMD, and possibly
     178             :  * cancel a operation thereof.
     179             :  *
     180             :  * @param cls closure.
     181             :  * @param cmd the command which is being cleaned up.
     182             :  */
     183             : static void
     184           0 : proof_kyc_cleanup (void *cls,
     185             :                    const struct TALER_TESTING_Command *cmd)
     186             : {
     187           0 :   struct KycProofGetState *kps = cls;
     188             : 
     189           0 :   if (NULL != kps->kph)
     190             :   {
     191           0 :     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
     192             :                 "Command %u (%s) did not complete\n",
     193             :                 kps->is->ip,
     194             :                 cmd->label);
     195           0 :     TALER_EXCHANGE_kyc_proof_cancel (kps->kph);
     196           0 :     kps->kph = NULL;
     197             :   }
     198           0 :   GNUNET_free (kps->redirect_url);
     199           0 :   GNUNET_free (kps);
     200           0 : }
     201             : 
     202             : 
     203             : /**
     204             :  * Offer internal data from a "proof 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           0 : proof_kyc_traits (void *cls,
     214             :                   const void **ret,
     215             :                   const char *trait,
     216             :                   unsigned int index)
     217             : {
     218           0 :   struct KycProofGetState *kps = cls;
     219             :   struct TALER_TESTING_Trait traits[] = {
     220           0 :     TALER_TESTING_make_trait_web_url (
     221           0 :       (const char **) &kps->redirect_url),
     222           0 :     TALER_TESTING_trait_end ()
     223             :   };
     224             : 
     225           0 :   return TALER_TESTING_get_trait (traits,
     226             :                                   ret,
     227             :                                   trait,
     228             :                                   index);
     229             : }
     230             : 
     231             : 
     232             : struct TALER_TESTING_Command
     233           0 : TALER_TESTING_cmd_proof_kyc_oauth2 (
     234             :   const char *label,
     235             :   const char *payment_target_reference,
     236             :   const char *logic_section,
     237             :   const char *code,
     238             :   const char *state,
     239             :   unsigned int expected_response_code)
     240             : {
     241             :   struct KycProofGetState *kps;
     242             : 
     243           0 :   kps = GNUNET_new (struct KycProofGetState);
     244           0 :   kps->code = code;
     245           0 :   kps->state = state;
     246           0 :   kps->logic = logic_section;
     247           0 :   kps->payment_target_reference = payment_target_reference;
     248           0 :   kps->expected_response_code = expected_response_code;
     249             :   {
     250           0 :     struct TALER_TESTING_Command cmd = {
     251             :       .cls = kps,
     252             :       .label = label,
     253             :       .run = &proof_kyc_run,
     254             :       .cleanup = &proof_kyc_cleanup,
     255             :       .traits = &proof_kyc_traits
     256             :     };
     257             : 
     258           0 :     return cmd;
     259             :   }
     260             : }
     261             : 
     262             : 
     263             : /* end of testing_api_cmd_kyc_proof.c */

Generated by: LCOV version 1.14