donau

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

commit 576e5b2d865eef36e04aa66458732ba02d685616
parent a43c752cdd68cb33e673f99cb393f958739d55d4
Author: Matyja Lukas Adam <lukas.matyja@students.bfh.ch>
Date:   Thu, 18 Jan 2024 01:01:57 +0100

[testing] add charity get test

Diffstat:
Msrc/include/donau_testing_lib.h | 13+++++++++++++
Msrc/lib/donau_api_handle.c | 2+-
Msrc/testing/Makefile.am | 3++-
Msrc/testing/test_donau_api.c | 3+++
Asrc/testing/testing_api_cmd_charity_get.c | 224+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rsrc/testing/test_api_cmd_get_donau.c -> src/testing/testing_api_cmd_get_donau.c | 0
6 files changed, 243 insertions(+), 2 deletions(-)

diff --git a/src/include/donau_testing_lib.h b/src/include/donau_testing_lib.h @@ -51,6 +51,19 @@ TALER_TESTING_cmd_get_donau ( bool wait_for_keys, bool load_private_key); +/** + * Create a GET "charity" command with a @a timeout. + * + * @param label the command label. + * @param timeout how long to long-poll for the charity to exist. + * @param expected_response_code expected HTTP response code. + * @return the command. + */ +struct TALER_TESTING_Command +TALER_TESTING_cmd_charity_get (const char *label, + struct GNUNET_TIME_Relative timeout, + unsigned int expected_response_code); + /** * Convenience function to run a test. * diff --git a/src/lib/donau_api_handle.c b/src/lib/donau_api_handle.c @@ -442,7 +442,7 @@ EXITIF_exit: * @param resp_obj parsed JSON result, NULL on error */ static void -keys_completed_cb (void *cls, +c (void *cls, long response_code, const void *resp_obj) { diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am @@ -20,7 +20,8 @@ libdonautesting_la_LDFLAGS = \ -version-info 0:0:0 \ -no-undefined libdonautesting_la_SOURCES = \ - test_api_cmd_get_donau.c \ + testing_api_cmd_get_donau.c \ + testing_api_cmd_charity_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 @@ -74,6 +74,9 @@ run (void *cls, cred.cfg, true, true), + TALER_TESTING_cmd_charity_get ("get-charity-1", + GNUNET_TIME_UNIT_SECONDS, + MHD_HTTP_OK), /* End the suite. */ TALER_TESTING_cmd_end () }; diff --git a/src/testing/testing_api_cmd_charity_get.c b/src/testing/testing_api_cmd_charity_get.c @@ -0,0 +1,224 @@ +/* + 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_reserve_get.c + * @brief Implement the GET /reserve/$RID test command. + * @author Marcello Stanisci + * @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 "poll" CMD. + */ +struct PollState +{ + + /** + * How long do we give the exchange to respond? + */ + struct GNUNET_TIME_Relative timeout; + + /** + * Label to the command which created the reserve to check, + * needed to resort the reserve key. + */ + const char *poll_reference; + + /** + * Timeout to wait for at most. + */ + //struct GNUNET_SCHEDULER_Task *tt; + + /** + * The interpreter we are using. + */ + struct TALER_TESTING_Interpreter *is; +}; + + +/** + * State for a "status" CMD. + */ +struct StatusState +{ + + /** + * How long do we give the donau to respond? + */ + struct GNUNET_TIME_Relative timeout; + + /** + * Poller waiting for us. + */ + struct PollState *ps; + + /** + * Label to the command which created the reserve to check, + * needed to resort the reserve key. + */ + // const char *reserve_reference; + + /** + * Handle to the "charity status" operation. + */ + struct DONAU_CharityGetHandle *cgh; + + /** + * Expected reserve balance. + */ + // const char *expected_balance; + + /** + * Public key of the reserve being analyzed. + */ + // const struct TALER_ReservePublicKeyP *reserve_pubp; + + /** + * 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 +charity_status_cb (void *cls, + const struct DONAU_GetCharityResponse *gcr) +{ + struct StatusState *ss = cls; + struct TALER_TESTING_Interpreter *is = ss->is; + + + 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; + } + + if (GNUNET_TIME_relative_is_zero (ss->timeout)) + TALER_TESTING_interpreter_next (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; + const char *donau_url = "http://localhost:8080/"; + + ss->is = is; + + struct DONAU_BearerToken bearer; + bearer.token = NULL; + ss->cgh = DONAU_charity_get ( + TALER_TESTING_interpreter_get_context (is), + donau_url, + 1, + bearer, + ss->timeout, + &charity_status_cb, + ss); + if (! GNUNET_TIME_relative_is_zero (ss->timeout)) + { + TALER_TESTING_interpreter_next (is); + return; + } +} + +/** + * 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) + { + // TALER_TESTING_command_incomplete (ss->is, + // cmd->label); + DONAU_charity_get_cancel (ss->cgh); + ss->cgh = NULL; + } + GNUNET_free (ss); +} + + +struct TALER_TESTING_Command +TALER_TESTING_cmd_charity_get (const char *label, + 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; + { + struct TALER_TESTING_Command cmd = { + .cls = ss, + .label = label, + .run = &status_run, + .cleanup = &status_cleanup + }; + + return cmd; + } +} diff --git a/src/testing/test_api_cmd_get_donau.c b/src/testing/testing_api_cmd_get_donau.c