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 (5747B)


      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/taler_json_lib.h"
     25 #include <gnunet/gnunet_curl_lib.h>
     26 #include "taler/taler_testing_lib.h"
     27 
     28 
     29 /**
     30  * State for a "auditor_del" CMD.
     31  */
     32 struct AuditorDelState
     33 {
     34 
     35   /**
     36    * Auditor enable handle while operation is running.
     37    */
     38   struct TALER_EXCHANGE_PostManagementAuditorsDisableHandle *dh;
     39 
     40   /**
     41    * Our interpreter.
     42    */
     43   struct TALER_TESTING_Interpreter *is;
     44 
     45   /**
     46    * Expected HTTP response code.
     47    */
     48   unsigned int expected_response_code;
     49 
     50   /**
     51    * Should we make the request with a bad master_sig signature?
     52    */
     53   bool bad_sig;
     54 };
     55 
     56 
     57 /**
     58  * Callback to analyze the /management/auditors response, just used to check
     59  * if the response code is acceptable.
     60  *
     61  * @param cls closure.
     62  * @param adr response details
     63  */
     64 static void
     65 auditor_del_cb (
     66   void *cls,
     67   const struct TALER_EXCHANGE_PostManagementAuditorsDisableResponse *adr)
     68 
     69 {
     70   struct AuditorDelState *ds = cls;
     71   const struct TALER_EXCHANGE_HttpResponse *hr = &adr->hr;
     72 
     73   ds->dh = NULL;
     74   if (ds->expected_response_code != hr->http_status)
     75   {
     76     TALER_TESTING_unexpected_status (ds->is,
     77                                      hr->http_status,
     78                                      ds->expected_response_code);
     79     return;
     80   }
     81   TALER_TESTING_interpreter_next (ds->is);
     82 }
     83 
     84 
     85 /**
     86  * Run the command.
     87  *
     88  * @param cls closure.
     89  * @param cmd the command to execute.
     90  * @param is the interpreter state.
     91  */
     92 static void
     93 auditor_del_run (void *cls,
     94                  const struct TALER_TESTING_Command *cmd,
     95                  struct TALER_TESTING_Interpreter *is)
     96 {
     97   struct AuditorDelState *ds = cls;
     98   struct TALER_MasterSignatureP master_sig;
     99   struct GNUNET_TIME_Timestamp now;
    100   const struct TALER_AuditorPublicKeyP *auditor_pub;
    101   const struct TALER_TESTING_Command *auditor_cmd;
    102   const struct TALER_TESTING_Command *exchange_cmd;
    103   const char *exchange_url;
    104 
    105   (void) cmd;
    106   now = GNUNET_TIME_timestamp_get ();
    107   ds->is = is;
    108   auditor_cmd = TALER_TESTING_interpreter_get_command (is,
    109                                                        "auditor");
    110   if (NULL == auditor_cmd)
    111   {
    112     GNUNET_break (0);
    113     TALER_TESTING_interpreter_fail (is);
    114     return;
    115   }
    116   GNUNET_assert (GNUNET_OK ==
    117                  TALER_TESTING_get_trait_auditor_pub (auditor_cmd,
    118                                                       &auditor_pub));
    119   exchange_cmd = TALER_TESTING_interpreter_get_command (is,
    120                                                         "exchange");
    121   if (NULL == exchange_cmd)
    122   {
    123     GNUNET_break (0);
    124     TALER_TESTING_interpreter_fail (is);
    125     return;
    126   }
    127   GNUNET_assert (GNUNET_OK ==
    128                  TALER_TESTING_get_trait_exchange_url (exchange_cmd,
    129                                                        &exchange_url));
    130   if (ds->bad_sig)
    131   {
    132     memset (&master_sig,
    133             42,
    134             sizeof (master_sig));
    135   }
    136   else
    137   {
    138     const struct TALER_MasterPrivateKeyP *master_priv;
    139 
    140     GNUNET_assert (GNUNET_OK ==
    141                    TALER_TESTING_get_trait_master_priv (exchange_cmd,
    142                                                         &master_priv));
    143     TALER_exchange_offline_auditor_del_sign (auditor_pub,
    144                                              now,
    145                                              master_priv,
    146                                              &master_sig);
    147   }
    148   ds->dh = TALER_EXCHANGE_post_management_auditors_disable_create (
    149     TALER_TESTING_interpreter_get_context (is),
    150     exchange_url,
    151     auditor_pub,
    152     now,
    153     &master_sig);
    154   if (NULL == ds->dh)
    155   {
    156     GNUNET_break (0);
    157     TALER_TESTING_interpreter_fail (is);
    158     return;
    159   }
    160   TALER_EXCHANGE_post_management_auditors_disable_start (ds->dh, &auditor_del_cb
    161                                                          , ds);
    162 }
    163 
    164 
    165 /**
    166  * Free the state of a "auditor_del" CMD, and possibly cancel a
    167  * pending operation thereof.
    168  *
    169  * @param cls closure, must be a `struct AuditorDelState`.
    170  * @param cmd the command which is being cleaned up.
    171  */
    172 static void
    173 auditor_del_cleanup (void *cls,
    174                      const struct TALER_TESTING_Command *cmd)
    175 {
    176   struct AuditorDelState *ds = cls;
    177 
    178   if (NULL != ds->dh)
    179   {
    180     TALER_TESTING_command_incomplete (ds->is,
    181                                       cmd->label);
    182     TALER_EXCHANGE_post_management_auditors_disable_cancel (ds->dh);
    183     ds->dh = NULL;
    184   }
    185   GNUNET_free (ds);
    186 }
    187 
    188 
    189 struct TALER_TESTING_Command
    190 TALER_TESTING_cmd_auditor_del (const char *label,
    191                                unsigned int expected_http_status,
    192                                bool bad_sig)
    193 {
    194   struct AuditorDelState *ds;
    195 
    196   ds = GNUNET_new (struct AuditorDelState);
    197   ds->expected_response_code = expected_http_status;
    198   ds->bad_sig = bad_sig;
    199   {
    200     struct TALER_TESTING_Command cmd = {
    201       .cls = ds,
    202       .label = label,
    203       .run = &auditor_del_run,
    204       .cleanup = &auditor_del_cleanup
    205     };
    206 
    207     return cmd;
    208   }
    209 }
    210 
    211 
    212 /* end of testing_api_cmd_auditor_del.c */