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: 0 38 0.0 %
Date: 2022-08-25 06:15:09 Functions: 0 4 0.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           0 : auditor_del_cb (void *cls,
      69             :                 const struct TALER_EXCHANGE_HttpResponse *hr)
      70             : {
      71           0 :   struct AuditorDelState *ds = cls;
      72             : 
      73           0 :   ds->dh = NULL;
      74           0 :   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           0 :   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           0 : auditor_del_run (void *cls,
     101             :                  const struct TALER_TESTING_Command *cmd,
     102             :                  struct TALER_TESTING_Interpreter *is)
     103             : {
     104           0 :   struct AuditorDelState *ds = cls;
     105             :   struct TALER_MasterSignatureP master_sig;
     106             :   struct GNUNET_TIME_Timestamp now;
     107             : 
     108             :   (void) cmd;
     109           0 :   now = GNUNET_TIME_timestamp_get ();
     110           0 :   ds->is = is;
     111           0 :   if (ds->bad_sig)
     112             :   {
     113           0 :     memset (&master_sig,
     114             :             42,
     115             :             sizeof (master_sig));
     116             :   }
     117             :   else
     118             :   {
     119           0 :     TALER_exchange_offline_auditor_del_sign (&is->auditor_pub,
     120             :                                              now,
     121           0 :                                              &is->master_priv,
     122             :                                              &master_sig);
     123             :   }
     124           0 :   ds->dh = TALER_EXCHANGE_management_disable_auditor (
     125             :     is->ctx,
     126           0 :     is->exchange_url,
     127           0 :     &is->auditor_pub,
     128             :     now,
     129             :     &master_sig,
     130             :     &auditor_del_cb,
     131             :     ds);
     132           0 :   if (NULL == ds->dh)
     133             :   {
     134           0 :     GNUNET_break (0);
     135           0 :     TALER_TESTING_interpreter_fail (is);
     136           0 :     return;
     137             :   }
     138             : }
     139             : 
     140             : 
     141             : /**
     142             :  * Free the state of a "auditor_del" CMD, and possibly cancel a
     143             :  * pending operation thereof.
     144             :  *
     145             :  * @param cls closure, must be a `struct AuditorDelState`.
     146             :  * @param cmd the command which is being cleaned up.
     147             :  */
     148             : static void
     149           0 : auditor_del_cleanup (void *cls,
     150             :                      const struct TALER_TESTING_Command *cmd)
     151             : {
     152           0 :   struct AuditorDelState *ds = cls;
     153             : 
     154           0 :   if (NULL != ds->dh)
     155             :   {
     156           0 :     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
     157             :                 "Command %u (%s) did not complete\n",
     158             :                 ds->is->ip,
     159             :                 cmd->label);
     160           0 :     TALER_EXCHANGE_management_disable_auditor_cancel (ds->dh);
     161           0 :     ds->dh = NULL;
     162             :   }
     163           0 :   GNUNET_free (ds);
     164           0 : }
     165             : 
     166             : 
     167             : struct TALER_TESTING_Command
     168           0 : TALER_TESTING_cmd_auditor_del (const char *label,
     169             :                                unsigned int expected_http_status,
     170             :                                bool bad_sig)
     171             : {
     172             :   struct AuditorDelState *ds;
     173             : 
     174           0 :   ds = GNUNET_new (struct AuditorDelState);
     175           0 :   ds->expected_response_code = expected_http_status;
     176           0 :   ds->bad_sig = bad_sig;
     177             :   {
     178           0 :     struct TALER_TESTING_Command cmd = {
     179             :       .cls = ds,
     180             :       .label = label,
     181             :       .run = &auditor_del_run,
     182             :       .cleanup = &auditor_del_cleanup
     183             :     };
     184             : 
     185           0 :     return cmd;
     186             :   }
     187             : }
     188             : 
     189             : 
     190             : /* end of testing_api_cmd_auditor_del.c */

Generated by: LCOV version 1.14