aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/taler_testing_lib.h24
-rw-r--r--src/lib/exchange_api_handle.c34
-rw-r--r--src/lib/test_exchange_api_keys_cherry_picking_new.c34
-rw-r--r--src/lib/testing_api_cmd_check_keys.c2
4 files changed, 62 insertions, 32 deletions
diff --git a/src/include/taler_testing_lib.h b/src/include/taler_testing_lib.h
index 7c2f6f29a..d0b5f2754 100644
--- a/src/include/taler_testing_lib.h
+++ b/src/include/taler_testing_lib.h
@@ -936,6 +936,30 @@ TALER_TESTING_cmd_exec_keyup_with_now
/**
+ * Make a "check keys" command. This type of command
+ * 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_with_now
+ (const char *label,
+ unsigned int generation,
+ unsigned int num_denom_keys,
+ struct GNUNET_TIME_Absolute now);
+
+
+/**
* Make a "auditor sign" CMD.
*
* @param label command label
diff --git a/src/lib/exchange_api_handle.c b/src/lib/exchange_api_handle.c
index 5cc65de33..0993257a8 100644
--- a/src/lib/exchange_api_handle.c
+++ b/src/lib/exchange_api_handle.c
@@ -218,7 +218,7 @@ struct TALER_EXCHANGE_Handle
* If GNUNET_YES, use fake now given by the user, in
* request of "/keys".
*/
- unsigned int with_now;
+ int with_now;
/**
* Fake now given by the user.
@@ -1824,30 +1824,36 @@ request_keys (void *cls)
struct TALER_EXCHANGE_Handle *exchange = cls;
struct KeysRequest *kr;
CURL *eh;
+ char url[200] = "/keys?";
exchange->retry_task = NULL;
GNUNET_assert (NULL == exchange->kr);
kr = GNUNET_new (struct KeysRequest);
kr->exchange = exchange;
- if (GNUNET_YES ==
- TEAH_handle_is_ready (exchange))
- {
- char *arg;
+ if (GNUNET_YES == TEAH_handle_is_ready (exchange))
+ {
TALER_LOG_DEBUG ("Last DK issue date (before GETting /keys): %s\n",
GNUNET_STRINGS_absolute_time_to_string (exchange->key_data.last_denom_issue_date));
- GNUNET_asprintf (&arg,
- "/keys?last_issue_date=%llu",
- (unsigned long long) exchange->key_data.last_denom_issue_date.abs_value_us / 1000000LLU);
- kr->url = TEAH_path_to_url (exchange,
- arg);
- GNUNET_free (arg);
+ sprintf (&url[strlen (url)],
+ "last_issue_date=%llu&",
+ (unsigned long long) exchange->key_data.last_denom_issue_date.abs_value_us / 1000000LLU);
}
- else
+
+ if (GNUNET_YES == exchange->with_now)
{
- kr->url = TEAH_path_to_url (exchange,
- "/keys");
+ TALER_LOG_DEBUG ("Faking now to GET /keys): %s\n",
+ GNUNET_STRINGS_absolute_time_to_string (exchange->now));
+ sprintf (&url[strlen (url)],
+ "now=%llu&",
+ (unsigned long long) exchange->now.abs_value_us / 1000000LLU);
}
+
+ /* Clean the last '&'/'?' sign that we optimistically put. */
+ url[strlen (url) - 1] = '\0';
+ kr->url = TEAH_path_to_url (exchange,
+ url);
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Requesting keys with URL `%s'.\n",
kr->url);
diff --git a/src/lib/test_exchange_api_keys_cherry_picking_new.c b/src/lib/test_exchange_api_keys_cherry_picking_new.c
index 9760d91ba..ccfb93a3a 100644
--- a/src/lib/test_exchange_api_keys_cherry_picking_new.c
+++ b/src/lib/test_exchange_api_keys_cherry_picking_new.c
@@ -151,6 +151,7 @@ run (void *cls,
};
+ now = GNUNET_TIME_absolute_get ();
struct TALER_TESTING_Command ordinary_cherry_pick[] = {
/* Trigger keys reloading from disk. */
@@ -164,11 +165,12 @@ run (void *cls,
1, /* generation */
1),
/**
- * We now set lookahead_sign to 90s, and fake 10s passed.
+ * We now set lookahead_sign to 90s, and expect a new DK
+ * to be created. The first one lives (= has withdraw_duration of)
+ * only 80s.
*/
- TALER_TESTING_cmd_exec_keyup_with_now ("keyup-2",
- CONFIG_FILE_EXTENDED,
- NOWPLUSSECS (10)),
+ TALER_TESTING_cmd_exec_keyup ("keyup-2",
+ CONFIG_FILE_EXTENDED),
TALER_TESTING_cmd_exec_auditor_sign ("sign-keys-1",
CONFIG_FILE_EXTENDED),
@@ -177,19 +179,15 @@ run (void *cls,
is->exchanged,
SIGUSR1),
/**
- * First DK has still 70s of remaining life
- * (duration_withdraw), so it's not enough to cover the new
- * 90s window, so a new one should be created.
* Total 2 DKs.
*/
TALER_TESTING_cmd_check_keys ("check-keys-2",
2, /* generation */
2),
- /* Must fake 20s lapse now. */
- TALER_TESTING_cmd_exec_keyup_with_now ("keyup-3",
- CONFIG_FILE_EXTENDED,
- NOWPLUSSECS (20)),
+ /* Nothing should happen now. */
+ TALER_TESTING_cmd_exec_keyup ("keyup-3",
+ CONFIG_FILE_EXTENDED),
TALER_TESTING_cmd_exec_auditor_sign ("sign-keys-2",
CONFIG_FILE),
TALER_TESTING_cmd_signal ("trigger-keys-reload-2",
@@ -197,13 +195,15 @@ run (void *cls,
SIGUSR1),
/**
- * First DK has 50s of remaining life (duration_withdraw).
- * The second DK has ~60s of remaining life, therefore two
- * keys should be (still) returned.
+ * Make 30s time lapse (by passing the "now" argument to
+ * "/keys"). First DK has 50s of remaining life
+ * (duration_withdraw). The second DK has ~60s of remaining
+ * life, therefore two keys should be (still) returned.
*/
- TALER_TESTING_cmd_check_keys ("check-keys-3",
- 3,
- 2),
+ TALER_TESTING_cmd_check_keys_with_now ("check-keys-3",
+ 3,
+ 2,
+ NOWPLUSSECS (30)),
TALER_TESTING_cmd_end ()
};
struct TALER_TESTING_Command commands[] = {
diff --git a/src/lib/testing_api_cmd_check_keys.c b/src/lib/testing_api_cmd_check_keys.c
index 983098ce9..d6ab012dd 100644
--- a/src/lib/testing_api_cmd_check_keys.c
+++ b/src/lib/testing_api_cmd_check_keys.c
@@ -73,7 +73,7 @@ struct CheckKeysState
* If GNUNET_YES, then we'll provide the "/keys" request.
* with the "now" argument.
*/
- unsigned int with_now;
+ int with_now;
/**
* Fake now as passed by the user.