LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_auditor_del.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 70.8 % 48 34
Test Date: 2026-04-14 15:39:31 Functions: 100.0 % 4 4

            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 "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            8 : auditor_del_cb (
      66              :   void *cls,
      67              :   const struct TALER_EXCHANGE_PostManagementAuditorsDisableResponse *adr)
      68              : 
      69              : {
      70            8 :   struct AuditorDelState *ds = cls;
      71            8 :   const struct TALER_EXCHANGE_HttpResponse *hr = &adr->hr;
      72              : 
      73            8 :   ds->dh = NULL;
      74            8 :   if (ds->expected_response_code != hr->http_status)
      75              :   {
      76            0 :     TALER_TESTING_unexpected_status (ds->is,
      77              :                                      hr->http_status,
      78              :                                      ds->expected_response_code);
      79            0 :     return;
      80              :   }
      81            8 :   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            8 : auditor_del_run (void *cls,
      94              :                  const struct TALER_TESTING_Command *cmd,
      95              :                  struct TALER_TESTING_Interpreter *is)
      96              : {
      97            8 :   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            8 :   now = GNUNET_TIME_timestamp_get ();
     107            8 :   ds->is = is;
     108            8 :   auditor_cmd = TALER_TESTING_interpreter_get_command (is,
     109              :                                                        "auditor");
     110            8 :   if (NULL == auditor_cmd)
     111              :   {
     112            0 :     GNUNET_break (0);
     113            0 :     TALER_TESTING_interpreter_fail (is);
     114            0 :     return;
     115              :   }
     116            8 :   GNUNET_assert (GNUNET_OK ==
     117              :                  TALER_TESTING_get_trait_auditor_pub (auditor_cmd,
     118              :                                                       &auditor_pub));
     119            8 :   exchange_cmd = TALER_TESTING_interpreter_get_command (is,
     120              :                                                         "exchange");
     121            8 :   if (NULL == exchange_cmd)
     122              :   {
     123            0 :     GNUNET_break (0);
     124            0 :     TALER_TESTING_interpreter_fail (is);
     125            0 :     return;
     126              :   }
     127            8 :   GNUNET_assert (GNUNET_OK ==
     128              :                  TALER_TESTING_get_trait_exchange_url (exchange_cmd,
     129              :                                                        &exchange_url));
     130            8 :   if (ds->bad_sig)
     131              :   {
     132            2 :     memset (&master_sig,
     133              :             42,
     134              :             sizeof (master_sig));
     135              :   }
     136              :   else
     137              :   {
     138              :     const struct TALER_MasterPrivateKeyP *master_priv;
     139              : 
     140            6 :     GNUNET_assert (GNUNET_OK ==
     141              :                    TALER_TESTING_get_trait_master_priv (exchange_cmd,
     142              :                                                         &master_priv));
     143            6 :     TALER_exchange_offline_auditor_del_sign (auditor_pub,
     144              :                                              now,
     145              :                                              master_priv,
     146              :                                              &master_sig);
     147              :   }
     148            8 :   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            8 :   if (NULL == ds->dh)
     155              :   {
     156            0 :     GNUNET_break (0);
     157            0 :     TALER_TESTING_interpreter_fail (is);
     158            0 :     return;
     159              :   }
     160            8 :   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            8 : auditor_del_cleanup (void *cls,
     174              :                      const struct TALER_TESTING_Command *cmd)
     175              : {
     176            8 :   struct AuditorDelState *ds = cls;
     177              : 
     178            8 :   if (NULL != ds->dh)
     179              :   {
     180            0 :     TALER_TESTING_command_incomplete (ds->is,
     181              :                                       cmd->label);
     182            0 :     TALER_EXCHANGE_post_management_auditors_disable_cancel (ds->dh);
     183            0 :     ds->dh = NULL;
     184              :   }
     185            8 :   GNUNET_free (ds);
     186            8 : }
     187              : 
     188              : 
     189              : struct TALER_TESTING_Command
     190            8 : 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            8 :   ds = GNUNET_new (struct AuditorDelState);
     197            8 :   ds->expected_response_code = expected_http_status;
     198            8 :   ds->bad_sig = bad_sig;
     199              :   {
     200            8 :     struct TALER_TESTING_Command cmd = {
     201              :       .cls = ds,
     202              :       .label = label,
     203              :       .run = &auditor_del_run,
     204              :       .cleanup = &auditor_del_cleanup
     205              :     };
     206              : 
     207            8 :     return cmd;
     208              :   }
     209              : }
     210              : 
     211              : 
     212              : /* end of testing_api_cmd_auditor_del.c */
        

Generated by: LCOV version 2.0-1