donau

Donation authority for GNU Taler (experimental)
Log | Files | Refs | Submodules | README | LICENSE

commit a1e0ac1f097806255e1aadd9fe6edd95644fa502
parent 13a894ad796088018fb591b0a0eb8ce88f24dc49
Author: Matyja Lukas Adam <lukas.matyja@students.bfh.ch>
Date:   Wed, 28 Feb 2024 23:35:06 +0100

[testing] finish get charities

Diffstat:
Msrc/include/donau_service.h | 2--
Msrc/include/donau_testing_lib.h | 12+++++++++++-
Msrc/lib/donau_api_charities_get.c | 22++--------------------
Msrc/lib/donau_api_charity_get.c | 34+++++-----------------------------
Msrc/testing/Makefile.am | 1+
Msrc/testing/test_donau_api.c | 5+++--
Asrc/testing/testing_api_cmd_charities_get.c | 157+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/testing/testing_api_cmd_charity_get.c | 26++------------------------
8 files changed, 181 insertions(+), 78 deletions(-)

diff --git a/src/include/donau_service.h b/src/include/donau_service.h @@ -881,7 +881,6 @@ DONAU_charities_get ( struct GNUNET_CURL_Context *ctx, const char *url, const struct DONAU_BearerToken bearer, - const struct GNUNET_TIME_Relative timeout, DONAU_GetCharitiesResponseCallback cb, void *cb_cls); @@ -1011,7 +1010,6 @@ DONAU_charity_get ( const char *url, const uint64_t id, const struct DONAU_BearerToken bearer, - struct GNUNET_TIME_Relative timeout, DONAU_GetCharityResponseCallback cb, void *cb_cls); diff --git a/src/include/donau_testing_lib.h b/src/include/donau_testing_lib.h @@ -65,9 +65,19 @@ struct TALER_TESTING_Command TALER_TESTING_cmd_charity_get (const char *label, const uint64_t charity_id, const struct DONAU_BearerToken bearer, - const struct GNUNET_TIME_Relative timeout, unsigned int expected_response_code); +/** + * Create a GET "charities" command. + * + * @param label the command label. + * @param expected_response_code expected HTTP response code. + * @return the command. + */ +struct TALER_TESTING_Command +TALER_TESTING_cmd_charities_get (const char *label, + unsigned int expected_response_code); + /** * Convenience function to run a test. * diff --git a/src/lib/donau_api_charities_get.c b/src/lib/donau_api_charities_get.c @@ -131,8 +131,6 @@ handle_charities_get_finished (void *cls, long response_code, const void *resp_obj) { - // struct DONAU_Charities *cd = NULL; - struct DONAU_CharitiesGetHandle *cgh = cls; const json_t *j = resp_obj; struct DONAU_GetCharitiesResponse gcresp = { @@ -186,6 +184,7 @@ handle_charities_get_finished (void *cls, cgh->url); break; } + if (NULL != cgh->cb) { cgh->cb (cgh->cb_cls, @@ -201,7 +200,6 @@ DONAU_charities_get ( struct GNUNET_CURL_Context *ctx, const char *url, const struct DONAU_BearerToken bearer, // TODO: check authorization - struct GNUNET_TIME_Relative timeout, DONAU_GetCharitiesResponseCallback cb, void *cb_cls) { @@ -214,16 +212,7 @@ DONAU_charities_get ( cgh->url = GNUNET_strdup (url); cgh->cb = cb; cgh->cb_cls = cb_cls; - char *arg_str; - unsigned long long tms - = timeout.rel_value_us - / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us; - if (tms == 0) - arg_str = "charities"; - else - GNUNET_asprintf (&arg_str, - "charities?timeout_ms=%llu", - tms); + char *arg_str = "charities"; cgh->url = TALER_url_join (url, arg_str, NULL); @@ -243,13 +232,6 @@ DONAU_charities_get ( GNUNET_free (cgh); return NULL; } - if (0 != tms) - { - GNUNET_break (CURLE_OK == - curl_easy_setopt (eh, - CURLOPT_TIMEOUT_MS, - (long) (tms + 100L))); - } cgh->job = GNUNET_CURL_job_add_with_ct_json (ctx, eh, &handle_charities_get_finished, diff --git a/src/lib/donau_api_charity_get.c b/src/lib/donau_api_charity_get.c @@ -198,7 +198,6 @@ DONAU_charity_get ( const char *url, const uint64_t id, const struct DONAU_BearerToken bearer, // TODO: check authorization - struct GNUNET_TIME_Relative timeout, DONAU_GetCharityResponseCallback cb, void *cb_cls) { @@ -213,27 +212,11 @@ DONAU_charity_get ( cgh->charity_id = id; cgh->cb_cls = cb_cls; char arg_str[sizeof (id) * 2 + 32]; - char timeout_str[32]; - unsigned int tms - = (unsigned int) timeout.rel_value_us - / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us; - GNUNET_snprintf (timeout_str, - sizeof (timeout_str), - "%u", - tms); - if (tms == 0) - GNUNET_snprintf (arg_str, - sizeof (arg_str), - "charities/%llu", - (unsigned long long) - id); - else - GNUNET_snprintf (arg_str, - sizeof (arg_str), - "charities/%llu?timeout_ms=%s", - (unsigned long long) - id, - timeout_str); //TODO: query by year + GNUNET_snprintf (arg_str, + sizeof (arg_str), + "charities/%llu", + (unsigned long long) + id); cgh->url = TALER_url_join (url, arg_str, NULL); @@ -253,13 +236,6 @@ DONAU_charity_get ( GNUNET_free (cgh); return NULL; } - if (0 != tms) - { - GNUNET_break (CURLE_OK == - curl_easy_setopt (eh, - CURLOPT_TIMEOUT_MS, - (long) (tms + 100L))); - } cgh->job = GNUNET_CURL_job_add_with_ct_json (ctx, eh, &handle_charity_get_finished, diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am @@ -22,6 +22,7 @@ libdonautesting_la_LDFLAGS = \ libdonautesting_la_SOURCES = \ testing_api_cmd_get_donau.c \ testing_api_cmd_charity_get.c \ + testing_api_cmd_charities_get.c \ testing_api_traits.c \ testing_api_loop.c diff --git a/src/testing/test_donau_api.c b/src/testing/test_donau_api.c @@ -79,9 +79,10 @@ run (void *cls, TALER_TESTING_cmd_charity_get ("get-charity-by-id", 4, bearer, - GNUNET_TIME_relative_get_zero_ (), MHD_HTTP_OK), - //TODO: test POST charity, GET charities, DELETE charity + TALER_TESTING_cmd_charities_get ("get-charities", + MHD_HTTP_OK), + //TODO: test POST charity, DELETE charity /* End the suite. */ TALER_TESTING_cmd_end () }; diff --git a/src/testing/testing_api_cmd_charities_get.c b/src/testing/testing_api_cmd_charities_get.c @@ -0,0 +1,157 @@ +/* + This file is part of TALER + Copyright (C) 2014-2024 Taler Systems SA + + 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/> +*/ +/** + * @file testing/testing_api_cmd_charities_get.c + * @brief Implement the GET /charities test command. + * @author Lukas Matyja + */ +#include <taler/platform.h> +#include <taler/taler_json_lib.h> +#include <gnunet/gnunet_curl_lib.h> +#include <taler/taler_testing_lib.h> +#include "donau_testing_lib.h" + + +/** + * State for a "status" CMD. + */ +struct StatusState +{ + /** + * Handle to the "charities status" operation. + */ + struct DONAU_CharitiesGetHandle *cgh; + + /** + * The bearer token for authorization. + */ + struct DONAU_BearerToken bearer; + + /** + * Expected HTTP response code. + */ + unsigned int expected_response_code; + + /** + * Interpreter state. + */ + struct TALER_TESTING_Interpreter *is; + +}; + + +/** + * Check that the reserve balance and HTTP response code are + * both acceptable. + * + * @param cls closure. + * @param gcr HTTP response details + */ +static void +charities_status_cb (void *cls, + const struct DONAU_GetCharitiesResponse *gcr) +{ + struct StatusState *ss = cls; + + ss->cgh = NULL; + if (ss->expected_response_code != gcr->hr.http_status) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Unexpected HTTP response code: %d in %s:%u\n", + gcr->hr.http_status, + __FILE__, + __LINE__); + json_dumpf (gcr->hr.reply, + stderr, + 0); + TALER_TESTING_interpreter_fail (ss->is); + return; + } + TALER_TESTING_interpreter_next (ss->is); +} + + +/** + * Run the command. + * + * @param cls closure. + * @param cmd the command being executed. + * @param is the interpreter state. + */ +static void +status_run (void *cls, + const struct TALER_TESTING_Command *cmd, + struct TALER_TESTING_Interpreter *is) +{ + struct StatusState *ss = cls; + + ss->is = is; + + ss->cgh = DONAU_charities_get ( + TALER_TESTING_interpreter_get_context (is), + "http://localhost:8080/", //TODO: TALER_TESTING_get_donau_url (is), + ss->bearer, + &charities_status_cb, + ss); +} + +/** + * Cleanup the state from a "reserve status" CMD, and possibly + * cancel a pending operation thereof. + * + * @param cls closure. + * @param cmd the command which is being cleaned up. + */ +static void +status_cleanup (void *cls, + const struct TALER_TESTING_Command *cmd) +{ + struct StatusState *ss = cls; + + if (NULL != ss->cgh) + { + // log incomplete command + TALER_TESTING_command_incomplete (ss->is, + cmd->label); + DONAU_charities_get_cancel (ss->cgh); + ss->cgh = NULL; + } + GNUNET_free (ss); +} + + +struct TALER_TESTING_Command +TALER_TESTING_cmd_charities_get (const char *label, + unsigned int expected_response_code) +{ + struct StatusState *ss; + + ss = GNUNET_new (struct StatusState); + ss->expected_response_code = expected_response_code; + { + struct TALER_TESTING_Command cmd = { + .cls = ss, + .label = label, + .run = &status_run, + .cleanup = &status_cleanup + }; + + return cmd; + } +} diff --git a/src/testing/testing_api_cmd_charity_get.c b/src/testing/testing_api_cmd_charity_get.c @@ -18,7 +18,7 @@ */ /** * @file testing/testing_api_cmd_charity_get.c - * @brief Implement the GET /reserve/$RID test command. + * @brief Implement the GET /charities/$ID test command. * @author Marcello Stanisci * @author Lukas Matyja */ @@ -34,17 +34,6 @@ */ struct StatusState { - - /** - * How long do we give the donau to respond? - */ - struct GNUNET_TIME_Relative timeout; - - /** - * Poller waiting for us. - */ -// struct PollState *ps; - /** * Handle to the "charity status" operation. */ @@ -85,7 +74,6 @@ charity_status_cb (void *cls, const struct DONAU_GetCharityResponse *gcr) { struct StatusState *ss = cls; - struct TALER_TESTING_Interpreter *is = ss->is; ss->cgh = NULL; @@ -102,9 +90,7 @@ charity_status_cb (void *cls, TALER_TESTING_interpreter_fail (ss->is); return; } - - if (GNUNET_TIME_relative_is_zero (ss->timeout)) - TALER_TESTING_interpreter_next (is); + TALER_TESTING_interpreter_next (ss->is); } @@ -129,14 +115,8 @@ status_run (void *cls, "http://localhost:8080/", //TODO: TALER_TESTING_get_donau_url (is), ss->charity_id, ss->bearer, - ss->timeout, &charity_status_cb, ss); - if (! GNUNET_TIME_relative_is_zero (ss->timeout)) - { - TALER_TESTING_interpreter_next (is); - return; - } } /** @@ -168,14 +148,12 @@ struct TALER_TESTING_Command TALER_TESTING_cmd_charity_get (const char *label, const uint64_t charity_id, const struct DONAU_BearerToken bearer, - const struct GNUNET_TIME_Relative timeout, unsigned int expected_response_code) { struct StatusState *ss; ss = GNUNET_new (struct StatusState); ss->expected_response_code = expected_response_code; - ss->timeout = timeout; ss->bearer = bearer; ss->charity_id = charity_id; {