LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_purse_delete.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 57.1 % 49 28
Test Date: 2026-09-11 18:55:36 Functions: 100.0 % 4 4

            Line data    Source code
       1              : /*
       2              :   This file is part of TALER
       3              :   Copyright (C) 2020-2026 Taler Systems SA
       4              : 
       5              :   TALER is free software; you can redistribute it and/or modify it
       6              :   under the terms of the GNU General Public License as published by
       7              :   the Free Software Foundation; either version 3, or (at your
       8              :   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 GNU
      13              :   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/testing_api_cmd_purse_delete.c
      21              :  * @brief command for testing /management/purse/disable.
      22              :  * @author Christian Grothoff
      23              :  */
      24              : #include "taler/taler_json_lib.h"
      25              : #include <gnunet/gnunet_curl_lib.h>
      26              : struct PurseDeleteState;
      27              : #define TALER_EXCHANGE_DELETE_PURSES_RESULT_CLOSURE \
      28              :         struct PurseDeleteState
      29              : #include "taler/exchange/delete-purses-PURSE_PUB.h"
      30              : #include "taler/taler_testing_lib.h"
      31              : 
      32              : 
      33              : /**
      34              :  * State for a "purse_delete" CMD.
      35              :  */
      36              : struct PurseDeleteState
      37              : {
      38              : 
      39              :   /**
      40              :    * Purse delete handle while operation is running.
      41              :    */
      42              :   struct TALER_EXCHANGE_DeletePursesHandle *dph;
      43              : 
      44              :   /**
      45              :    * Our interpreter.
      46              :    */
      47              :   struct TALER_TESTING_Interpreter *is;
      48              : 
      49              :   /**
      50              :    * Expected HTTP response code.
      51              :    */
      52              :   unsigned int expected_response_code;
      53              : 
      54              :   /**
      55              :    * Command that created the purse we now want to
      56              :    * delete.
      57              :    */
      58              :   const char *purse_cmd;
      59              : };
      60              : 
      61              : 
      62              : /**
      63              :  * Callback to analyze the DELETE /purses/$PID response, just used to check if
      64              :  * the response code is acceptable.
      65              :  *
      66              :  * @param pds closure.
      67              :  * @param pdr HTTP response details
      68              :  */
      69              : static void
      70            2 : purse_delete_cb (struct PurseDeleteState *pds,
      71              :                  const struct TALER_EXCHANGE_DeletePursesResponse *pdr)
      72              : {
      73            2 :   pds->dph = NULL;
      74            2 :   if (pds->expected_response_code != pdr->hr.http_status)
      75              :   {
      76            0 :     TALER_TESTING_unexpected_status (pds->is,
      77              :                                      pdr->hr.http_status,
      78              :                                      pds->expected_response_code);
      79            0 :     return;
      80              :   }
      81            2 :   TALER_TESTING_interpreter_next (pds->is);
      82              : }
      83              : 
      84              : 
      85              : /**
      86              :  * Run the command.
      87              :  *
      88              :  * @param cls closure.
      89              :  * @param cmd the command to execute.
      90              :  * @param is the interpreter state.
      91              :  */
      92              : static void
      93            2 : purse_delete_run (void *cls,
      94              :                   const struct TALER_TESTING_Command *cmd,
      95              :                   struct TALER_TESTING_Interpreter *is)
      96              : {
      97            2 :   struct PurseDeleteState *pds = cls;
      98              :   const struct TALER_PurseContractPrivateKeyP *purse_priv;
      99              :   const struct TALER_TESTING_Command *ref;
     100              :   const char *exchange_url;
     101              : 
     102              :   (void) cmd;
     103            2 :   exchange_url = TALER_TESTING_get_exchange_url (is);
     104            2 :   if (NULL == exchange_url)
     105              :   {
     106            0 :     GNUNET_break (0);
     107            0 :     return;
     108              :   }
     109            2 :   ref = TALER_TESTING_interpreter_lookup_command (is,
     110              :                                                   pds->purse_cmd);
     111            2 :   if (NULL == ref)
     112              :   {
     113            0 :     GNUNET_break (0);
     114            0 :     TALER_TESTING_interpreter_fail (is);
     115            0 :     return;
     116              :   }
     117            2 :   if (GNUNET_OK !=
     118            2 :       TALER_TESTING_get_trait_purse_priv (ref,
     119              :                                           &purse_priv))
     120              :   {
     121            0 :     GNUNET_break (0);
     122            0 :     TALER_TESTING_interpreter_fail (is);
     123            0 :     return;
     124              :   }
     125            2 :   pds->is = is;
     126            2 :   pds->dph = TALER_EXCHANGE_delete_purses_create (
     127              :     TALER_TESTING_interpreter_get_context (is),
     128              :     exchange_url,
     129              :     purse_priv);
     130            2 :   if (NULL == pds->dph)
     131              :   {
     132            0 :     GNUNET_break (0);
     133            0 :     TALER_TESTING_interpreter_fail (is);
     134            0 :     return;
     135              :   }
     136              :   {
     137              :     enum TALER_ErrorCode ec;
     138              : 
     139            2 :     ec = TALER_EXCHANGE_delete_purses_start (
     140              :       pds->dph,
     141              :       &purse_delete_cb,
     142              :       pds);
     143            2 :     if (TALER_EC_NONE != ec)
     144              :     {
     145            0 :       GNUNET_break (0);
     146            0 :       TALER_EXCHANGE_delete_purses_cancel (pds->dph);
     147            0 :       pds->dph = NULL;
     148            0 :       TALER_TESTING_interpreter_fail (is);
     149            0 :       return;
     150              :     }
     151              :   }
     152              : }
     153              : 
     154              : 
     155              : /**
     156              :  * Free the state of a "purse_delete" CMD, and possibly cancel a
     157              :  * pending operation thereof.
     158              :  *
     159              :  * @param cls closure, must be a `struct PurseDeleteState`.
     160              :  * @param cmd the command which is being cleaned up.
     161              :  */
     162              : static void
     163            2 : purse_delete_cleanup (void *cls,
     164              :                       const struct TALER_TESTING_Command *cmd)
     165              : {
     166            2 :   struct PurseDeleteState *pds = cls;
     167              : 
     168            2 :   if (NULL != pds->dph)
     169              :   {
     170            0 :     TALER_TESTING_command_incomplete (pds->is,
     171              :                                       cmd->label);
     172            0 :     TALER_EXCHANGE_delete_purses_cancel (pds->dph);
     173            0 :     pds->dph = NULL;
     174              :   }
     175            2 :   GNUNET_free (pds);
     176            2 : }
     177              : 
     178              : 
     179              : struct TALER_TESTING_Command
     180            2 : TALER_TESTING_cmd_purse_delete (const char *label,
     181              :                                 unsigned int expected_http_status,
     182              :                                 const char *purse_cmd)
     183              : {
     184              :   struct PurseDeleteState *ds;
     185              : 
     186            2 :   ds = GNUNET_new (struct PurseDeleteState);
     187            2 :   ds->expected_response_code = expected_http_status;
     188            2 :   ds->purse_cmd = purse_cmd;
     189              :   {
     190            2 :     struct TALER_TESTING_Command cmd = {
     191              :       .cls = ds,
     192              :       .label = label,
     193              :       .run = &purse_delete_run,
     194              :       .cleanup = &purse_delete_cleanup
     195              :     };
     196              : 
     197            2 :     return cmd;
     198              :   }
     199              : }
     200              : 
     201              : 
     202              : /* end of testing_api_cmd_purse_delete.c */
        

Generated by: LCOV version 2.0-1