LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_offline_sign_keys.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 20 27 74.1 %
Date: 2021-08-30 06:43:37 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          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 "platform.h"
      27             : #include "taler_json_lib.h"
      28             : #include <gnunet/gnunet_curl_lib.h>
      29             : #include "taler_signatures.h"
      30             : #include "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           8 : offlinesign_run (void *cls,
      61             :                  const struct TALER_TESTING_Command *cmd,
      62             :                  struct TALER_TESTING_Interpreter *is)
      63             : {
      64           8 :   struct OfflineSignState *ks = cls;
      65             : 
      66             :   ks->offlinesign_proc
      67           8 :     = 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           8 :   if (NULL == ks->offlinesign_proc)
      79             :   {
      80           0 :     GNUNET_break (0);
      81           0 :     TALER_TESTING_interpreter_fail (is);
      82           0 :     return;
      83             :   }
      84           8 :   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           8 : offlinesign_cleanup (void *cls,
      97             :                      const struct TALER_TESTING_Command *cmd)
      98             : {
      99           8 :   struct OfflineSignState *ks = cls;
     100             : 
     101             :   (void) cmd;
     102           8 :   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           8 :   GNUNET_free (ks);
     112           8 : }
     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 int
     125          16 : offlinesign_traits (void *cls,
     126             :                     const void **ret,
     127             :                     const char *trait,
     128             :                     unsigned int index)
     129             : {
     130          16 :   struct OfflineSignState *ks = cls;
     131             :   struct TALER_TESTING_Trait traits[] = {
     132          16 :     TALER_TESTING_make_trait_process (0,
     133             :                                       &ks->offlinesign_proc),
     134          16 :     TALER_TESTING_trait_end ()
     135             :   };
     136             : 
     137          16 :   return TALER_TESTING_get_trait (traits,
     138             :                                   ret,
     139             :                                   trait,
     140             :                                   index);
     141             : }
     142             : 
     143             : 
     144             : struct TALER_TESTING_Command
     145           8 : TALER_TESTING_cmd_exec_offline_sign_keys (const char *label,
     146             :                                           const char *config_filename)
     147             : {
     148             :   struct OfflineSignState *ks;
     149             : 
     150           8 :   ks = GNUNET_new (struct OfflineSignState);
     151           8 :   ks->config_filename = config_filename;
     152             :   {
     153           8 :     struct TALER_TESTING_Command cmd = {
     154             :       .cls = ks,
     155             :       .label = label,
     156             :       .run = &offlinesign_run,
     157             :       .cleanup = &offlinesign_cleanup,
     158             :       .traits = &offlinesign_traits
     159             :     };
     160             : 
     161           8 :     return cmd;
     162             :   }
     163             : }
     164             : 
     165             : 
     166             : /* end of testing_api_cmd_exec_offline_sign_keys.c */

Generated by: LCOV version 1.14