summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcello Stanisci <stanisci.m@gmail.com>2019-01-16 19:44:44 +0100
committerMarcello Stanisci <stanisci.m@gmail.com>2019-01-16 19:44:44 +0100
commit448a57d81e2a72d8117603ee60f60e5586c7d05d (patch)
treeeb21973b67387378248d8698766ea3016ae1438c
parentece3a9bfdb6419d344abeb6c78c167b80d81fb6b (diff)
downloadexchange-448a57d81e2a72d8117603ee60f60e5586c7d05d.tar.gz
exchange-448a57d81e2a72d8117603ee60f60e5586c7d05d.tar.bz2
exchange-448a57d81e2a72d8117603ee60f60e5586c7d05d.zip
Extend tests.
Give a way to force redownload (= no cherry picking) all /keys.
-rw-r--r--src/include/taler_exchange_service.h3
-rw-r--r--src/include/taler_testing_lib.h23
-rw-r--r--src/lib/exchange_api_handle.c30
-rwxr-xr-xsrc/lib/test_exchange_api_overlapping_keys_bug.c9
-rw-r--r--src/lib/testing_api_cmd_check_keys.c55
5 files changed, 113 insertions, 7 deletions
diff --git a/src/include/taler_exchange_service.h b/src/include/taler_exchange_service.h
index fa93dca80..a1ecc0bef 100644
--- a/src/include/taler_exchange_service.h
+++ b/src/include/taler_exchange_service.h
@@ -433,7 +433,8 @@ TALER_EXCHANGE_get_keys (struct TALER_EXCHANGE_Handle *exchange);
*/
struct GNUNET_TIME_Absolute
TALER_EXCHANGE_check_keys_current (struct TALER_EXCHANGE_Handle *exchange,
- int force_download);
+ int force_download,
+ int pull_all_keys);
/**
diff --git a/src/include/taler_testing_lib.h b/src/include/taler_testing_lib.h
index ed09ad471..eeb0a5c00 100644
--- a/src/include/taler_testing_lib.h
+++ b/src/include/taler_testing_lib.h
@@ -1402,6 +1402,29 @@ TALER_TESTING_cmd_check_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
* end_CMD-terminated array of CMDs and executed them.
* Once it hits the end CMD, it passes the control
diff --git a/src/lib/exchange_api_handle.c b/src/lib/exchange_api_handle.c
index 8eedfd60a..bace2b47b 100644
--- a/src/lib/exchange_api_handle.c
+++ b/src/lib/exchange_api_handle.c
@@ -1022,19 +1022,33 @@ 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
* not trigger download.
*
* @param exchange exchange to check keys for
* @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
*/
struct GNUNET_TIME_Absolute
TALER_EXCHANGE_check_keys_current (struct TALER_EXCHANGE_Handle *exchange,
- int force_download)
+ int force_download,
+ int pull_all_keys)
{
if (NULL != exchange->kr)
return GNUNET_TIME_UNIT_ZERO_ABS;
+ if (GNUNET_YES == pull_all_keys)
+ TEAH_handle_reset (exchange);
if ( (GNUNET_NO == force_download) &&
(0 < GNUNET_TIME_absolute_get_remaining (exchange->key_data_expiration).rel_value_us) )
return exchange->key_data_expiration;
@@ -1219,6 +1233,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.
*
* @param h the exchange handle to query
@@ -1903,6 +1929,7 @@ const struct TALER_EXCHANGE_Keys *
TALER_EXCHANGE_get_keys (struct TALER_EXCHANGE_Handle *exchange)
{
(void) TALER_EXCHANGE_check_keys_current (exchange,
+ GNUNET_NO,
GNUNET_NO);
return &exchange->key_data;
}
@@ -1919,6 +1946,7 @@ json_t *
TALER_EXCHANGE_get_keys_raw (struct TALER_EXCHANGE_Handle *exchange)
{
(void) TALER_EXCHANGE_check_keys_current (exchange,
+ GNUNET_NO,
GNUNET_NO);
return json_deep_copy (exchange->key_data_raw);
}
diff --git a/src/lib/test_exchange_api_overlapping_keys_bug.c b/src/lib/test_exchange_api_overlapping_keys_bug.c
index d1fd7123b..c9d5adb4b 100755
--- a/src/lib/test_exchange_api_overlapping_keys_bug.c
+++ b/src/lib/test_exchange_api_overlapping_keys_bug.c
@@ -81,9 +81,12 @@ run (void *cls,
1,
4),
- TALER_TESTING_cmd_check_keys ("second-download",
- 2,
- 6),
+ /**
+ * Avoid cherry-pick, just GET /keys.
+ */
+ TALER_TESTING_cmd_check_keys_pull_all_keys ("second-download",
+ 2,
+ 4),
TALER_TESTING_cmd_end ()
};
diff --git a/src/lib/testing_api_cmd_check_keys.c b/src/lib/testing_api_cmd_check_keys.c
index d329f31a4..6cd605c38 100644
--- a/src/lib/testing_api_cmd_check_keys.c
+++ b/src/lib/testing_api_cmd_check_keys.c
@@ -47,6 +47,13 @@ struct CheckKeysState
* supposed to have.
*/
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);
/* Means re-download /keys. */
- GNUNET_break (0 == TALER_EXCHANGE_check_keys_current
- (is->exchange, GNUNET_YES).abs_value_us);
+ GNUNET_break
+ (0 == TALER_EXCHANGE_check_keys_current
+ (is->exchange,
+ GNUNET_YES,
+ cks->pull_all_keys).abs_value_us);
return;
}
if (is->key_generation > cks->generation)
@@ -162,4 +172,45 @@ TALER_TESTING_cmd_check_keys
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 */