LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_wire_del.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 70.2 % 47 33
Test Date: 2025-12-28 14:06:02 Functions: 100.0 % 4 4

            Line data    Source code
       1              : /*
       2              :   This file is part of TALER
       3              :   Copyright (C) 2020, 2023 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_wire_del.c
      21              :  * @brief command for testing POST to /management/wire
      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 "wire_del" CMD.
      34              :  */
      35              : struct WireDelState
      36              : {
      37              : 
      38              :   /**
      39              :    * Wire enable handle while operation is running.
      40              :    */
      41              :   struct TALER_EXCHANGE_ManagementWireDisableHandle *dh;
      42              : 
      43              :   /**
      44              :    * Our interpreter.
      45              :    */
      46              :   struct TALER_TESTING_Interpreter *is;
      47              : 
      48              :   /**
      49              :    * Account to del.
      50              :    */
      51              :   struct TALER_FullPayto payto_uri;
      52              : 
      53              :   /**
      54              :    * Expected HTTP response code.
      55              :    */
      56              :   unsigned int expected_response_code;
      57              : 
      58              :   /**
      59              :    * Should we make the request with a bad master_sig signature?
      60              :    */
      61              :   bool bad_sig;
      62              : };
      63              : 
      64              : 
      65              : /**
      66              :  * Callback to analyze the /management/wire response, just used to check
      67              :  * if the response code is acceptable.
      68              :  *
      69              :  * @param cls closure.
      70              :  * @param wdr response details
      71              :  */
      72              : static void
      73            6 : wire_del_cb (void *cls,
      74              :              const struct TALER_EXCHANGE_ManagementWireDisableResponse *wdr)
      75              : {
      76            6 :   struct WireDelState *ds = cls;
      77            6 :   const struct TALER_EXCHANGE_HttpResponse *hr = &wdr->hr;
      78              : 
      79            6 :   ds->dh = NULL;
      80            6 :   if (ds->expected_response_code != hr->http_status)
      81              :   {
      82            0 :     TALER_TESTING_unexpected_status (ds->is,
      83              :                                      hr->http_status,
      84              :                                      ds->expected_response_code);
      85              : 
      86            0 :     return;
      87              :   }
      88            6 :   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            6 : wire_del_run (void *cls,
     101              :               const struct TALER_TESTING_Command *cmd,
     102              :               struct TALER_TESTING_Interpreter *is)
     103              : {
     104            6 :   struct WireDelState *ds = cls;
     105              :   struct TALER_MasterSignatureP master_sig;
     106              :   struct GNUNET_TIME_Timestamp now;
     107              :   const char *exchange_url;
     108              : 
     109              :   (void) cmd;
     110              :   {
     111              :     const struct TALER_TESTING_Command *exchange_cmd;
     112              : 
     113            6 :     exchange_cmd = TALER_TESTING_interpreter_get_command (is,
     114              :                                                           "exchange");
     115            6 :     if (NULL == exchange_cmd)
     116              :     {
     117            0 :       GNUNET_break (0);
     118            0 :       TALER_TESTING_interpreter_fail (is);
     119            0 :       return;
     120              :     }
     121            6 :     GNUNET_assert (GNUNET_OK ==
     122              :                    TALER_TESTING_get_trait_exchange_url (exchange_cmd,
     123              :                                                          &exchange_url));
     124              :   }
     125            6 :   now = GNUNET_TIME_timestamp_get ();
     126            6 :   ds->is = is;
     127            6 :   if (ds->bad_sig)
     128              :   {
     129            2 :     memset (&master_sig,
     130              :             42,
     131              :             sizeof (master_sig));
     132              :   }
     133              :   else
     134              :   {
     135              :     const struct TALER_TESTING_Command *exchange_cmd;
     136              :     const struct TALER_MasterPrivateKeyP *master_priv;
     137              : 
     138            4 :     exchange_cmd = TALER_TESTING_interpreter_get_command (is,
     139              :                                                           "exchange");
     140            4 :     if (NULL == exchange_cmd)
     141              :     {
     142            0 :       GNUNET_break (0);
     143            0 :       TALER_TESTING_interpreter_fail (is);
     144            0 :       return;
     145              :     }
     146            4 :     GNUNET_assert (GNUNET_OK ==
     147              :                    TALER_TESTING_get_trait_master_priv (exchange_cmd,
     148              :                                                         &master_priv));
     149            4 :     TALER_exchange_offline_wire_del_sign (ds->payto_uri,
     150              :                                           now,
     151              :                                           master_priv,
     152              :                                           &master_sig);
     153              :   }
     154            6 :   ds->dh = TALER_EXCHANGE_management_disable_wire (
     155              :     TALER_TESTING_interpreter_get_context (is),
     156              :     exchange_url,
     157              :     ds->payto_uri,
     158              :     now,
     159              :     &master_sig,
     160              :     &wire_del_cb,
     161              :     ds);
     162            6 :   if (NULL == ds->dh)
     163              :   {
     164            0 :     GNUNET_break (0);
     165            0 :     TALER_TESTING_interpreter_fail (is);
     166            0 :     return;
     167              :   }
     168              : }
     169              : 
     170              : 
     171              : /**
     172              :  * Free the state of a "wire_del" CMD, and possibly cancel a
     173              :  * pending operation thereof.
     174              :  *
     175              :  * @param cls closure, must be a `struct WireDelState`.
     176              :  * @param cmd the command which is being cleaned up.
     177              :  */
     178              : static void
     179            6 : wire_del_cleanup (void *cls,
     180              :                   const struct TALER_TESTING_Command *cmd)
     181              : {
     182            6 :   struct WireDelState *ds = cls;
     183              : 
     184            6 :   if (NULL != ds->dh)
     185              :   {
     186            0 :     TALER_TESTING_command_incomplete (ds->is,
     187              :                                       cmd->label);
     188            0 :     TALER_EXCHANGE_management_disable_wire_cancel (ds->dh);
     189            0 :     ds->dh = NULL;
     190              :   }
     191            6 :   GNUNET_free (ds);
     192            6 : }
     193              : 
     194              : 
     195              : struct TALER_TESTING_Command
     196            6 : TALER_TESTING_cmd_wire_del (const char *label,
     197              :                             struct TALER_FullPayto payto_uri,
     198              :                             unsigned int expected_http_status,
     199              :                             bool bad_sig)
     200              : {
     201              :   struct WireDelState *ds;
     202              : 
     203            6 :   ds = GNUNET_new (struct WireDelState);
     204            6 :   ds->expected_response_code = expected_http_status;
     205            6 :   ds->bad_sig = bad_sig;
     206            6 :   ds->payto_uri = payto_uri;
     207              :   {
     208            6 :     struct TALER_TESTING_Command cmd = {
     209              :       .cls = ds,
     210              :       .label = label,
     211              :       .run = &wire_del_run,
     212              :       .cleanup = &wire_del_cleanup
     213              :     };
     214              : 
     215            6 :     return cmd;
     216              :   }
     217              : }
     218              : 
     219              : 
     220              : /* end of testing_api_cmd_wire_del.c */
        

Generated by: LCOV version 2.0-1