Extend tests.

Give a way to force redownload (= no cherry picking) all /keys.
This commit is contained in:
Marcello Stanisci 2019-01-16 19:44:44 +01:00
parent ece3a9bfdb
commit 448a57d81e
No known key found for this signature in database
GPG Key ID: 8D526861953F4C0F
5 changed files with 113 additions and 7 deletions

View File

@ -433,7 +433,8 @@ TALER_EXCHANGE_get_keys (struct TALER_EXCHANGE_Handle *exchange);
*/ */
struct GNUNET_TIME_Absolute struct GNUNET_TIME_Absolute
TALER_EXCHANGE_check_keys_current (struct TALER_EXCHANGE_Handle *exchange, TALER_EXCHANGE_check_keys_current (struct TALER_EXCHANGE_Handle *exchange,
int force_download); int force_download,
int pull_all_keys);
/** /**

View File

@ -1401,6 +1401,29 @@ TALER_TESTING_cmd_check_keys
unsigned int num_denom_keys); unsigned int num_denom_keys);
/**
* Make a "check keys" command that forcedly does NOT cherry pick;
* just redownload the whole /keys. Then checks whether the number
* of denomination keys from @a exchange matches @a num_denom_keys.
*
* @param label command label
* @param generation when this command is run, exactly @a
* generation /keys downloads took place. If the number
* of downloads is less than @a generation, the logic will
* first make sure that @a generation downloads are done,
* and _then_ execute the rest of the command.
* @param num_denom_keys expected number of denomination keys.
* @param exchange connection handle to the exchange to test.
*
* @return the command.
*/
struct TALER_TESTING_Command
TALER_TESTING_cmd_check_keys_pull_all_keys
(const char *label,
unsigned int generation,
unsigned int num_denom_keys);
/** /**
* Create a "batch" command. Such command takes a * Create a "batch" command. Such command takes a
* end_CMD-terminated array of CMDs and executed them. * end_CMD-terminated array of CMDs and executed them.

View File

@ -1021,20 +1021,34 @@ static void
request_keys (void *cls); request_keys (void *cls);
/**
* Put the handle back to the init state. Might
* be useful to force-download all /keys.
*
* @param h exchange handle.
*/
void
TEAH_handle_reset (struct TALER_EXCHANGE_Handle *h);
/** /**
* Check if our current response for /keys is valid, and if * Check if our current response for /keys is valid, and if
* not trigger download. * not trigger download.
* *
* @param exchange exchange to check keys for * @param exchange exchange to check keys for
* @param force_download #GNUNET_YES to force download even if /keys is still valid * @param force_download #GNUNET_YES to force download even if /keys is still valid
* @param pull_all_keys if GNUNET_YES, then the exchange state is reset to 'init',
* and all denoms will be redownloaded.
* @return until when the response is current, 0 if we are re-downloading * @return until when the response is current, 0 if we are re-downloading
*/ */
struct GNUNET_TIME_Absolute struct GNUNET_TIME_Absolute
TALER_EXCHANGE_check_keys_current (struct TALER_EXCHANGE_Handle *exchange, TALER_EXCHANGE_check_keys_current (struct TALER_EXCHANGE_Handle *exchange,
int force_download) int force_download,
int pull_all_keys)
{ {
if (NULL != exchange->kr) if (NULL != exchange->kr)
return GNUNET_TIME_UNIT_ZERO_ABS; return GNUNET_TIME_UNIT_ZERO_ABS;
if (GNUNET_YES == pull_all_keys)
TEAH_handle_reset (exchange);
if ( (GNUNET_NO == force_download) && if ( (GNUNET_NO == force_download) &&
(0 < GNUNET_TIME_absolute_get_remaining (exchange->key_data_expiration).rel_value_us) ) (0 < GNUNET_TIME_absolute_get_remaining (exchange->key_data_expiration).rel_value_us) )
return exchange->key_data_expiration; return exchange->key_data_expiration;
@ -1218,6 +1232,18 @@ TEAH_handle_to_context (struct TALER_EXCHANGE_Handle *h)
} }
/**
* Put the handle back to the init state. Might
* be useful to force-download all /keys.
*
* @param h exchange handle.
*/
void
TEAH_handle_reset (struct TALER_EXCHANGE_Handle *h)
{
h->state = MHS_INIT;
}
/** /**
* Check if the handle is ready to process requests. * Check if the handle is ready to process requests.
* *
@ -1903,6 +1929,7 @@ const struct TALER_EXCHANGE_Keys *
TALER_EXCHANGE_get_keys (struct TALER_EXCHANGE_Handle *exchange) TALER_EXCHANGE_get_keys (struct TALER_EXCHANGE_Handle *exchange)
{ {
(void) TALER_EXCHANGE_check_keys_current (exchange, (void) TALER_EXCHANGE_check_keys_current (exchange,
GNUNET_NO,
GNUNET_NO); GNUNET_NO);
return &exchange->key_data; return &exchange->key_data;
} }
@ -1919,6 +1946,7 @@ json_t *
TALER_EXCHANGE_get_keys_raw (struct TALER_EXCHANGE_Handle *exchange) TALER_EXCHANGE_get_keys_raw (struct TALER_EXCHANGE_Handle *exchange)
{ {
(void) TALER_EXCHANGE_check_keys_current (exchange, (void) TALER_EXCHANGE_check_keys_current (exchange,
GNUNET_NO,
GNUNET_NO); GNUNET_NO);
return json_deep_copy (exchange->key_data_raw); return json_deep_copy (exchange->key_data_raw);
} }

View File

@ -81,9 +81,12 @@ run (void *cls,
1, 1,
4), 4),
TALER_TESTING_cmd_check_keys ("second-download", /**
2, * Avoid cherry-pick, just GET /keys.
6), */
TALER_TESTING_cmd_check_keys_pull_all_keys ("second-download",
2,
4),
TALER_TESTING_cmd_end () TALER_TESTING_cmd_end ()
}; };

