LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_auditor_add_denom_sig.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 64 0
Test Date: 2026-04-14 15:39:31 Functions: 0.0 % 4 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 "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_add" CMD.
      31              :  */
      32              : struct AuditorAddDenomSigState
      33              : {
      34              : 
      35              :   /**
      36              :    * Auditor enable handle while operation is running.
      37              :    */
      38              :   struct TALER_EXCHANGE_PostAuditorsHandle *dh;
      39              : 
      40              :   /**
      41              :    * Our interpreter.
      42              :    */
      43              :   struct TALER_TESTING_Interpreter *is;
      44              : 
      45              :   /**
      46              :    * Reference to command identifying denomination to add.
      47              :    */
      48              :   const char *denom_ref;
      49              : 
      50              :   /**
      51              :    * Expected HTTP response code.
      52              :    */
      53              :   unsigned int expected_response_code;
      54              : 
      55              :   /**
      56              :    * Should we make the request with a bad master_sig signature?
      57              :    */
      58              :   bool bad_sig;
      59              : };
      60              : 
      61              : 
      62              : /**
      63              :  * Callback to analyze the /management/auditor response, just used to check
      64              :  * if the response code is acceptable.
      65              :  *
      66              :  * @param cls closure.
      67              :  * @param adr response details
      68              :  */
      69              : static void
      70            0 : denom_sig_add_cb (
      71              :   void *cls,
      72              :   const struct TALER_EXCHANGE_PostAuditorsResponse *adr)
      73              : {
      74            0 :   struct AuditorAddDenomSigState *ds = cls;
      75            0 :   const struct TALER_EXCHANGE_HttpResponse *hr = &adr->hr;
      76              : 
      77            0 :   ds->dh = NULL;
      78            0 :   if (ds->expected_response_code != hr->http_status)
      79              :   {
      80            0 :     TALER_TESTING_unexpected_status (ds->is,
      81              :                                      hr->http_status,
      82              :                                      ds->expected_response_code);
      83            0 :     return;
      84              :   }
      85            0 :   TALER_TESTING_interpreter_next (ds->is);
      86              : }
      87              : 
      88              : 
      89              : /**
      90              :  * Run the command.
      91              :  *
      92              :  * @param cls closure.
      93              :  * @param cmd the command to execute.
      94              :  * @param is the interpreter state.
      95              :  */
      96              : static void
      97            0 : auditor_add_run (void *cls,
      98              :                  const struct TALER_TESTING_Command *cmd,
      99              :                  struct TALER_TESTING_Interpreter *is)
     100              : {
     101            0 :   struct AuditorAddDenomSigState *ds = cls;
     102              :   struct TALER_AuditorSignatureP auditor_sig;
     103              :   const struct TALER_EXCHANGE_DenomPublicKey *dk;
     104              :   const struct TALER_AuditorPublicKeyP *auditor_pub;
     105              :   const struct TALER_TESTING_Command *auditor_cmd;
     106              :   const struct TALER_TESTING_Command *exchange_cmd;
     107              :   const char *exchange_url;
     108              :   const char *auditor_url;
     109              : 
     110              :   (void) cmd;
     111              :   /* Get denom pub from trait */
     112              :   {
     113              :     const struct TALER_TESTING_Command *denom_cmd;
     114              : 
     115            0 :     denom_cmd = TALER_TESTING_interpreter_lookup_command (is,
     116              :                                                           ds->denom_ref);
     117            0 :     if (NULL == denom_cmd)
     118              :     {
     119            0 :       GNUNET_break (0);
     120            0 :       TALER_TESTING_interpreter_fail (is);
     121            0 :       return;
     122              :     }
     123            0 :     GNUNET_assert (GNUNET_OK ==
     124              :                    TALER_TESTING_get_trait_denom_pub (denom_cmd,
     125              :                                                       0,
     126              :                                                       &dk));
     127              :   }
     128            0 :   ds->is = is;
     129            0 :   auditor_cmd = TALER_TESTING_interpreter_get_command (is,
     130              :                                                        "auditor");
     131            0 :   if (NULL == auditor_cmd)
     132              :   {
     133            0 :     GNUNET_break (0);
     134            0 :     TALER_TESTING_interpreter_fail (is);
     135            0 :     return;
     136              :   }
     137            0 :   GNUNET_assert (GNUNET_OK ==
     138              :                  TALER_TESTING_get_trait_auditor_pub (auditor_cmd,
     139              :                                                       &auditor_pub));
     140            0 :   GNUNET_assert (GNUNET_OK ==
     141              :                  TALER_TESTING_get_trait_auditor_url (auditor_cmd,
     142              :                                                       &auditor_url));
     143            0 :   exchange_cmd = TALER_TESTING_interpreter_get_command (is,
     144              :                                                         "exchange");
     145            0 :   if (NULL == exchange_cmd)
     146              :   {
     147            0 :     GNUNET_break (0);
     148            0 :     TALER_TESTING_interpreter_fail (is);
     149            0 :     return;
     150              :   }
     151            0 :   GNUNET_assert (GNUNET_OK ==
     152              :                  TALER_TESTING_get_trait_exchange_url (exchange_cmd,
     153              :                                                        &exchange_url));
     154            0 :   if (ds->bad_sig)
     155              :   {
     156            0 :     memset (&auditor_sig,
     157              :             42,
     158              :             sizeof (auditor_sig));
     159              :   }
     160              :   else
     161              :   {
     162              :     const struct TALER_MasterPublicKeyP *master_pub;
     163              :     const struct TALER_AuditorPrivateKeyP *auditor_priv;
     164              : 
     165            0 :     GNUNET_assert (GNUNET_OK ==
     166              :                    TALER_TESTING_get_trait_master_pub (exchange_cmd,
     167              :                                                        &master_pub));
     168            0 :     GNUNET_assert (GNUNET_OK ==
     169              :                    TALER_TESTING_get_trait_auditor_priv (auditor_cmd,
     170              :                                                          &auditor_priv));
     171            0 :     TALER_auditor_denom_validity_sign (
     172              :       auditor_url,
     173            0 :       &dk->h_key,
     174              :       master_pub,
     175            0 :       dk->valid_from,
     176            0 :       dk->withdraw_valid_until,
     177            0 :       dk->expire_deposit,
     178            0 :       dk->expire_legal,
     179            0 :       &dk->value,
     180            0 :       &dk->fees,
     181              :       auditor_priv,
     182              :       &auditor_sig);
     183              :   }
     184            0 :   ds->dh = TALER_EXCHANGE_post_auditors_create (
     185              :     TALER_TESTING_interpreter_get_context (is),
     186              :     exchange_url,
     187            0 :     &dk->h_key,
     188              :     auditor_pub,
     189              :     &auditor_sig);
     190            0 :   if (NULL == ds->dh)
     191              :   {
     192            0 :     GNUNET_break (0);
     193            0 :     TALER_TESTING_interpreter_fail (is);
     194            0 :     return;
     195              :   }
     196            0 :   GNUNET_assert (TALER_EC_NONE ==
     197              :                  TALER_EXCHANGE_post_auditors_start (ds->dh,
     198              :                                                      &denom_sig_add_cb,
     199              :                                                      ds));
     200              : }
     201              : 
     202              : 
     203              : /**
     204              :  * Free the state of a "auditor_add" CMD, and possibly cancel a
     205              :  * pending operation thereof.
     206              :  *
     207              :  * @param cls closure, must be a `struct AuditorAddDenomSigState`.
     208              :  * @param cmd the command which is being cleaned up.
     209              :  */
     210              : static void
     211            0 : auditor_add_cleanup (void *cls,
     212              :                      const struct TALER_TESTING_Command *cmd)
     213              : {
     214            0 :   struct AuditorAddDenomSigState *ds = cls;
     215              : 
     216            0 :   if (NULL != ds->dh)
     217              :   {
     218            0 :     TALER_TESTING_command_incomplete (ds->is,
     219              :                                       cmd->label);
     220            0 :     TALER_EXCHANGE_post_auditors_cancel (ds->dh);
     221            0 :     ds->dh = NULL;
     222              :   }
     223            0 :   GNUNET_free (ds);
     224            0 : }
     225              : 
     226              : 
     227              : struct TALER_TESTING_Command
     228            0 : TALER_TESTING_cmd_auditor_add_denom_sig (const char *label,
     229              :                                          unsigned int expected_http_status,
     230              :                                          const char *denom_ref,
     231              :                                          bool bad_sig)
     232              : {
     233              :   struct AuditorAddDenomSigState *ds;
     234              : 
     235            0 :   ds = GNUNET_new (struct AuditorAddDenomSigState);
     236            0 :   ds->expected_response_code = expected_http_status;
     237            0 :   ds->bad_sig = bad_sig;
     238            0 :   ds->denom_ref = denom_ref;
     239              :   {
     240            0 :     struct TALER_TESTING_Command cmd = {
     241              :       .cls = ds,
     242              :       .label = label,
     243              :       .run = &auditor_add_run,
     244              :       .cleanup = &auditor_add_cleanup
     245              :     };
     246              : 
     247            0 :     return cmd;
     248              :   }
     249              : }
     250              : 
     251              : 
     252              : /* end of testing_api_cmd_auditor_add_denom_sig.c */
        

Generated by: LCOV version 2.0-1