LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_check_keys.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 0 59 0.0 %
Date: 2022-08-25 06:15:09 Functions: 0 6 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   (C) 2018, 2020, 2021 Taler Systems SA
       4             : 
       5             :   TALER is free software; you can redistribute it and/or modify
       6             :   it under the terms of the GNU General Public License as
       7             :   published by the Free Software Foundation; either version 3, or
       8             :   (at your 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
      13             :   GNU 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_check_keys.c
      21             :  * @brief Implementation of "check keys" test command.
      22             :  * @author Marcello Stanisci
      23             :  * @author Christian Grothoff
      24             :  */
      25             : #include "platform.h"
      26             : #include "taler_json_lib.h"
      27             : #include <gnunet/gnunet_curl_lib.h>
      28             : #include "taler_testing_lib.h"
      29             : 
      30             : 
      31             : /**
      32             :  * State for a "check keys" CMD.
      33             :  */
      34             : struct CheckKeysState
      35             : {
      36             :   /**
      37             :    * This number will instruct the CMD interpreter to
      38             :    * make sure that /keys was downloaded `generation` times
      39             :    * _before_ running the very CMD logic.
      40             :    */
      41             :   unsigned int generation;
      42             : 
      43             :   /**
      44             :    * If this value is true, then the "cherry
      45             :    * picking" facility is turned off; whole /keys is
      46             :    * downloaded.
      47             :    */
      48             :   bool pull_all_keys;
      49             : 
      50             :   /**
      51             :    * Label of a command to use to derive the "last_denom_issue" date to use.
      52             :    */
      53             :   const char *last_denom_date_ref;
      54             : 
      55             :   /**
      56             :    * Last denomination date we received when doing this request.
      57             :    */
      58             :   struct GNUNET_TIME_Timestamp my_denom_date;
      59             : };
      60             : 
      61             : 
      62             : /**
      63             :  * Run the "check keys" command.
      64             :  *
      65             :  * @param cls closure.
      66             :  * @param cmd the command currently being executed.
      67             :  * @param is the interpreter state.
      68             :  */
      69             : static void
      70           0 : check_keys_run (void *cls,
      71             :                 const struct TALER_TESTING_Command *cmd,
      72             :                 struct TALER_TESTING_Interpreter *is)
      73             : {
      74           0 :   struct CheckKeysState *cks = cls;
      75             : 
      76           0 :   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
      77             :               "cmd `%s' (ip: %u), key generation: %d\n",
      78             :               cmd->label,
      79             :               is->ip,
      80             :               is->key_generation);
      81           0 :   if (is->key_generation < cks->generation)
      82             :   {
      83             :     struct GNUNET_TIME_Timestamp rdate;
      84             : 
      85           0 :     is->working = GNUNET_NO;
      86           0 :     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
      87             :                 "Triggering GET /keys, cmd `%s'\n",
      88             :                 cmd->label);
      89           0 :     if (NULL != cks->last_denom_date_ref)
      90             :     {
      91           0 :       if (0 == strcmp ("zero",
      92             :                        cks->last_denom_date_ref))
      93             :       {
      94           0 :         TALER_LOG_DEBUG ("Forcing last_denom_date URL argument set to zero\n");
      95           0 :         TALER_EXCHANGE_set_last_denom (is->exchange,
      96           0 :                                        GNUNET_TIME_UNIT_ZERO_TS);
      97             :       }
      98             :       else
      99             :       {
     100             :         const struct GNUNET_TIME_Timestamp *last_denom_date;
     101             :         const struct TALER_TESTING_Command *ref;
     102             : 
     103           0 :         ref = TALER_TESTING_interpreter_lookup_command (is,
     104             :                                                         cks->last_denom_date_ref);
     105           0 :         if (NULL == ref)
     106             :         {
     107           0 :           GNUNET_break (0);
     108           0 :           TALER_TESTING_interpreter_fail (is);
     109           0 :           return;
     110             :         }
     111           0 :         if (GNUNET_OK !=
     112           0 :             TALER_TESTING_get_trait_timestamp (ref,
     113             :                                                0,
     114             :                                                &last_denom_date))
     115             :         {
     116           0 :           GNUNET_break (0);
     117           0 :           TALER_TESTING_interpreter_fail (is);
     118           0 :           return;
     119             :         }
     120             : 
     121           0 :         TALER_LOG_DEBUG ("Forcing last_denom_date URL argument\n");
     122           0 :         TALER_EXCHANGE_set_last_denom (is->exchange,
     123             :                                        *last_denom_date);
     124             :       }
     125             :     }
     126             : 
     127           0 :     rdate = TALER_EXCHANGE_check_keys_current (
     128             :       is->exchange,
     129           0 :       cks->pull_all_keys
     130             :       ? TALER_EXCHANGE_CKF_FORCE_ALL_NOW
     131             :       : TALER_EXCHANGE_CKF_FORCE_DOWNLOAD);
     132             :     /* Redownload /keys.  */
     133           0 :     GNUNET_break (GNUNET_TIME_absolute_is_zero (rdate.abs_time));
     134           0 :     return;
     135             :   }
     136             :   {
     137             :     const struct TALER_EXCHANGE_Keys *keys;
     138             : 
     139           0 :     keys = TALER_EXCHANGE_get_keys (is->exchange);
     140           0 :     if (NULL == keys)
     141             :     {
     142           0 :       GNUNET_break (0);
     143           0 :       TALER_TESTING_interpreter_fail (is);
     144           0 :       return;
     145             :     }
     146           0 :     cks->my_denom_date = keys->last_denom_issue_date;
     147             :   }
     148           0 :   TALER_TESTING_interpreter_next (is);
     149             : }
     150             : 
     151             : 
     152             : /**
     153             :  * Cleanup the state.
     154             :  *
     155             :  * @param cls closure.
     156             :  * @param cmd the command which is being cleaned up.
     157             :  */
     158             : static void
     159           0 : check_keys_cleanup (void *cls,
     160             :                     const struct TALER_TESTING_Command *cmd)
     161             : {
     162           0 :   struct CheckKeysState *cks = cls;
     163             : 
     164             :   (void) cmd;
     165           0 :   GNUNET_free (cks);
     166           0 : }
     167             : 
     168             : 
     169             : /**
     170             :  * Offer internal data to a "check_keys" CMD state to other
     171             :  * commands.
     172             :  *
     173             :  * @param cls closure
     174             :  * @param[out] ret result (could be anything)
     175             :  * @param trait name of the trait
     176             :  * @param index index number of the object to offer.
     177             :  * @return #GNUNET_OK on success
     178             :  */
     179             : static int
     180           0 : check_keys_traits (void *cls,
     181             :                    const void **ret,
     182             :                    const char *trait,
     183             :                    unsigned int index)
     184             : {
     185           0 :   struct CheckKeysState *cks = cls;
     186             :   struct TALER_TESTING_Trait traits[] = {
     187             :     /* history entry MUST be first due to response code logic below! */
     188           0 :     TALER_TESTING_make_trait_timestamp (0,
     189           0 :                                         &cks->my_denom_date),
     190           0 :     TALER_TESTING_trait_end ()
     191             :   };
     192             : 
     193           0 :   return TALER_TESTING_get_trait (traits,
     194             :                                   ret,
     195             :                                   trait,
     196             :                                   index);
     197             : }
     198             : 
     199             : 
     200             : struct TALER_TESTING_Command
     201           0 : TALER_TESTING_cmd_check_keys (const char *label,
     202             :                               unsigned int generation)
     203             : {
     204             :   struct CheckKeysState *cks;
     205             : 
     206           0 :   cks = GNUNET_new (struct CheckKeysState);
     207           0 :   cks->generation = generation;
     208             :   {
     209           0 :     struct TALER_TESTING_Command cmd = {
     210             :       .cls = cks,
     211             :       .label = label,
     212             :       .run = &check_keys_run,
     213             :       .cleanup = &check_keys_cleanup,
     214             :       .traits = &check_keys_traits
     215             :     };
     216             : 
     217           0 :     return cmd;
     218             :   }
     219             : }
     220             : 
     221             : 
     222             : struct TALER_TESTING_Command
     223           0 : TALER_TESTING_cmd_check_keys_pull_all_keys (const char *label,
     224             :                                             unsigned int generation)
     225             : {
     226             :   struct TALER_TESTING_Command cmd
     227           0 :     = TALER_TESTING_cmd_check_keys (label,
     228             :                                     generation);
     229           0 :   struct CheckKeysState *cks = cmd.cls;
     230             : 
     231           0 :   cks->pull_all_keys = true;
     232           0 :   return cmd;
     233             : }
     234             : 
     235             : 
     236             : struct TALER_TESTING_Command
     237           0 : TALER_TESTING_cmd_check_keys_with_last_denom (
     238             :   const char *label,
     239             :   unsigned int generation,
     240             :   const char *last_denom_date_ref)
     241             : {
     242             :   struct TALER_TESTING_Command cmd
     243           0 :     = TALER_TESTING_cmd_check_keys (label,
     244             :                                     generation);
     245           0 :   struct CheckKeysState *cks = cmd.cls;
     246           0 :   cks->last_denom_date_ref = last_denom_date_ref;
     247           0 :   return cmd;
     248             : }
     249             : 
     250             : 
     251             : /* end of testing_api_cmd_check_keys.c */

Generated by: LCOV version 1.14