View File

@ -47,6 +47,13 @@ struct CheckKeysState
* supposed to have. * supposed to have.
*/ */
unsigned int num_denom_keys; unsigned int num_denom_keys;
/**
* If this value is GNUNET_YES, then the "cherry
* picking" facility is turned off; whole /keys is
* downloaded.
*/
unsigned int pull_all_keys;
}; };
@ -77,8 +84,11 @@ check_keys_run (void *cls,
cmd->label); cmd->label);
/* Means re-download /keys. */ /* Means re-download /keys. */
GNUNET_break (0 == TALER_EXCHANGE_check_keys_current GNUNET_break
(is->exchange, GNUNET_YES).abs_value_us); (0 == TALER_EXCHANGE_check_keys_current
(is->exchange,
GNUNET_YES,
cks->pull_all_keys).abs_value_us);
return; return;
} }
if (is->key_generation > cks->generation) if (is->key_generation > cks->generation)
@ -162,4 +172,45 @@ TALER_TESTING_cmd_check_keys
return cmd; return cmd;
} }
/**
* Make a "check keys" command that forcedly does NOT cherry pick;
* just redownload the whole /keys. Then checks whether the number
* of denomination keys from @a exchange matches @a num_denom_keys.
*
* @param label command label
* @param generation when this command is run, exactly @a
* generation /keys downloads took place. If the number
* of downloads is less than @a generation, the logic will
* first make sure that @a generation downloads are done,
* and _then_ execute the rest of the command.
* @param num_denom_keys expected number of denomination keys.
* @param exchange connection handle to the exchange to test.
*
* @return the command.
*/
struct TALER_TESTING_Command
TALER_TESTING_cmd_check_keys_pull_all_keys
(const char *label,
unsigned int generation,
unsigned int num_denom_keys)
{
struct CheckKeysState *cks;
cks = GNUNET_new (struct CheckKeysState);
cks->generation = generation;
cks->num_denom_keys = num_denom_keys;
cks->pull_all_keys = GNUNET_YES;
struct TALER_TESTING_Command cmd = {
.cls = cks,
.label = label,
.run = &check_keys_run,
.cleanup = &check_keys_cleanup
};
return cmd;
}
/* end of testing_api_cmd_check_keys.c */ /* end of testing_api_cmd_check_keys.c */