exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

testing_api_cmd_auditor_del.c (5693B)


      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 "taler/platform.h"
     25 #include "taler/taler_json_lib.h"
     26 #include <gnunet/gnunet_curl_lib.h>
     27 #include "taler/taler_testing_lib.h"
     28 #include "taler/taler_signatures.h"
     29 #include "taler/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 adr response details
     66  */
     67 static void
     68 auditor_del_cb (
     69   void *cls,
     70   const struct TALER_EXCHANGE_ManagementAuditorDisableResponse *adr)
     71 
     72 {
     73   struct AuditorDelState *ds = cls;
     74   const struct TALER_EXCHANGE_HttpResponse *hr = &adr->hr;
     75 
     76   ds->dh = NULL;
     77   if (ds->expected_response_code != hr->http_status)
     78   {
     79     TALER_TESTING_unexpected_status (ds->is,
     80                                      hr->http_status,
     81                                      ds->expected_response_code);
     82     return;
     83   }
     84   TALER_TESTING_interpreter_next (ds->is);
     85 }
     86 
     87 
     88 /**
     89  * Run the command.
     90  *
     91  * @param cls closure.
     92  * @param cmd the command to execute.
     93  * @param is the interpreter state.
     94  */
     95 static void
     96 auditor_del_run (void *cls,
     97                  const struct TALER_TESTING_Command *cmd,
     98                  struct TALER_TESTING_Interpreter *is)
     99 {
    100   struct AuditorDelState *ds = cls;
    101   struct TALER_MasterSignatureP master_sig;
    102   struct GNUNET_TIME_Timestamp now;
    103   const struct TALER_AuditorPublicKeyP *auditor_pub;
    104   const struct TALER_TESTING_Command *auditor_cmd;
    105   const struct TALER_TESTING_Command *exchange_cmd;
    106   const char *exchange_url;
    107 
    108   (void) cmd;
    109   now = GNUNET_TIME_timestamp_get ();
    110   ds->is = is;
    111   auditor_cmd = TALER_TESTING_interpreter_get_command (is,
    112                                                        "auditor");
    113   if (NULL == auditor_cmd)
    114   {
    115     GNUNET_break (0);
    116     TALER_TESTING_interpreter_fail (is);
    117     return;
    118   }
    119   GNUNET_assert (GNUNET_OK ==
    120                  TALER_TESTING_get_trait_auditor_pub (auditor_cmd,
    121                                                       &auditor_pub));
    122   exchange_cmd = TALER_TESTING_interpreter_get_command (is,
    123                                                         "exchange");
    124   if (NULL == exchange_cmd)
    125   {
    126     GNUNET_break (0);
    127     TALER_TESTING_interpreter_fail (is);
    128     return;
    129   }
    130   GNUNET_assert (GNUNET_OK ==
    131                  TALER_TESTING_get_trait_exchange_url (exchange_cmd,
    132                                                        &exchange_url));
    133   if (ds->bad_sig)
    134   {
    135     memset (&master_sig,
    136             42,
    137             sizeof (master_sig));
    138   }
    139   else
    140   {
    141     const struct TALER_MasterPrivateKeyP *master_priv;
    142 
    143     GNUNET_assert (GNUNET_OK ==
    144                    TALER_TESTING_get_trait_master_priv (exchange_cmd,
    145                                                         &master_priv));
    146     TALER_exchange_offline_auditor_del_sign (auditor_pub,
    147                                              now,
    148                                              master_priv,
    149                                              &master_sig);
    150   }
    151   ds->dh = TALER_EXCHANGE_management_disable_auditor (
    152     TALER_TESTING_interpreter_get_context (is),
    153     exchange_url,
    154     auditor_pub,
    155     now,
    156     &master_sig,
    157     &auditor_del_cb,
    158     ds);
    159   if (NULL == ds->dh)
    160   {
    161     GNUNET_break (0);
    162     TALER_TESTING_interpreter_fail (is);
    163     return;
    164   }
    165 }
    166 
    167 
    168 /**
    169  * Free the state of a "auditor_del" CMD, and possibly cancel a
    170  * pending operation thereof.
    171  *
    172  * @param cls closure, must be a `struct AuditorDelState`.
    173  * @param cmd the command which is being cleaned up.
    174  */
    175 static void
    176 auditor_del_cleanup (void *cls,
    177                      const struct TALER_TESTING_Command *cmd)
    178 {
    179   struct AuditorDelState *ds = cls;
    180 
    181   if (NULL != ds->dh)
    182   {
    183     TALER_TESTING_command_incomplete (ds->is,
    184                                       cmd->label);
    185     TALER_EXCHANGE_management_disable_auditor_cancel (ds->dh);
    186     ds->dh = NULL;
    187   }
    188   GNUNET_free (ds);
    189 }
    190 
    191 
    192 struct TALER_TESTING_Command
    193 TALER_TESTING_cmd_auditor_del (const char *label,
    194                                unsigned int expected_http_status,
    195                                bool bad_sig)
    196 {
    197   struct AuditorDelState *ds;
    198 
    199   ds = GNUNET_new (struct AuditorDelState);
    200   ds->expected_response_code = expected_http_status;
    201   ds->bad_sig = bad_sig;
    202   {
    203     struct TALER_TESTING_Command cmd = {
    204       .cls = ds,
    205       .label = label,
    206       .run = &auditor_del_run,
    207       .cleanup = &auditor_del_cleanup
    208     };
    209 
    210     return cmd;
    211   }
    212 }
    213 
    214 
    215 /* end of testing_api_cmd_auditor_del.c */