LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_kyc_wallet_get.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 71.7 % 92 66
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_wallet_get.c
      22              :  * @brief Implement the testing CMDs for the /kyc_wallet/ 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 "/kyc-wallet" GET CMD.
      30              :  */
      31              : struct KycWalletGetState;
      32              : 
      33              : #define TALER_EXCHANGE_POST_KYC_WALLET_RESULT_CLOSURE \
      34              :         struct KycWalletGetState
      35              : #include "taler/exchange/post-kyc-wallet.h"
      36              : #include "taler/taler_testing_lib.h"
      37              : 
      38              : /**
      39              :  * State for a "/kyc-wallet" GET CMD.
      40              :  */
      41              : struct KycWalletGetState
      42              : {
      43              : 
      44              :   /**
      45              :    * Private key of the reserve (account).
      46              :    */
      47              :   union TALER_AccountPrivateKeyP account_priv;
      48              : 
      49              :   /**
      50              :    * Public key of the reserve (account).
      51              :    */
      52              :   union TALER_AccountPublicKeyP account_pub;
      53              : 
      54              :   /**
      55              :    * Payto URI of the reserve of the wallet.
      56              :    */
      57              :   struct TALER_NormalizedPayto reserve_payto_uri;
      58              : 
      59              :   /**
      60              :    * Our command.
      61              :    */
      62              :   const struct TALER_TESTING_Command *cmd;
      63              : 
      64              :   /**
      65              :    * Command to get a reserve private key from.
      66              :    */
      67              :   const char *reserve_reference;
      68              : 
      69              :   /**
      70              :    * Expected HTTP response code.
      71              :    */
      72              :   unsigned int expected_response_code;
      73              : 
      74              :   /**
      75              :    * Set to the KYC requirement payto hash *if* the exchange replied with a
      76              :    * request for KYC (#MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS).
      77              :    */
      78              :   struct TALER_NormalizedPaytoHashP h_payto;
      79              : 
      80              :   /**
      81              :    * Set to the KYC requirement row *if* the exchange replied with
      82              :    * request for KYC (#MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS).
      83              :    */
      84              :   uint64_t requirement_row;
      85              : 
      86              :   /**
      87              :    * Handle to the "track transaction" pending operation.
      88              :    */
      89              :   struct TALER_EXCHANGE_PostKycWalletHandle *kwh;
      90              : 
      91              :   /**
      92              :    * Balance to pass to the exchange.
      93              :    */
      94              :   struct TALER_Amount balance;
      95              : 
      96              :   /**
      97              :    * Interpreter state.
      98              :    */
      99              :   struct TALER_TESTING_Interpreter *is;
     100              : };
     101              : 
     102              : 
     103              : /**
     104              :  * Handle response to the command.
     105              :  *
     106              :  * @param kwg our state
     107              :  * @param wkr GET deposit response details
     108              :  */
     109              : static void
     110            7 : wallet_kyc_cb (
     111              :   struct KycWalletGetState *kwg,
     112              :   const struct TALER_EXCHANGE_PostKycWalletResponse *wkr)
     113              : {
     114            7 :   struct TALER_TESTING_Interpreter *is = kwg->is;
     115              : 
     116            7 :   kwg->kwh = NULL;
     117            7 :   if (kwg->expected_response_code != wkr->hr.http_status)
     118              :   {
     119            0 :     TALER_TESTING_unexpected_status (is,
     120              :                                      wkr->hr.http_status,
     121              :                                      kwg->expected_response_code);
     122            0 :     return;
     123              :   }
     124            7 :   switch (wkr->hr.http_status)
     125              :   {
     126            2 :   case MHD_HTTP_OK:
     127            2 :     break;
     128            0 :   case MHD_HTTP_NO_CONTENT:
     129            0 :     break;
     130            0 :   case MHD_HTTP_FORBIDDEN:
     131            0 :     GNUNET_break (0);
     132            0 :     TALER_TESTING_interpreter_fail (is);
     133            0 :     return;
     134            5 :   case MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS:
     135              :     kwg->requirement_row
     136            5 :       = wkr->details.unavailable_for_legal_reasons.requirement_row;
     137              :     kwg->h_payto
     138            5 :       = wkr->details.unavailable_for_legal_reasons.h_payto;
     139            5 :     break;
     140            0 :   default:
     141            0 :     GNUNET_break (0);
     142            0 :     break;
     143              :   }
     144            7 :   TALER_TESTING_interpreter_next (kwg->is);
     145              : }
     146              : 
     147              : 
     148              : /**
     149              :  * Run the command.
     150              :  *
     151              :  * @param cls closure.
     152              :  * @param cmd the command to execute.
     153              :  * @param is the interpreter state.
     154              :  */
     155              : static void
     156            7 : wallet_kyc_run (void *cls,
     157              :                 const struct TALER_TESTING_Command *cmd,
     158              :                 struct TALER_TESTING_Interpreter *is)
     159              : {
     160            7 :   struct KycWalletGetState *kwg = cls;
     161              :   const char *exchange_url;
     162              : 
     163            7 :   kwg->cmd = cmd;
     164            7 :   kwg->is = is;
     165            7 :   exchange_url = TALER_TESTING_get_exchange_url (is);
     166            7 :   if (NULL == exchange_url)
     167              :   {
     168            0 :     GNUNET_break (0);
     169            0 :     return;
     170              :   }
     171            7 :   if (NULL != kwg->reserve_reference)
     172              :   {
     173              :     const struct TALER_TESTING_Command *res_cmd;
     174              :     const struct TALER_ReservePrivateKeyP *reserve_priv;
     175              : 
     176              :     res_cmd
     177            4 :       = TALER_TESTING_interpreter_lookup_command (kwg->is,
     178              :                                                   kwg->reserve_reference);
     179            4 :     if (NULL == res_cmd)
     180              :     {
     181            0 :       GNUNET_break (0);
     182            0 :       TALER_TESTING_interpreter_fail (kwg->is);
     183            0 :       return;
     184              :     }
     185            4 :     if (GNUNET_OK !=
     186            4 :         TALER_TESTING_get_trait_reserve_priv (
     187              :           res_cmd,
     188              :           &reserve_priv))
     189              :     {
     190            0 :       GNUNET_break (0);
     191            0 :       TALER_TESTING_interpreter_fail (kwg->is);
     192            0 :       return;
     193              :     }
     194            4 :     kwg->account_priv.reserve_priv = *reserve_priv;
     195              :   }
     196              :   else
     197              :   {
     198            3 :     GNUNET_CRYPTO_eddsa_key_create (
     199              :       &kwg->account_priv.reserve_priv.eddsa_priv);
     200              :   }
     201            7 :   GNUNET_CRYPTO_eddsa_key_get_public (
     202            7 :     &kwg->account_priv.reserve_priv.eddsa_priv,
     203              :     &kwg->account_pub.reserve_pub.eddsa_pub);
     204              :   kwg->reserve_payto_uri
     205            7 :     = TALER_reserve_make_payto (exchange_url,
     206            7 :                                 &kwg->account_pub.reserve_pub);
     207            7 :   kwg->kwh = TALER_EXCHANGE_post_kyc_wallet_create (
     208              :     TALER_TESTING_interpreter_get_context (is),
     209              :     exchange_url,
     210            7 :     &kwg->account_priv.reserve_priv,
     211            7 :     &kwg->balance);
     212            7 :   GNUNET_assert (NULL != kwg->kwh);
     213              :   {
     214              :     enum TALER_ErrorCode ec;
     215              : 
     216            7 :     ec = TALER_EXCHANGE_post_kyc_wallet_start (kwg->kwh,
     217              :                                                &wallet_kyc_cb,
     218              :                                                kwg);
     219            7 :     if (TALER_EC_NONE != ec)
     220              :     {
     221            0 :       GNUNET_break (0);
     222            0 :       kwg->kwh = NULL;
     223            0 :       TALER_TESTING_interpreter_fail (is);
     224            0 :       return;
     225              :     }
     226              :   }
     227              : }
     228              : 
     229              : 
     230              : /**
     231              :  * Cleanup the state from a "track transaction" CMD, and possibly
     232              :  * cancel a operation thereof.
     233              :  *
     234              :  * @param cls closure with our `struct KycWalletGetState`
     235              :  * @param cmd the command which is being cleaned up.
     236              :  */
     237              : static void
     238            7 : wallet_kyc_cleanup (
     239              :   void *cls,
     240              :   const struct TALER_TESTING_Command *cmd)
     241              : {
     242            7 :   struct KycWalletGetState *kwg = cls;
     243              : 
     244            7 :   if (NULL != kwg->kwh)
     245              :   {
     246            0 :     TALER_TESTING_command_incomplete (kwg->is,
     247              :                                       cmd->label);
     248            0 :     TALER_EXCHANGE_post_kyc_wallet_cancel (kwg->kwh);
     249            0 :     kwg->kwh = NULL;
     250              :   }
     251            7 :   GNUNET_free (kwg->reserve_payto_uri.normalized_payto);
     252            7 :   GNUNET_free (kwg);
     253            7 : }
     254              : 
     255              : 
     256              : /**
     257              :  * Offer internal data from a "wallet KYC" CMD.
     258              :  *
     259              :  * @param cls closure.
     260              :  * @param[out] ret result (could be anything).
     261              :  * @param trait name of the trait.
     262              :  * @param index index number of the object to offer.
     263              :  * @return #GNUNET_OK on success.
     264              :  */
     265              : static enum GNUNET_GenericReturnValue
     266           21 : wallet_kyc_traits (void *cls,
     267              :                    const void **ret,
     268              :                    const char *trait,
     269              :                    unsigned int index)
     270              : {
     271           21 :   struct KycWalletGetState *kwg = cls;
     272              :   struct TALER_TESTING_Trait traits[] = {
     273           21 :     TALER_TESTING_make_trait_account_priv (
     274           21 :       &kwg->account_priv),
     275           21 :     TALER_TESTING_make_trait_account_pub (
     276           21 :       &kwg->account_pub),
     277           21 :     TALER_TESTING_make_trait_reserve_priv (
     278           21 :       &kwg->account_priv.reserve_priv),
     279           21 :     TALER_TESTING_make_trait_reserve_pub (
     280           21 :       &kwg->account_pub.reserve_pub),
     281           21 :     TALER_TESTING_make_trait_legi_requirement_row (
     282           21 :       &kwg->requirement_row),
     283           21 :     TALER_TESTING_make_trait_h_normalized_payto (
     284           21 :       &kwg->h_payto),
     285           21 :     TALER_TESTING_make_trait_normalized_payto_uri (
     286           21 :       &kwg->reserve_payto_uri),
     287           21 :     TALER_TESTING_trait_end ()
     288              :   };
     289              : 
     290           21 :   return TALER_TESTING_get_trait (traits,
     291              :                                   ret,
     292              :                                   trait,
     293              :                                   index);
     294              : }
     295              : 
     296              : 
     297              : struct TALER_TESTING_Command
     298            7 : TALER_TESTING_cmd_wallet_kyc_get (
     299              :   const char *label,
     300              :   const char *reserve_reference,
     301              :   const char *threshold_balance,
     302              :   unsigned int expected_response_code)
     303              : {
     304              :   struct KycWalletGetState *kwg;
     305              : 
     306            7 :   kwg = GNUNET_new (struct KycWalletGetState);
     307            7 :   kwg->reserve_reference = reserve_reference;
     308            7 :   kwg->expected_response_code = expected_response_code;
     309            7 :   GNUNET_assert (GNUNET_OK ==
     310              :                  TALER_string_to_amount (threshold_balance,
     311              :                                          &kwg->balance));
     312              :   {
     313            7 :     struct TALER_TESTING_Command cmd = {
     314              :       .cls = kwg,
     315              :       .label = label,
     316              :       .run = &wallet_kyc_run,
     317              :       .cleanup = &wallet_kyc_cleanup,
     318              :       .traits = &wallet_kyc_traits
     319              :     };
     320              : 
     321            7 :     return cmd;
     322              :   }
     323              : }
     324              : 
     325              : 
     326              : /* end of testing_api_cmd_kyc_wallet_get.c */
        

Generated by: LCOV version 2.0-1