2018-01-23 10:28:24 +01:00
|
|
|
/*
|
|
|
|
This file is part of TALER
|
2020-12-20 17:10:01 +01:00
|
|
|
(C) 2018, 2020 Taler Systems SA
|
2018-01-23 10:28:24 +01:00
|
|
|
|
|
|
|
TALER is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as
|
|
|
|
published by the Free Software Foundation; either version 3, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
TALER is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public
|
|
|
|
License along with TALER; see the file COPYING. If not, see
|
|
|
|
<http://www.gnu.org/licenses/>
|
|
|
|
*/
|
|
|
|
/**
|
2020-01-19 15:23:19 +01:00
|
|
|
* @file testing/testing_api_cmd_check_keys.c
|
2020-12-20 17:10:01 +01:00
|
|
|
* @brief Implementation of "check keys" test command.
|
2018-01-23 10:28:24 +01:00
|
|
|
* @author Marcello Stanisci
|
2020-12-20 17:10:01 +01:00
|
|
|
* @author Christian Grothoff
|
2018-01-23 10:28:24 +01:00
|
|
|
*/
|
|
|
|
#include "platform.h"
|
|
|
|
#include "taler_json_lib.h"
|
|
|
|
#include <gnunet/gnunet_curl_lib.h>
|
|
|
|
#include "taler_testing_lib.h"
|
|
|
|
|
2018-05-25 14:15:58 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* State for a "check keys" CMD.
|
|
|
|
*/
|
2018-01-23 10:28:24 +01:00
|
|
|
struct CheckKeysState
|
|
|
|
{
|
|
|
|
/**
|
2018-12-21 14:04:43 +01:00
|
|
|
* This number will instruct the CMD interpreter to
|
|
|
|
* make sure that /keys was downloaded `generation` times
|
|
|
|
* _before_ running the very CMD logic.
|
2018-01-23 10:28:24 +01:00
|
|
|
*/
|
|
|
|
unsigned int generation;
|
|
|
|
|
2019-01-16 19:44:44 +01:00
|
|
|
/**
|
2020-12-20 17:10:01 +01:00
|
|
|
* If this value is true, then the "cherry
|
2019-01-16 19:44:44 +01:00
|
|
|
* picking" facility is turned off; whole /keys is
|
|
|
|
* downloaded.
|
|
|
|
*/
|
2020-12-20 17:10:01 +01:00
|
|
|
bool pull_all_keys;
|
2019-04-03 18:09:10 +02:00
|
|
|
|
|
|
|
/**
|
2020-12-20 17:10:01 +01:00
|
|
|
* Label of a command to use to derive the "last_denom_issue" date to use.
|
2019-04-03 18:09:10 +02:00
|
|
|
*/
|
2020-12-20 17:10:01 +01:00
|
|
|
const char *last_denom_date_ref;
|
2019-04-03 18:09:10 +02:00
|
|
|
|
|
|
|
/**
|
2020-12-20 17:10:01 +01:00
|
|
|
* Last denomination date we received when doing this request.
|
2019-04-03 18:09:10 +02:00
|
|
|
*/
|
2020-12-20 17:10:01 +01:00
|
|
|
struct GNUNET_TIME_Absolute my_denom_date;
|
2018-01-23 10:28:24 +01:00
|
|
|
};
|
|
|
|
|
2018-02-27 22:22:18 +01:00
|
|
|
|
2018-01-23 10:28:24 +01:00
|
|
|
/**
|
2018-05-25 14:15:58 +02:00
|
|
|
* Run the "check keys" command.
|
2018-01-23 10:28:24 +01:00
|
|
|
*
|
2018-05-25 14:15:58 +02:00
|
|
|
* @param cls closure.
|
|
|
|
* @param cmd the command currently being executed.
|
2018-01-23 10:28:24 +01:00
|
|
|
* @param is the interpreter state.
|
|
|
|
*/
|
2018-02-27 22:22:18 +01:00
|
|
|
static void
|
2018-01-23 10:28:24 +01:00
|
|
|
check_keys_run (void *cls,
|
|
|
|
const struct TALER_TESTING_Command *cmd,
|
|
|
|
struct TALER_TESTING_Interpreter *is)
|
|
|
|
{
|
|
|
|
struct CheckKeysState *cks = cls;
|
|
|
|
|
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
2019-01-21 15:46:33 +01:00
|
|
|
"cmd `%s' (ip: %u), key generation: %d\n",
|
2018-09-15 22:20:07 +02:00
|
|
|
cmd->label,
|
2019-01-21 15:46:33 +01:00
|
|
|
is->ip,
|
2018-09-15 22:20:07 +02:00
|
|
|
is->key_generation);
|
2018-01-23 10:28:24 +01:00
|
|
|
if (is->key_generation < cks->generation)
|
|
|
|
{
|
2020-12-20 17:10:01 +01:00
|
|
|
struct GNUNET_TIME_Absolute rdate;
|
|
|
|
|
2018-01-23 10:28:24 +01:00
|
|
|
is->working = GNUNET_NO;
|
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
2019-01-09 22:44:05 +01:00
|
|
|
"Triggering GET /keys, cmd `%s'\n",
|
2018-01-23 10:28:24 +01:00
|
|
|
cmd->label);
|
2020-12-20 17:10:01 +01:00
|
|
|
if (NULL != cks->last_denom_date_ref)
|
2019-01-17 16:37:16 +01:00
|
|
|
{
|
2020-12-20 17:10:01 +01:00
|
|
|
if (0 == strcmp ("zero",
|
|
|
|
cks->last_denom_date_ref))
|
|
|
|
{
|
|
|
|
TALER_LOG_DEBUG ("Forcing last_denom_date URL argument set to zero\n");
|
|
|
|
TALER_EXCHANGE_set_last_denom (is->exchange,
|
|
|
|
GNUNET_TIME_UNIT_ZERO_ABS);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const struct GNUNET_TIME_Absolute *last_denom_date;
|
|
|
|
const struct TALER_TESTING_Command *ref;
|
|
|
|
|
|
|
|
ref = TALER_TESTING_interpreter_lookup_command (is,
|
|
|
|
cks->last_denom_date_ref);
|
|
|
|
if (NULL == ref)
|
|
|
|
{
|
|
|
|
GNUNET_break (0);
|
|
|
|
TALER_TESTING_interpreter_fail (is);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (GNUNET_OK !=
|
|
|
|
TALER_TESTING_get_trait_absolute_time (ref,
|
|
|
|
0,
|
|
|
|
&last_denom_date))
|
|
|
|
{
|
|
|
|
GNUNET_break (0);
|
|
|
|
TALER_TESTING_interpreter_fail (is);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
TALER_LOG_DEBUG ("Forcing last_denom_date URL argument\n");
|
|
|
|
TALER_EXCHANGE_set_last_denom (is->exchange,
|
|
|
|
*last_denom_date);
|
|
|
|
}
|
2019-01-17 16:37:16 +01:00
|
|
|
}
|
2018-09-25 12:00:25 +02:00
|
|
|
|
2020-12-20 17:10:01 +01:00
|
|
|
rdate = TALER_EXCHANGE_check_keys_current (
|
|
|
|
is->exchange,
|
|
|
|
cks->pull_all_keys
|
|
|
|
? TALER_EXCHANGE_CKF_FORCE_ALL_NOW
|
|
|
|
: TALER_EXCHANGE_CKF_FORCE_DOWNLOAD);
|
2019-04-03 18:09:10 +02:00
|
|
|
/* Redownload /keys. */
|
2020-12-20 17:10:01 +01:00
|
|
|
GNUNET_break (0 ==
|
|
|
|
rdate.abs_value_us);
|
2018-01-23 10:28:24 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
{
|
2020-12-20 17:10:01 +01:00
|
|
|
const struct TALER_EXCHANGE_Keys *keys;
|
|
|
|
|
|
|
|
keys = TALER_EXCHANGE_get_keys (is->exchange);
|
|
|
|
if (NULL == keys)
|
|
|
|
{
|
|
|
|
GNUNET_break (0);
|
|
|
|
TALER_TESTING_interpreter_fail (is);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cks->my_denom_date = keys->last_denom_issue_date;
|
2018-01-23 10:28:24 +01:00
|
|
|
}
|
|
|
|
TALER_TESTING_interpreter_next (is);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cleanup the state.
|
|
|
|
*
|
2018-05-25 14:15:58 +02:00
|
|
|
* @param cls closure.
|
2018-01-23 10:28:24 +01:00
|
|
|
* @param cmd the command which is being cleaned up.
|
|
|
|
*/
|
2018-02-27 22:22:18 +01:00
|
|
|
static void
|
2018-01-23 10:28:24 +01:00
|
|
|
check_keys_cleanup (void *cls,
|
|
|
|
const struct TALER_TESTING_Command *cmd)
|
|
|
|
{
|
|
|
|
struct CheckKeysState *cks = cls;
|
|
|
|
|
2020-03-27 14:05:59 +01:00
|
|
|
(void) cmd;
|
2018-01-23 10:28:24 +01:00
|
|
|
GNUNET_free (cks);
|
|
|
|
}
|
|
|
|
|
2018-02-27 22:22:18 +01:00
|
|
|
|
2020-12-20 17:10:01 +01:00
|
|
|
/**
|
|
|
|
* Offer internal data to a "check_keys" CMD state to other
|
|
|
|
* commands.
|
|
|
|
*
|
|
|
|
* @param cls closure
|
|
|
|
* @param[out] ret result (could be anything)
|
|
|
|
* @param trait name of the trait
|
|
|
|
* @param index index number of the object to offer.
|
|
|
|
* @return #GNUNET_OK on success
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
check_keys_traits (void *cls,
|
|
|
|
const void **ret,
|
|
|
|
const char *trait,
|
|
|
|
unsigned int index)
|
2019-01-17 16:37:16 +01:00
|
|
|
{
|
2020-12-20 17:10:01 +01:00
|
|
|
struct CheckKeysState *cks = cls;
|
|
|
|
struct TALER_TESTING_Trait traits[] = {
|
|
|
|
/* history entry MUST be first due to response code logic below! */
|
|
|
|
TALER_TESTING_make_trait_absolute_time (0,
|
|
|
|
&cks->my_denom_date),
|
|
|
|
TALER_TESTING_trait_end ()
|
|
|
|
};
|
|
|
|
|
|
|
|
return TALER_TESTING_get_trait (traits,
|
|
|
|
ret,
|
|
|
|
trait,
|
|
|
|
index);
|
2019-01-17 16:37:16 +01:00
|
|
|
}
|
|
|
|
|
2019-10-31 12:59:50 +01:00
|
|
|
|
2018-01-23 10:28:24 +01:00
|
|
|
struct TALER_TESTING_Command
|
2020-01-18 16:41:24 +01:00
|
|
|
TALER_TESTING_cmd_check_keys (const char *label,
|
2020-12-14 17:12:25 +01:00
|
|
|
unsigned int generation)
|
2019-04-03 18:09:10 +02:00
|
|
|
{
|
|
|
|
struct CheckKeysState *cks;
|
|
|
|
|
|
|
|
cks = GNUNET_new (struct CheckKeysState);
|
|
|
|
cks->generation = generation;
|
2020-01-18 16:41:24 +01:00
|
|
|
{
|
|
|
|
struct TALER_TESTING_Command cmd = {
|
|
|
|
.cls = cks,
|
|
|
|
.label = label,
|
|
|
|
.run = &check_keys_run,
|
2020-12-20 17:10:01 +01:00
|
|
|
.cleanup = &check_keys_cleanup,
|
|
|
|
.traits = &check_keys_traits
|
2020-01-18 16:41:24 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
return cmd;
|
|
|
|
}
|
2019-04-03 18:09:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-16 19:44:44 +01:00
|
|
|
struct TALER_TESTING_Command
|
2020-01-18 16:41:24 +01:00
|
|
|
TALER_TESTING_cmd_check_keys_pull_all_keys (const char *label,
|
2020-12-14 17:12:25 +01:00
|
|
|
unsigned int generation)
|
2019-01-16 19:44:44 +01:00
|
|
|
{
|
2020-12-20 17:10:01 +01:00
|
|
|
struct TALER_TESTING_Command cmd
|
|
|
|
= TALER_TESTING_cmd_check_keys (label,
|
|
|
|
generation);
|
|
|
|
struct CheckKeysState *cks = cmd.cls;
|
2019-01-16 19:44:44 +01:00
|
|
|
|
2020-12-20 17:10:01 +01:00
|
|
|
cks->pull_all_keys = true;
|
|
|
|
return cmd;
|
|
|
|
}
|
2020-01-18 16:41:24 +01:00
|
|
|
|
2020-12-20 17:10:01 +01:00
|
|
|
|
|
|
|
struct TALER_TESTING_Command
|
|
|
|
TALER_TESTING_cmd_check_keys_with_last_denom (
|
|
|
|
const char *label,
|
|
|
|
unsigned int generation,
|
|
|
|
const char *last_denom_date_ref)
|
|
|
|
{
|
|
|
|
struct TALER_TESTING_Command cmd
|
|
|
|
= TALER_TESTING_cmd_check_keys (label,
|
|
|
|
generation);
|
|
|
|
struct CheckKeysState *cks = cmd.cls;
|
|
|
|
cks->last_denom_date_ref = last_denom_date_ref;
|
|
|
|
return cmd;
|
2019-01-16 19:44:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-25 14:15:58 +02:00
|
|
|
/* end of testing_api_cmd_check_keys.c */
|