LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_auditor_add_denom_sig.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 0 58 0.0 %
Date: 2021-08-30 06:43:37 Functions: 0 5 0.0 %
Legend: Lines: hit not hit

          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 hr HTTP response details
      71             :  */
      72             : static void
      73           0 : denom_sig_add_cb (void *cls,
      74             :                   const struct TALER_EXCHANGE_HttpResponse *hr)
      75             : {
      76           0 :   struct AuditorAddDenomSigState *ds = cls;
      77             : 
      78           0 :   ds->dh = NULL;
      79           0 :   if (ds->expected_response_code != hr->http_status)
      80             :   {
      81           0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
      82             :                 "Unexpected response code %u to command %s in %s:%u\n",
      83             :                 hr->http_status,
      84             :                 ds->is->commands[ds->is->ip].label,
      85             :                 __FILE__,
      86             :                 __LINE__);
      87           0 :     json_dumpf (hr->reply,
      88             :                 stderr,
      89             :                 0);
      90           0 :     TALER_TESTING_interpreter_fail (ds->is);
      91           0 :     return;
      92             :   }
      93           0 :   TALER_TESTING_interpreter_next (ds->is);
      94             : }
      95             : 
      96             : 
      97             : /**
      98             :  * Run the command.
      99             :  *
     100             :  * @param cls closure.
     101             :  * @param cmd the command to execute.
     102             :  * @param is the interpreter state.
     103             :  */
     104             : static void
     105           0 : auditor_add_run (void *cls,
     106             :                  const struct TALER_TESTING_Command *cmd,
     107             :                  struct TALER_TESTING_Interpreter *is)
     108             : {
     109           0 :   struct AuditorAddDenomSigState *ds = cls;
     110             :   struct TALER_AuditorSignatureP auditor_sig;
     111             :   struct GNUNET_HashCode h_denom_pub;
     112             :   const struct TALER_EXCHANGE_DenomPublicKey *dk;
     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             : 
     122           0 :     if (NULL == denom_cmd)
     123             :     {
     124           0 :       GNUNET_break (0);
     125           0 :       TALER_TESTING_interpreter_fail (is);
     126           0 :       return;
     127             :     }
     128           0 :     GNUNET_assert (GNUNET_OK ==
     129             :                    TALER_TESTING_get_trait_denom_pub (denom_cmd,
     130             :                                                       0,
     131             :                                                       &dk));
     132             :   }
     133           0 :   ds->is = is;
     134           0 :   if (ds->bad_sig)
     135             :   {
     136           0 :     memset (&auditor_sig,
     137             :             42,
     138             :             sizeof (auditor_sig));
     139             :   }
     140             :   else
     141             :   {
     142             :     struct TALER_MasterPublicKeyP master_pub;
     143             : 
     144           0 :     GNUNET_CRYPTO_eddsa_key_get_public (&is->master_priv.eddsa_priv,
     145             :                                         &master_pub.eddsa_pub);
     146           0 :     TALER_auditor_denom_validity_sign (
     147           0 :       is->auditor_url,
     148           0 :       &dk->h_key,
     149             :       &master_pub,
     150           0 :       dk->valid_from,
     151           0 :       dk->withdraw_valid_until,
     152           0 :       dk->expire_deposit,
     153           0 :       dk->expire_legal,
     154           0 :       &dk->value,
     155           0 :       &dk->fee_withdraw,
     156           0 :       &dk->fee_deposit,
     157           0 :       &dk->fee_refresh,
     158           0 :       &dk->fee_refund,
     159           0 :       &is->auditor_priv,
     160             :       &auditor_sig);
     161             :   }
     162           0 :   ds->dh = TALER_EXCHANGE_add_auditor_denomination (
     163             :     is->ctx,
     164           0 :     is->exchange_url,
     165             :     &h_denom_pub,
     166           0 :     &is->auditor_pub,
     167             :     &auditor_sig,
     168             :     &denom_sig_add_cb,
     169             :     ds);
     170           0 :   if (NULL == ds->dh)
     171             :   {
     172           0 :     GNUNET_break (0);
     173           0 :     TALER_TESTING_interpreter_fail (is);
     174           0 :     return;
     175             :   }
     176             : }
     177             : 
     178             : 
     179             : /**
     180             :  * Free the state of a "auditor_add" CMD, and possibly cancel a
     181             :  * pending operation thereof.
     182             :  *
     183             :  * @param cls closure, must be a `struct AuditorAddDenomSigState`.
     184             :  * @param cmd the command which is being cleaned up.
     185             :  */
     186             : static void
     187           0 : auditor_add_cleanup (void *cls,
     188             :                      const struct TALER_TESTING_Command *cmd)
     189             : {
     190           0 :   struct AuditorAddDenomSigState *ds = cls;
     191             : 
     192           0 :   if (NULL != ds->dh)
     193             :   {
     194           0 :     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
     195             :                 "Command %u (%s) did not complete\n",
     196             :                 ds->is->ip,
     197             :                 cmd->label);
     198           0 :     TALER_EXCHANGE_add_auditor_denomination_cancel (ds->dh);
     199           0 :     ds->dh = NULL;
     200             :   }
     201           0 :   GNUNET_free (ds);
     202           0 : }
     203             : 
     204             : 
     205             : /**
     206             :  * Offer internal data from a "auditor_add" CMD, to other commands.
     207             :  *
     208             :  * @param cls closure.
     209             :  * @param[out] ret result.
     210             :  * @param trait name of the trait.
     211             :  * @param index index number of the object to offer.
     212             :  *
     213             :  * @return #GNUNET_OK on success.
     214             :  */
     215             : static int
     216           0 : auditor_add_traits (void *cls,
     217             :                     const void **ret,
     218             :                     const char *trait,
     219             :                     unsigned int index)
     220             : {
     221           0 :   return GNUNET_NO;
     222             : }
     223             : 
     224             : 
     225             : struct TALER_TESTING_Command
     226           0 : TALER_TESTING_cmd_auditor_add_denom_sig (const char *label,
     227             :                                          unsigned int expected_http_status,
     228             :                                          const char *denom_ref,
     229             :                                          bool bad_sig)
     230             : {
     231             :   struct AuditorAddDenomSigState *ds;
     232             : 
     233           0 :   ds = GNUNET_new (struct AuditorAddDenomSigState);
     234           0 :   ds->expected_response_code = expected_http_status;
     235           0 :   ds->bad_sig = bad_sig;
     236           0 :   ds->denom_ref = denom_ref;
     237             :   {
     238           0 :     struct TALER_TESTING_Command cmd = {
     239             :       .cls = ds,
     240             :       .label = label,
     241             :       .run = &auditor_add_run,
     242             :       .cleanup = &auditor_add_cleanup,
     243             :       .traits = &auditor_add_traits
     244             :     };
     245             : 
     246           0 :     return cmd;
     247             :   }
     248             : }
     249             : 
     250             : 
     251             : /* end of testing_api_cmd_auditor_add_denom_sig.c */

Generated by: LCOV version 1.14