donau

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

commit 6999614c1ce7a80cff7a0b0b034547868424fa92
parent 5cf2adf773da81ef517d519ddf5b645732d8ddfc
Author: Matyja Lukas Adam <lukas.matyja@students.bfh.ch>
Date:   Thu,  7 Mar 2024 00:59:28 +0100

[testing] start using traits but the charity id from the server is missing

Diffstat:
Msrc/donau/donau-httpd_post-charity.c | 2+-
Msrc/include/donau_service.h | 2+-
Msrc/include/donau_testing_lib.h | 1+
Msrc/lib/donau_api_charity_post.c | 4++++
Dsrc/testing/insert_charity2.json | 8--------
Msrc/testing/test_donau_api.c | 3++-
Msrc/testing/testing_api_cmd_charity_get.c | 37++++++++++++++++++++++++-------------
Msrc/testing/testing_api_cmd_charity_post.c | 2+-
Msrc/testing/testing_api_cmd_get_donau.c | 24++++++++++++------------
9 files changed, 46 insertions(+), 37 deletions(-)

diff --git a/src/donau/donau-httpd_post-charity.c b/src/donau/donau-httpd_post-charity.c @@ -152,7 +152,7 @@ DH_handler_charity_post (struct DH_RequestContext *rc, } return TALER_MHD_reply_static ( rc->connection, - MHD_HTTP_NO_CONTENT, + MHD_HTTP_CREATED, NULL, NULL, 0); diff --git a/src/include/donau_service.h b/src/include/donau_service.h @@ -1088,7 +1088,7 @@ struct DONAU_PostCharityResponse /** * Information returned on success, if - * @e hr.http_status is #MHD_HTTP_OK + * @e hr.http_status is #MHD_HTTP_CREATED */ struct { diff --git a/src/include/donau_testing_lib.h b/src/include/donau_testing_lib.h @@ -63,6 +63,7 @@ TALER_TESTING_cmd_get_donau ( struct TALER_TESTING_Command TALER_TESTING_cmd_charity_get (const char *label, const uint64_t charity_id, + const char *charity_reference, const struct DONAU_BearerToken *bearer, unsigned int expected_response_code); diff --git a/src/lib/donau_api_charity_post.c b/src/lib/donau_api_charity_post.c @@ -90,7 +90,11 @@ handle_charity_post_finished (void *cls, cph->job = NULL; switch (response_code) { + case MHD_HTTP_CREATED: + break; case MHD_HTTP_NO_CONTENT: + pcresp.hr.ec = TALER_JSON_get_error_code (j); + pcresp.hr.hint = TALER_JSON_get_error_hint (j); break; case MHD_HTTP_FORBIDDEN: pcresp.hr.ec = TALER_JSON_get_error_code (j); diff --git a/src/testing/insert_charity2.json b/src/testing/insert_charity2.json @@ -1,8 +0,0 @@ -{ - "charity_pub": "ZT1SK8C3B1RZBN19TF8GJ1AJNF4GVP9MH64R9E1K6RMTMYYY17Z0", - "charity_name": "example", - "charity_url": "example.com", - "max_per_year": "EUR:10", - "receipts_to_date":"EUR:0", - "current_year": 2024 -} diff --git a/src/testing/test_donau_api.c b/src/testing/test_donau_api.c @@ -92,9 +92,10 @@ run (void *cls, "EUR:0", // receipts_to_date 2024, // current year &bearer, - MHD_HTTP_NO_CONTENT), + MHD_HTTP_CREATED), TALER_TESTING_cmd_charity_get ("get-charity-by-id", 8, + "post-charity", &bearer, MHD_HTTP_OK), TALER_TESTING_cmd_charities_get ("get-charities", diff --git a/src/testing/testing_api_cmd_charity_get.c b/src/testing/testing_api_cmd_charity_get.c @@ -59,8 +59,12 @@ struct StatusState */ struct TALER_TESTING_Interpreter *is; -}; + /** + * Reference to charity post command. + */ + const char *charity_reference; +}; /** * Check that the reserve balance and HTTP response code are @@ -110,17 +114,23 @@ status_run (void *cls, ss->is = is; /* Get charity id from trait */ -// { -// const unsigned long long *charity_id; -// if (GNUNET_OK != -// TALER_TESTING_get_trait_charity_id (cmd, -// &charity_id)) -// { -// GNUNET_break (0); -// TALER_TESTING_interpreter_fail (is); -// return; -// } -// } + { + const struct TALER_TESTING_Command *charity_post_cmd; + const unsigned long long *charity_id; + + charity_post_cmd = TALER_TESTING_interpreter_lookup_command (is, + ss->charity_reference); + + if (GNUNET_OK != + TALER_TESTING_get_trait_charity_id (charity_post_cmd, + &charity_id)) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (is); + return; + } + ss->charity_id = (uint64_t) *(charity_id); + } ss->cgh = DONAU_charity_get ( TALER_TESTING_interpreter_get_context (is), @@ -159,15 +169,16 @@ status_cleanup (void *cls, struct TALER_TESTING_Command TALER_TESTING_cmd_charity_get (const char *label, const uint64_t charity_id, + const char *charity_reference, const struct DONAU_BearerToken *bearer, unsigned int expected_response_code) { struct StatusState *ss; - ss = GNUNET_new (struct StatusState); ss->expected_response_code = expected_response_code; ss->bearer = bearer; ss->charity_id = charity_id; + ss->charity_reference = charity_reference; { struct TALER_TESTING_Command cmd = { .cls = ss, diff --git a/src/testing/testing_api_cmd_charity_post.c b/src/testing/testing_api_cmd_charity_post.c @@ -98,7 +98,7 @@ charity_status_cb (void *cls, TALER_TESTING_interpreter_fail (ss->is); return; } - if (MHD_HTTP_OK == gcr->hr.http_status) + if (ss->expected_response_code == gcr->hr.http_status) ss->charity_id = gcr->details.ok.charity_id; TALER_TESTING_interpreter_next (ss->is); } diff --git a/src/testing/testing_api_cmd_get_donau.c b/src/testing/testing_api_cmd_get_donau.c @@ -226,19 +226,19 @@ static char * get_donau_base_url ( const struct GNUNET_CONFIGURATION_Handle *cfg) { - char *donau_url = "http://localhost:8080/"; + char *donau_url; // = "http://localhost:8080/"; - // if (GNUNET_OK != - // GNUNET_CONFIGURATION_get_value_string (cfg, - // "donau", - // "BASE_URL", - // &donau_url)) - // { - // GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, - // "donau", - // "BASE_URL"); - // return NULL; - // } + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_string (cfg, + "donau", + "BASE_URL", + &donau_url)) + { + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + "donau", + "BASE_URL"); + return NULL; + } return donau_url; }