diff options
author | Marcello Stanisci <stanisci.m@gmail.com> | 2019-04-04 12:14:25 +0200 |
---|---|---|
committer | Marcello Stanisci <stanisci.m@gmail.com> | 2019-04-04 12:14:25 +0200 |
commit | 3e757cdeda7938d9d5f88bcc7b91deebaaf154ba (patch) | |
tree | c820658fa30ed2010900e7d5dc41cd1b23131b79 /src/lib | |
parent | ce71d83ad6b651b3cac43d131bf62afa1583bf67 (diff) |
Inserting "now" argument into "/keys".
Also using this new logic from the cherry-pick test case.
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/exchange_api_handle.c | 34 | ||||
-rw-r--r-- | src/lib/test_exchange_api_keys_cherry_picking_new.c | 34 | ||||
-rw-r--r-- | src/lib/testing_api_cmd_check_keys.c | 2 |
3 files changed, 38 insertions, 32 deletions
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. |