donau

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

commit 454a3fc3011b9674f1d1817d8eac9b2b3b534ad3
parent 7dc8c45a07d31f7da8db8390281c9e1aebc1c4e3
Author: Matyja Lukas Adam <lukas.matyja@students.bfh.ch>
Date:   Tue, 27 Feb 2024 15:34:12 +0100

[lib][testing] finish charity get

Diffstat:
Msrc/include/donau_service.h | 2+-
Msrc/include/donau_testing_lib.h | 20+++++++++++++++++---
Msrc/lib/donau_api_charity_get.c | 58++++++++++++----------------------------------------------
Msrc/testing/test_donau_api.c | 6+++++-
Msrc/testing/testing_api_cmd_charity_get.c | 65++++++++++++++++-------------------------------------------------
Msrc/testing/testing_api_traits.c | 25+++++++++++++++++++++++++
6 files changed, 76 insertions(+), 100 deletions(-)

diff --git a/src/include/donau_service.h b/src/include/donau_service.h @@ -969,7 +969,7 @@ struct DONAU_GetCharityResponse /** * Charity status information. */ - struct DONAU_Charity *charity; + struct DONAU_Charity charity; } ok; diff --git a/src/include/donau_testing_lib.h b/src/include/donau_testing_lib.h @@ -55,13 +55,17 @@ TALER_TESTING_cmd_get_donau ( * Create a GET "charity" command with a @a timeout. * * @param label the command label. + * @param charity_id + * @param bearer authorization token * @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, + const uint64_t charity_id, + const struct DONAU_BearerToken bearer, + const struct GNUNET_TIME_Relative timeout, unsigned int expected_response_code); /** @@ -83,6 +87,17 @@ DONAU_TESTING_main (char *const *argv, TALER_TESTING_Main main_cb, void *main_cb_cls); +/* ****************** convenience functions ************** */ + +/** + * Get donau URL from interpreter. Convenience function. + * + * @param is interpreter state. + * @return the donau URL, or NULL on error + */ +const char * +TALER_TESTING_get_donau_url ( + struct TALER_TESTING_Interpreter *is); /* ****** Specific traits supported by this component ******* */ @@ -105,4 +120,4 @@ DONAU_TESTING_main (char *const *argv, DONAU_TESTING_SIMPLE_TRAITS (TALER_TESTING_MAKE_DECL_SIMPLE_TRAIT) DONAU_TESTING_INDEXED_TRAITS (TALER_TESTING_MAKE_DECL_INDEXED_TRAIT) -#endif -\ No newline at end of file +#endif diff --git a/src/lib/donau_api_charity_get.c b/src/lib/donau_api_charity_get.c @@ -73,10 +73,9 @@ struct DONAU_CharityGetHandle static enum GNUNET_GenericReturnValue handle_charity_get_ok (const json_t *resp_obj, struct DONAU_CharityGetHandle *cgh, - struct DONAU_Charity *charity, struct DONAU_GetCharityResponse *gcresp) { - // const json_t *charity_hist_array; + struct DONAU_Charity *charity = &gcresp->details.ok.charity; const char *name; if (JSON_OBJECT != json_typeof (resp_obj)) { @@ -85,16 +84,16 @@ handle_charity_get_ok (const json_t *resp_obj, } struct GNUNET_JSON_Specification spec[] = { -// GNUNET_JSON_spec_fixed_auto ("charity_pub", -// &charity->charity_pub), -// GNUNET_JSON_spec_string ("name", &name), -// TALER_JSON_spec_amount_any ("max_per_year", -// &charity->max_per_year), -// TALER_JSON_spec_amount_any ("receipts_to_date", -// &charity-> -// receipts_to_date), -// GNUNET_JSON_spec_uint64 ("current_year", -// &charity->current_year), + GNUNET_JSON_spec_fixed_auto ("charity_pub", + &charity->charity_pub), + GNUNET_JSON_spec_string ("name", &name), + TALER_JSON_spec_amount_any ("max_per_year", + &charity->max_per_year), + TALER_JSON_spec_amount_any ("receipts_to_date", + &charity-> + receipts_to_date), + GNUNET_JSON_spec_uint64 ("current_year", + &charity->current_year), GNUNET_JSON_spec_end () }; if (GNUNET_OK != @@ -106,39 +105,7 @@ handle_charity_get_ok (const json_t *resp_obj, GNUNET_break_op (0); return GNUNET_SYSERR; } - //charity->name = GNUNET_strdup (name); - - /* parse the charity history data */ - // charity_resp.details.ok.charity->num_hist - // = json_array_size (charity_hist_array); - // if (0 != charity_resp.details.ok.charity->num_hist) - // { - // json_t *charity_history_obj; - // unsigned int index; - - // charity_resp.details.ok.charity->donation_history - // = GNUNET_new_array (charity_resp.details.ok.charity->num_hist, - // struct DONAU_CharityHistoryYear); - // json_array_foreach (charity_hist_array, index, charity_history_obj) { - // struct DONAU_CharityHistoryYear *donation_history = &charity_resp.details.ok.charity->donation_history[index]; - // struct GNUNET_JSON_Specification history_spec[] = { - // TALER_JSON_spec_amount_any ("final_amount", - // &donation_history->final_amount), - // GNUNET_JSON_spec_uint32 ("year", - // &donation_history->year), - // GNUNET_JSON_spec_end () - // }; - - // if (GNUNET_OK != - // GNUNET_JSON_parse (charity_history_obj, - // history_spec, - // NULL, NULL)) - // { - // GNUNET_break_op (0); - // return GNUNET_SYSERR; - // } - // } - // } + charity->name = GNUNET_strdup (name); cgh->cb (cgh->cb_cls, gcresp); @@ -179,7 +146,6 @@ handle_charity_get_finished (void *cls, if (GNUNET_OK != handle_charity_get_ok (j, cgh, - &gcresp.details.ok.charity, &gcresp)) { gcresp.hr.http_status = 0; diff --git a/src/testing/test_donau_api.c b/src/testing/test_donau_api.c @@ -64,6 +64,8 @@ static void run (void *cls, struct TALER_TESTING_Interpreter *is) { + struct DONAU_BearerToken bearer; + bearer.token = NULL; { struct TALER_TESTING_Command commands[] = { TALER_TESTING_cmd_system_start ("start-donau", @@ -74,7 +76,9 @@ run (void *cls, // cred.cfg, // true, // true), - TALER_TESTING_cmd_charity_get ("get-charity-1", + 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 diff --git a/src/testing/testing_api_cmd_charity_get.c b/src/testing/testing_api_cmd_charity_get.c @@ -30,35 +30,6 @@ /** - * 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 @@ -72,13 +43,7 @@ struct StatusState /** * 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; +// struct PollState *ps; /** * Handle to the "charity status" operation. @@ -86,14 +51,14 @@ struct StatusState struct DONAU_CharityGetHandle *cgh; /** - * Expected reserve balance. + * The bearer token for authorization. */ - // const char *expected_balance; + struct DONAU_BearerToken bearer; /** - * Public key of the reserve being analyzed. + * The ID of the requested charity. */ - // const struct TALER_ReservePublicKeyP *reserve_pubp; + uint64_t charity_id; /** * Expected HTTP response code. @@ -156,17 +121,14 @@ status_run (void *cls, 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, - 4, - bearer, + "http://localhost:8080/", //TODO: TALER_TESTING_get_donau_url (is), + ss->charity_id, + ss->bearer, ss->timeout, &charity_status_cb, ss); @@ -192,8 +154,9 @@ status_cleanup (void *cls, if (NULL != ss->cgh) { - // TALER_TESTING_command_incomplete (ss->is, - // cmd->label); + // log incomplete command + TALER_TESTING_command_incomplete (ss->is, + cmd->label); DONAU_charity_get_cancel (ss->cgh); ss->cgh = NULL; } @@ -203,7 +166,9 @@ status_cleanup (void *cls, struct TALER_TESTING_Command TALER_TESTING_cmd_charity_get (const char *label, - struct GNUNET_TIME_Relative timeout, + const uint64_t charity_id, + const struct DONAU_BearerToken bearer, + const struct GNUNET_TIME_Relative timeout, unsigned int expected_response_code) { struct StatusState *ss; @@ -211,6 +176,8 @@ TALER_TESTING_cmd_charity_get (const char *label, ss = GNUNET_new (struct StatusState); ss->expected_response_code = expected_response_code; ss->timeout = timeout; + ss->bearer = bearer; + ss->charity_id = charity_id; { struct TALER_TESTING_Command cmd = { .cls = ss, diff --git a/src/testing/testing_api_traits.c b/src/testing/testing_api_traits.c @@ -30,5 +30,30 @@ DONAU_TESTING_SIMPLE_TRAITS (TALER_TESTING_MAKE_IMPL_SIMPLE_TRAIT) DONAU_TESTING_INDEXED_TRAITS (TALER_TESTING_MAKE_IMPL_INDEXED_TRAIT) +const char * +TALER_TESTING_get_donau_url (struct TALER_TESTING_Interpreter *is) +{ + const char *donau_url; + const struct TALER_TESTING_Command *donau_cmd; + + donau_cmd + = TALER_TESTING_interpreter_get_command (is, + "donau"); + if (NULL == donau_cmd) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (is); + return NULL; + } + if (GNUNET_OK != + TALER_TESTING_get_trait_donau_url (donau_cmd, + &donau_url)) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (is); + return NULL; + } + return donau_url; +} /* end of testing_api_traits.c */