LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_auditor_add.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 0 40 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_add.c
      21             :  * @brief command for testing /auditor_add.
      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_add" CMD.
      34             :  */
      35             : struct AuditorAddState
      36             : {
      37             : 
      38             :   /**
      39             :    * Auditor enable handle while operation is running.
      40             :    */
      41             :   struct TALER_EXCHANGE_ManagementAuditorEnableHandle *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_add_cb (void *cls,
      69             :                 const struct TALER_EXCHANGE_HttpResponse *hr)
      70             : {
      71           0 :   struct AuditorAddState *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_add_run (void *cls,
     101             :                  const struct TALER_TESTING_Command *cmd,
     102             :                  struct TALER_TESTING_Interpreter *is)
     103             : {
     104           0 :   struct AuditorAddState *ds = cls;
     105             :   struct GNUNET_TIME_Timestamp now;
     106             :   struct TALER_MasterSignatureP master_sig;
     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_add_sign (&is->auditor_pub,
     120           0 :                                              is->auditor_url,
     121             :                                              now,
     122           0 :                                              &is->master_priv,
     123             :                                              &master_sig);
     124             :   }
     125           0 :   ds->dh = TALER_EXCHANGE_management_enable_auditor (
     126             :     is->ctx,
     127           0 :     is->exchange_url,
     128           0 :     &is->auditor_pub,
     129           0 :     is->auditor_url,
     130             :     "test-case auditor", /* human-readable auditor name */
     131             :     now,
     132             :     &master_sig,
     133             :     &auditor_add_cb,
     134             :     ds);
     135           0 :   if (NULL == ds->dh)
     136             :   {
     137           0 :     GNUNET_break (0);
     138           0 :     TALER_TESTING_interpreter_fail (is);
     139           0 :     return;
     140             :   }
     141             : }
     142             : 
     143             : 
     144             : /**
     145             :  * Free the state of a "auditor_add" CMD, and possibly cancel a
     146             :  * pending operation thereof.
     147             :  *
     148             :  * @param cls closure, must be a `struct AuditorAddState`.
     149             :  * @param cmd the command which is being cleaned up.
     150             :  */
     151             : static void
     152           0 : auditor_add_cleanup (void *cls,
     153             :                      const struct TALER_TESTING_Command *cmd)
     154             : {
     155           0 :   struct AuditorAddState *ds = cls;
     156             : 
     157           0 :   if (NULL != ds->dh)
     158             :   {
     159           0 :     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
     160             :                 "Command %u (%s) did not complete\n",
     161             :                 ds->is->ip,
     162             :                 cmd->label);
     163           0 :     TALER_EXCHANGE_management_enable_auditor_cancel (ds->dh);
     164           0 :     ds->dh = NULL;
     165             :   }
     166           0 :   GNUNET_free (ds);
     167           0 : }
     168             : 
     169             : 
     170             : struct TALER_TESTING_Command
     171           0 : TALER_TESTING_cmd_auditor_add (const char *label,
     172             :                                unsigned int expected_http_status,
     173             :                                bool bad_sig)
     174             : {
     175             :   struct AuditorAddState *ds;
     176             : 
     177           0 :   ds = GNUNET_new (struct AuditorAddState);
     178           0 :   ds->expected_response_code = expected_http_status;
     179           0 :   ds->bad_sig = bad_sig;
     180             :   {
     181           0 :     struct TALER_TESTING_Command cmd = {
     182             :       .cls = ds,
     183             :       .label = label,
     184             :       .run = &auditor_add_run,
     185             :       .cleanup = &auditor_add_cleanup
     186             :     };
     187             : 
     188           0 :     return cmd;
     189             :   }
     190             : }
     191             : 
     192             : 
     193             : /* end of testing_api_cmd_auditor_add.c */

Generated by: LCOV version 1.14