LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_auditor_add_denom_sig.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 62 0.0 %
Date: 2025-06-05 21:03:14 Functions: 0 4 0.0 %

          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_denom_sig.c
      21             :  * @brief command for testing POST to /auditor/$AUDITOR_PUB/$H_DENOM_PUB
      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 AuditorAddDenomSigState
      36             : {
      37             : 
      38             :   /**
      39             :    * Auditor enable handle while operation is running.
      40             :    */
      41             :   struct TALER_EXCHANGE_AuditorAddDenominationHandle *dh;
      42             : 
      43             :   /**
      44             :    * Our interpreter.
      45             :    */
      46             :   struct TALER_TESTING_Interpreter *is;
      47             : 
      48             :   /**
      49             :    * Reference to command identifying denomination to add.
      50             :    */
      51             :   const char *denom_ref;
      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/auditor response, just used to check
      67             :  * if the response code is acceptable.
      68             :  *
      69             :  * @param cls closure.
      70             :  * @param adr response details
      71             :  */
      72             : static void
      73           0 : denom_sig_add_cb (
      74             :   void *cls,
      75             :   const struct TALER_EXCHANGE_AuditorAddDenominationResponse *adr)
      76             : {
      77           0 :   struct AuditorAddDenomSigState *ds = cls;
      78           0 :   const struct TALER_EXCHANGE_HttpResponse *hr = &adr->hr;
      79             : 
      80           0 :   ds->dh = NULL;
      81           0 :   if (ds->expected_response_code != hr->http_status)
      82             :   {
      83           0 :     TALER_TESTING_unexpected_status (ds->is,
      84             :                                      hr->http_status,
      85             :                                      ds->expected_response_code);
      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 AuditorAddDenomSigState *ds = cls;
     105             :   struct TALER_AuditorSignatureP auditor_sig;
     106             :   struct TALER_DenominationHashP h_denom_pub;
     107             :   const struct TALER_EXCHANGE_DenomPublicKey *dk;
     108             :   const struct TALER_AuditorPublicKeyP *auditor_pub;
     109             :   const struct TALER_TESTING_Command *auditor_cmd;
     110             :   const struct TALER_TESTING_Command *exchange_cmd;
     111             :   const char *exchange_url;
     112             :   const char *auditor_url;
     113             : 
     114             :   (void) cmd;
     115             :   /* Get denom pub from trait */
     116             :   {
     117             :     const struct TALER_TESTING_Command *denom_cmd;
     118             : 
     119           0 :     denom_cmd = TALER_TESTING_interpreter_lookup_command (is,
     120             :                                                           ds->denom_ref);
     121           0 :     if (NULL == denom_cmd)
     122             :     {
     123           0 :       GNUNET_break (0);
     124           0 :       TALER_TESTING_interpreter_fail (is);
     125           0 :       return;
     126             :     }
     127           0 :     GNUNET_assert (GNUNET_OK ==
     128             :                    TALER_TESTING_get_trait_denom_pub (denom_cmd,
     129             :                                                       0,
     130             :                                                       &dk));
     131             :   }
     132           0 :   ds->is = is;
     133           0 :   auditor_cmd = TALER_TESTING_interpreter_get_command (is,
     134             :                                                        "auditor");
     135           0 :   if (NULL == auditor_cmd)
     136             :   {
     137           0 :     GNUNET_break (0);
     138           0 :     TALER_TESTING_interpreter_fail (is);
     139           0 :     return;
     140             :   }
     141           0 :   GNUNET_assert (GNUNET_OK ==
     142             :                  TALER_TESTING_get_trait_auditor_pub (auditor_cmd,
     143             :                                                       &auditor_pub));
     144           0 :   GNUNET_assert (GNUNET_OK ==
     145             :                  TALER_TESTING_get_trait_auditor_url (auditor_cmd,
     146             :                                                       &auditor_url));
     147           0 :   exchange_cmd = TALER_TESTING_interpreter_get_command (is,
     148             :                                                         "exchange");
     149           0 :   if (NULL == exchange_cmd)
     150             :   {
     151           0 :     GNUNET_break (0);
     152           0 :     TALER_TESTING_interpreter_fail (is);
     153           0 :     return;
     154             :   }
     155           0 :   GNUNET_assert (GNUNET_OK ==
     156             :                  TALER_TESTING_get_trait_exchange_url (exchange_cmd,
     157             :                                                        &exchange_url));
     158           0 :   if (ds->bad_sig)
     159             :   {
     160           0 :     memset (&auditor_sig,
     161             :             42,
     162             :             sizeof (auditor_sig));
     163             :   }
     164             :   else
     165             :   {
     166             :     const struct TALER_MasterPublicKeyP *master_pub;
     167             :     const struct TALER_AuditorPrivateKeyP *auditor_priv;
     168             : 
     169           0 :     GNUNET_assert (GNUNET_OK ==
     170             :                    TALER_TESTING_get_trait_master_pub (exchange_cmd,
     171             :                                                        &master_pub));
     172           0 :     GNUNET_assert (GNUNET_OK ==
     173             :                    TALER_TESTING_get_trait_auditor_priv (auditor_cmd,
     174             :                                                          &auditor_priv));
     175           0 :     TALER_auditor_denom_validity_sign (
     176             :       auditor_url,
     177           0 :       &dk->h_key,
     178             :       master_pub,
     179           0 :       dk->valid_from,
     180           0 :       dk->withdraw_valid_until,
     181           0 :       dk->expire_deposit,
     182           0 :       dk->expire_legal,
     183           0 :       &dk->value,
     184           0 :       &dk->fees,
     185             :       auditor_priv,
     186             :       &auditor_sig);
     187             :   }
     188           0 :   ds->dh = TALER_EXCHANGE_add_auditor_denomination (
     189             :     TALER_TESTING_interpreter_get_context (is),
     190             :     exchange_url,
     191             :     &h_denom_pub,
     192             :     auditor_pub,
     193             :     &auditor_sig,
     194             :     &denom_sig_add_cb,
     195             :     ds);
     196           0 :   if (NULL == ds->dh)
     197             :   {
     198           0 :     GNUNET_break (0);
     199           0 :     TALER_TESTING_interpreter_fail (is);
     200           0 :     return;
     201             :   }
     202             : }
     203             : 
     204             : 
     205             : /**
     206             :  * Free the state of a "auditor_add" CMD, and possibly cancel a
     207             :  * pending operation thereof.
     208             :  *
     209             :  * @param cls closure, must be a `struct AuditorAddDenomSigState`.
     210             :  * @param cmd the command which is being cleaned up.
     211             :  */
     212             : static void
     213           0 : auditor_add_cleanup (void *cls,
     214             :                      const struct TALER_TESTING_Command *cmd)
     215             : {
     216           0 :   struct AuditorAddDenomSigState *ds = cls;
     217             : 
     218           0 :   if (NULL != ds->dh)
     219             :   {
     220           0 :     TALER_TESTING_command_incomplete (ds->is,
     221             :                                       cmd->label);
     222           0 :     TALER_EXCHANGE_add_auditor_denomination_cancel (ds->dh);
     223           0 :     ds->dh = NULL;
     224             :   }
     225           0 :   GNUNET_free (ds);
     226           0 : }
     227             : 
     228             : 
     229             : struct TALER_TESTING_Command
     230           0 : TALER_TESTING_cmd_auditor_add_denom_sig (const char *label,
     231             :                                          unsigned int expected_http_status,
     232             :                                          const char *denom_ref,
     233             :                                          bool bad_sig)
     234             : {
     235             :   struct AuditorAddDenomSigState *ds;
     236             : 
     237           0 :   ds = GNUNET_new (struct AuditorAddDenomSigState);
     238           0 :   ds->expected_response_code = expected_http_status;
     239           0 :   ds->bad_sig = bad_sig;
     240           0 :   ds->denom_ref = denom_ref;
     241             :   {
     242           0 :     struct TALER_TESTING_Command cmd = {
     243             :       .cls = ds,
     244             :       .label = label,
     245             :       .run = &auditor_add_run,
     246             :       .cleanup = &auditor_add_cleanup
     247             :     };
     248             : 
     249           0 :     return cmd;
     250             :   }
     251             : }
     252             : 
     253             : 
     254             : /* end of testing_api_cmd_auditor_add_denom_sig.c */

Generated by: LCOV version 1.16