LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_revoke.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 44 0
Test Date: 2026-03-27 15:46:29 Functions: 0.0 % 4 0

            Line data    Source code
       1              : /*
       2              :   This file is part of TALER
       3              :   Copyright (C) 2014-2018 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              :  * @file testing/testing_api_cmd_revoke.c
      21              :  * @brief Implement the revoke test command.
      22              :  * @author Marcello Stanisci
      23              :  */
      24              : #include "taler/platform.h"
      25              : #include "taler/taler_json_lib.h"
      26              : #include <gnunet/gnunet_curl_lib.h>
      27              : #include "taler/taler_testing_lib.h"
      28              : 
      29              : 
      30              : /**
      31              :  * State for a "revoke" CMD.
      32              :  */
      33              : struct RevokeState
      34              : {
      35              :   /**
      36              :    * Expected HTTP status code.
      37              :    */
      38              :   unsigned int expected_response_code;
      39              : 
      40              :   /**
      41              :    * Command that offers a denomination to revoke.
      42              :    */
      43              :   const char *coin_reference;
      44              : 
      45              :   /**
      46              :    * The interpreter state.
      47              :    */
      48              :   struct TALER_TESTING_Interpreter *is;
      49              : 
      50              :   /**
      51              :    * The revoke process handle.
      52              :    */
      53              :   struct GNUNET_Process *revoke_proc;
      54              : 
      55              :   /**
      56              :    * Configuration file name.
      57              :    */
      58              :   const char *config_filename;
      59              : 
      60              :   /**
      61              :    * Encoding of the denomination (to revoke) public key hash.
      62              :    */
      63              :   char *dhks;
      64              : 
      65              : };
      66              : 
      67              : 
      68              : /**
      69              :  * Cleanup the state.
      70              :  *
      71              :  * @param cls closure, must be a `struct RevokeState`.
      72              :  * @param cmd the command which is being cleaned up.
      73              :  */
      74              : static void
      75            0 : revoke_cleanup (void *cls,
      76              :                 const struct TALER_TESTING_Command *cmd)
      77              : {
      78            0 :   struct RevokeState *rs = cls;
      79              : 
      80            0 :   if (NULL != rs->revoke_proc)
      81              :   {
      82            0 :     GNUNET_break (GNUNET_OK ==
      83              :                   GNUNET_process_kill (rs->revoke_proc,
      84              :                                        SIGKILL));
      85            0 :     GNUNET_process_wait (rs->revoke_proc,
      86              :                          true,
      87              :                          NULL,
      88              :                          NULL);
      89            0 :     GNUNET_process_destroy (rs->revoke_proc);
      90            0 :     rs->revoke_proc = NULL;
      91              :   }
      92            0 :   GNUNET_free (rs->dhks);
      93            0 :   GNUNET_free (rs);
      94            0 : }
      95              : 
      96              : 
      97              : /**
      98              :  * Offer internal data from a "revoke" CMD to other CMDs.
      99              :  *
     100              :  * @param cls closure
     101              :  * @param[out] ret result (could be anything)
     102              :  * @param trait name of the trait
     103              :  * @param index index number of the object to offer.
     104              :  * @return #GNUNET_OK on success
     105              :  */
     106              : static enum GNUNET_GenericReturnValue
     107            0 : revoke_traits (void *cls,
     108              :                const void **ret,
     109              :                const char *trait,
     110              :                unsigned int index)
     111              : {
     112            0 :   struct RevokeState *rs = cls;
     113              :   struct TALER_TESTING_Trait traits[] = {
     114              :     /* Needed by the handler which waits the proc'
     115              :      * death and calls the next command */
     116            0 :     TALER_TESTING_make_trait_process (&rs->revoke_proc),
     117            0 :     TALER_TESTING_trait_end ()
     118              :   };
     119              : 
     120            0 :   return TALER_TESTING_get_trait (traits,
     121              :                                   ret,
     122              :                                   trait,
     123              :                                   index);
     124              : }
     125              : 
     126              : 
     127              : /**
     128              :  * Run the "revoke" command.
     129              :  *
     130              :  * @param cls closure.
     131              :  * @param cmd the command to execute.
     132              :  * @param is the interpreter state.
     133              :  */
     134              : static void
     135            0 : revoke_run (void *cls,
     136              :             const struct TALER_TESTING_Command *cmd,
     137              :             struct TALER_TESTING_Interpreter *is)
     138              : {
     139            0 :   struct RevokeState *rs = cls;
     140              :   const struct TALER_TESTING_Command *coin_cmd;
     141              :   const struct TALER_EXCHANGE_DenomPublicKey *denom_pub;
     142              : 
     143            0 :   rs->is = is;
     144              :   /* Get denom pub from trait */
     145            0 :   coin_cmd = TALER_TESTING_interpreter_lookup_command (is,
     146              :                                                        rs->coin_reference);
     147            0 :   if (NULL == coin_cmd)
     148              :   {
     149            0 :     GNUNET_break (0);
     150            0 :     TALER_TESTING_interpreter_fail (is);
     151            0 :     return;
     152              :   }
     153            0 :   GNUNET_assert (GNUNET_OK ==
     154              :                  TALER_TESTING_get_trait_denom_pub (coin_cmd,
     155              :                                                     0,
     156              :                                                     &denom_pub));
     157              : 
     158            0 :   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
     159              :               "Trying to revoke denom '%s..'\n",
     160              :               TALER_B2S (&denom_pub->h_key));
     161              : 
     162            0 :   rs->dhks = GNUNET_STRINGS_data_to_string_alloc (
     163            0 :     &denom_pub->h_key,
     164              :     sizeof (struct GNUNET_HashCode));
     165            0 :   rs->revoke_proc = GNUNET_process_create (GNUNET_OS_INHERIT_STD_ERR);
     166            0 :   if (GNUNET_OK !=
     167            0 :       GNUNET_process_run_command_va (
     168              :         rs->revoke_proc,
     169              :         "taler-exchange-offline",
     170              :         "taler-exchange-offline",
     171              :         "-c", rs->config_filename,
     172              :         "revoke-denomination", rs->dhks,
     173              :         "upload",
     174              :         NULL))
     175              :   {
     176            0 :     GNUNET_break (0);
     177            0 :     GNUNET_process_destroy (rs->revoke_proc);
     178            0 :     rs->revoke_proc = NULL;
     179            0 :     TALER_TESTING_interpreter_fail (is);
     180            0 :     return;
     181              :   }
     182            0 :   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
     183              :               "Revoke is ongoing..\n");
     184            0 :   TALER_TESTING_wait_for_sigchld (is);
     185              : }
     186              : 
     187              : 
     188              : struct TALER_TESTING_Command
     189            0 : TALER_TESTING_cmd_revoke (const char *label,
     190              :                           unsigned int expected_response_code,
     191              :                           const char *coin_reference,
     192              :                           const char *config_filename)
     193              : {
     194              : 
     195              :   struct RevokeState *rs;
     196              : 
     197            0 :   rs = GNUNET_new (struct RevokeState);
     198            0 :   rs->expected_response_code = expected_response_code;
     199            0 :   rs->coin_reference = coin_reference;
     200            0 :   rs->config_filename = config_filename;
     201              :   {
     202            0 :     struct TALER_TESTING_Command cmd = {
     203              :       .cls = rs,
     204              :       .label = label,
     205              :       .run = &revoke_run,
     206              :       .cleanup = &revoke_cleanup,
     207              :       .traits = &revoke_traits
     208              :     };
     209              : 
     210            0 :     return cmd;
     211              :   }
     212              : }
        

Generated by: LCOV version 2.0-1