LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_offline_sign_keys.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 74.1 % 27 20
Test Date: 2025-12-26 23:00:34 Functions: 100.0 % 4 4

            Line data    Source code
       1              : /*
       2              :   This file is part of TALER
       3              :   Copyright (C) 2020 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
       7              :   by 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
      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,
      17              :   see <http://www.gnu.org/licenses/>
      18              : */
      19              : 
      20              : /**
      21              :  * @file testing/testing_api_cmd_offline_sign_keys.c
      22              :  * @brief run the taler-exchange-offline command to download, sign and upload keys
      23              :  * @author Marcello Stanisci
      24              :  * @author Christian Grothoff
      25              :  */
      26              : #include "taler/platform.h"
      27              : #include "taler/taler_json_lib.h"
      28              : #include <gnunet/gnunet_curl_lib.h>
      29              : #include "taler/taler_signatures.h"
      30              : #include "taler/taler_testing_lib.h"
      31              : 
      32              : 
      33              : /**
      34              :  * State for a "offlinesign" CMD.
      35              :  */
      36              : struct OfflineSignState
      37              : {
      38              : 
      39              :   /**
      40              :    * Process for the "offlinesign" command.
      41              :    */
      42              :   struct GNUNET_OS_Process *offlinesign_proc;
      43              : 
      44              :   /**
      45              :    * Configuration file used by the command.
      46              :    */
      47              :   const char *config_filename;
      48              : 
      49              : };
      50              : 
      51              : 
      52              : /**
      53              :  * Run the command; calls the `taler-exchange-offline` program.
      54              :  *
      55              :  * @param cls closure.
      56              :  * @param cmd the commaind being run.
      57              :  * @param is interpreter state.
      58              :  */
      59              : static void
      60            2 : offlinesign_run (void *cls,
      61              :                  const struct TALER_TESTING_Command *cmd,
      62              :                  struct TALER_TESTING_Interpreter *is)
      63              : {
      64            2 :   struct OfflineSignState *ks = cls;
      65              : 
      66              :   ks->offlinesign_proc
      67            2 :     = GNUNET_OS_start_process (
      68              :         GNUNET_OS_INHERIT_STD_ALL,
      69              :         NULL, NULL, NULL,
      70              :         "taler-exchange-offline",
      71              :         "taler-exchange-offline",
      72              :         "-c", ks->config_filename,
      73              :         "-L", "INFO",
      74              :         "download",
      75              :         "sign",
      76              :         "upload",
      77              :         NULL);
      78            2 :   if (NULL == ks->offlinesign_proc)
      79              :   {
      80            0 :     GNUNET_break (0);
      81            0 :     TALER_TESTING_interpreter_fail (is);
      82            0 :     return;
      83              :   }
      84            2 :   TALER_TESTING_wait_for_sigchld (is);
      85              : }
      86              : 
      87              : 
      88              : /**
      89              :  * Free the state of a "offlinesign" CMD, and possibly kills its
      90              :  * process if it did not terminate correctly.
      91              :  *
      92              :  * @param cls closure.
      93              :  * @param cmd the command being freed.
      94              :  */
      95              : static void
      96            2 : offlinesign_cleanup (void *cls,
      97              :                      const struct TALER_TESTING_Command *cmd)
      98              : {
      99            2 :   struct OfflineSignState *ks = cls;
     100              : 
     101              :   (void) cmd;
     102            2 :   if (NULL != ks->offlinesign_proc)
     103              :   {
     104            0 :     GNUNET_break (0 ==
     105              :                   GNUNET_OS_process_kill (ks->offlinesign_proc,
     106              :                                           SIGKILL));
     107            0 :     GNUNET_OS_process_wait (ks->offlinesign_proc);
     108            0 :     GNUNET_OS_process_destroy (ks->offlinesign_proc);
     109            0 :     ks->offlinesign_proc = NULL;
     110              :   }
     111            2 :   GNUNET_free (ks);
     112            2 : }
     113              : 
     114              : 
     115              : /**
     116              :  * Offer "offlinesign" CMD internal data to other commands.
     117              :  *
     118              :  * @param cls closure.
     119              :  * @param[out] ret result
     120              :  * @param trait name of the trait.
     121              :  * @param index index number of the object to offer.
     122              :  * @return #GNUNET_OK on success.
     123              :  */
     124              : static enum GNUNET_GenericReturnValue
     125            4 : offlinesign_traits (void *cls,
     126              :                     const void **ret,
     127              :                     const char *trait,
     128              :                     unsigned int index)
     129              : {
     130            4 :   struct OfflineSignState *ks = cls;
     131              :   struct TALER_TESTING_Trait traits[] = {
     132            4 :     TALER_TESTING_make_trait_process (&ks->offlinesign_proc),
     133            4 :     TALER_TESTING_trait_end ()
     134              :   };
     135              : 
     136            4 :   return TALER_TESTING_get_trait (traits,
     137              :                                   ret,
     138              :                                   trait,
     139              :                                   index);
     140              : }
     141              : 
     142              : 
     143              : struct TALER_TESTING_Command
     144            2 : TALER_TESTING_cmd_exec_offline_sign_keys (const char *label,
     145              :                                           const char *config_filename)
     146              : {
     147              :   struct OfflineSignState *ks;
     148              : 
     149            2 :   ks = GNUNET_new (struct OfflineSignState);
     150            2 :   ks->config_filename = config_filename;
     151              :   {
     152            2 :     struct TALER_TESTING_Command cmd = {
     153              :       .cls = ks,
     154              :       .label = label,
     155              :       .run = &offlinesign_run,
     156              :       .cleanup = &offlinesign_cleanup,
     157              :       .traits = &offlinesign_traits
     158              :     };
     159              : 
     160            2 :     return cmd;
     161              :   }
     162              : }
     163              : 
     164              : 
     165              : /* end of testing_api_cmd_exec_offline_sign_keys.c */
        

Generated by: LCOV version 2.0-1