LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_auditor_del.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 29 41 70.7 %
Date: 2021-08-30 06:43:37 Functions: 4 5 80.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 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_auditor_del.c
      21             :  * @brief command for testing /management/auditor/disable.
      22             :  * @author Christian Grothoff
      23             :  */
      24             : #include "platform.h"
      25             : #include "taler_json_lib.h"
      26             : #include <gnunet/gnunet_curl_lib.h>
      27             : #include "taler_testing_lib.h"
      28             : #include "taler_signatures.h"
      29             : #include "backoff.h"
      30             : 
      31             : 
      32             : /**
      33             :  * State for a "auditor_del" CMD.
      34             :  */
      35             : struct AuditorDelState
      36             : {
      37             : 
      38             :   /**
      39             :    * Auditor enable handle while operation is running.
      40             :    */
      41             :   struct TALER_EXCHANGE_ManagementAuditorDisableHandle *dh;
      42             : 
      43             :   /**
      44             :    * Our interpreter.
      45             :    */
      46             :   struct TALER_TESTING_Interpreter *is;
      47             : 
      48             :   /**
      49             :    * Expected HTTP response code.
      50             :    */
      51             :   unsigned int expected_response_code;
      52             : 
      53             :   /**
      54             :    * Should we make the request with a bad master_sig signature?
      55             :    */
      56             :   bool bad_sig;
      57             : };
      58             : 
      59             : 
      60             : /**
      61             :  * Callback to analyze the /management/auditors response, just used to check
      62             :  * if the response code is acceptable.
      63             :  *
      64             :  * @param cls closure.
      65             :  * @param hr HTTP response details
      66             :  */
      67             : static void
      68           4 : auditor_del_cb (void *cls,
      69             :                 const struct TALER_EXCHANGE_HttpResponse *hr)
      70             : {
      71           4 :   struct AuditorDelState *ds = cls;
      72             : 
      73           4 :   ds->dh = NULL;
      74           4 :   if (ds->expected_response_code != hr->http_status)
      75             :   {
      76           0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
      77             :                 "Unexpected response code %u to command %s in %s:%u\n",
      78             :                 hr->http_status,
      79             :                 ds->is->commands[ds->is->ip].label,
      80             :                 __FILE__,
      81             :                 __LINE__);
      82           0 :     json_dumpf (hr->reply,
      83             :                 stderr,
      84             :                 0);
      85           0 :     TALER_TESTING_interpreter_fail (ds->is);
      86           0 :     return;
      87             :   }
      88           4 :   TALER_TESTING_interpreter_next (ds->is);
      89             : }
      90             : 
      91             : 
      92             : /**
      93             :  * Run the command.
      94             :  *
      95             :  * @param cls closure.
      96             :  * @param cmd the command to execute.
      97             :  * @param is the interpreter state.
      98             :  */
      99             : static void
     100           4 : auditor_del_run (void *cls,
     101             :                  const struct TALER_TESTING_Command *cmd,
     102             :                  struct TALER_TESTING_Interpreter *is)
     103             : {
     104           4 :   struct AuditorDelState *ds = cls;
     105             :   struct TALER_MasterSignatureP master_sig;
     106             :   struct GNUNET_TIME_Absolute now;
     107             : 
     108             :   (void) cmd;
     109           4 :   now = GNUNET_TIME_absolute_get ();
     110           4 :   (void) GNUNET_TIME_round_abs (&now);
     111           4 :   ds->is = is;
     112           4 :   if (ds->bad_sig)
     113             :   {
     114           1 :     memset (&master_sig,
     115             :             42,
     116             :             sizeof (master_sig));
     117             :   }
     118             :   else
     119             :   {
     120           3 :     TALER_exchange_offline_auditor_del_sign (&is->auditor_pub,
     121             :                                              now,
     122           3 :                                              &is->master_priv,
     123             :                                              &master_sig);
     124             :   }
     125           8 :   ds->dh = TALER_EXCHANGE_management_disable_auditor (
     126             :     is->ctx,
     127           4 :     is->exchange_url,
     128           4 :     &is->auditor_pub,
     129             :     now,
     130             :     &master_sig,
     131             :     &auditor_del_cb,
     132             :     ds);
     133           4 :   if (NULL == ds->dh)
     134             :   {
     135           0 :     GNUNET_break (0);
     136           0 :     TALER_TESTING_interpreter_fail (is);
     137           0 :     return;
     138             :   }
     139             : }
     140             : 
     141             : 
     142             : /**
     143             :  * Free the state of a "auditor_del" CMD, and possibly cancel a
     144             :  * pending operation thereof.
     145             :  *
     146             :  * @param cls closure, must be a `struct AuditorDelState`.
     147             :  * @param cmd the command which is being cleaned up.
     148             :  */
     149             : static void
     150           4 : auditor_del_cleanup (void *cls,
     151             :                      const struct TALER_TESTING_Command *cmd)
     152             : {
     153           4 :   struct AuditorDelState *ds = cls;
     154             : 
     155           4 :   if (NULL != ds->dh)
     156             :   {
     157           0 :     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
     158             :                 "Command %u (%s) did not complete\n",
     159             :                 ds->is->ip,
     160             :                 cmd->label);
     161           0 :     TALER_EXCHANGE_management_disable_auditor_cancel (ds->dh);
     162           0 :     ds->dh = NULL;
     163             :   }
     164           4 :   GNUNET_free (ds);
     165           4 : }
     166             : 
     167             : 
     168             : /**
     169             :  * Offer internal data from a "auditor_del" CMD, to other commands.
     170             :  *
     171             :  * @param cls closure.
     172             :  * @param[out] ret result.
     173             :  * @param trait name of the trait.
     174             :  * @param index index number of the object to offer.
     175             :  *
     176             :  * @return #GNUNET_OK on success.
     177             :  */
     178             : static int
     179           0 : auditor_del_traits (void *cls,
     180             :                     const void **ret,
     181             :                     const char *trait,
     182             :                     unsigned int index)
     183             : {
     184           0 :   return GNUNET_NO;
     185             : }
     186             : 
     187             : 
     188             : struct TALER_TESTING_Command
     189           4 : TALER_TESTING_cmd_auditor_del (const char *label,
     190             :                                unsigned int expected_http_status,
     191             :                                bool bad_sig)
     192             : {
     193             :   struct AuditorDelState *ds;
     194             : 
     195           4 :   ds = GNUNET_new (struct AuditorDelState);
     196           4 :   ds->expected_response_code = expected_http_status;
     197           4 :   ds->bad_sig = bad_sig;
     198             :   {
     199           4 :     struct TALER_TESTING_Command cmd = {
     200             :       .cls = ds,
     201             :       .label = label,
     202             :       .run = &auditor_del_run,
     203             :       .cleanup = &auditor_del_cleanup,
     204             :       .traits = &auditor_del_traits
     205             :     };
     206             : 
     207           4 :     return cmd;
     208             :   }
     209             : }
     210             : 
     211             : 
     212             : /* end of testing_api_cmd_auditor_del.c */

Generated by: LCOV version 1.14