donau

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

commit 3420b088d28c5e8579ddcf46621508f599cb6757
parent 9b63dd74948f41881801109a966217f869aa3840
Author: Matyja Lukas Adam <lukas.matyja@students.bfh.ch>
Date:   Tue, 28 May 2024 21:32:55 +0200

[testing] add get donation-statement test

Diffstat:
Msrc/include/donau_testing_lib.h | 14++++++++++++++
Msrc/testing/Makefile.am | 1+
Msrc/testing/test_donau_api.c | 5++++-
Asrc/testing/testing_api_cmd_donation_statement_get.c | 177+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 196 insertions(+), 1 deletion(-)

diff --git a/src/include/donau_testing_lib.h b/src/include/donau_testing_lib.h @@ -151,6 +151,20 @@ TALER_TESTING_cmd_submit_receipts (const char *label, /** + * Create a GET "donation-statement" command. + * + * @param label the command label. + * @param year current or past year (mostly) + * @param expected_response_code expected HTTP response code. + * @return the command. + */ +struct TALER_TESTING_Command +TALER_TESTING_cmd_donation_statement_get (const char *label, + uint64_t year, + unsigned int expected_response_code); + + +/** * Convenience function to run a test. * * @param argv command-line arguments given diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am @@ -27,6 +27,7 @@ libdonautesting_la_SOURCES = \ testing_api_cmd_charity_delete.c \ testing_api_cmd_issue_receipts.c \ testing_api_cmd_submit_receipts.c \ + testing_api_cmd_donation_statement_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 @@ -95,10 +95,13 @@ run (void *cls, "7560001010000", // tax id "1234", // salt for tax id hash MHD_HTTP_CREATED), - TALER_TESTING_cmd_submit_receipts ("submit-receipts", + TALER_TESTING_cmd_submit_receipts ("submit-receipts", "issue-receipts", // cmd trait reference 2024, MHD_HTTP_OK), + TALER_TESTING_cmd_donation_statement_get ("donation-statement", + 2024, + MHD_HTTP_OK), TALER_TESTING_cmd_charity_delete ("delete-charity", "post-charity", // cmd trait reference &bearer, diff --git a/src/testing/testing_api_cmd_donation_statement_get.c b/src/testing/testing_api_cmd_donation_statement_get.c @@ -0,0 +1,177 @@ +/* + This file is part of TALER + Copyright (C) 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_donation_statement_get.c + * @brief Implement the GET /donation-statement/$YEAR/$HASH_DONOR_ID 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 "status" CMD. + */ +struct StatusState +{ + /** + * Handle to the "charity status" operation. + */ + struct DONAU_DonationStatementGetHandle *dsgh; + + /** + * Expected HTTP response code. + */ + unsigned int expected_response_code; + + /** + * Interpreter state. + */ + struct TALER_TESTING_Interpreter *is; + + /** + * The Donation Statement + */ + struct DONAU_DonationStatement donation_statement; + +}; + +/** + * Check that the reserve balance and HTTP response code are + * both acceptable. + * + * @param cls closure. + * @param dsr HTTP response details + */ +static void +charity_status_cb (void *cls, + const struct DONAU_DonationStatementResponse *dsr) +{ + struct StatusState *ss = cls; + + ss->dsgh = NULL; + if (ss->expected_response_code != dsr->hr.http_status) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Unexpected HTTP response code: %d in %s:%u\n", + dsr->hr.http_status, + __FILE__, + __LINE__); + json_dumpf (dsr->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; + /* Get charity salted tax id hash from trait */ + { + const struct TALER_TESTING_Command *issue_receipts_cmd; + const struct DONAU_HashDonorTaxId *h_donor_tax_id; + + issue_receipts_cmd = TALER_TESTING_interpreter_lookup_command (is, + "issue-receipts"); + + if (GNUNET_OK != + TALER_TESTING_get_trait_salted_tax_id_hash (issue_receipts_cmd, + &h_donor_tax_id)) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (is); + return; + } + ss->donation_statement.h_donor_tax_id = (struct DONAU_HashDonorTaxId*) h_donor_tax_id; + } + + ss->dsgh = DONAU_donation_statement_get ( + TALER_TESTING_interpreter_get_context (is), + TALER_TESTING_get_donau_url (is), + ss->donation_statement.year, + ss->donation_statement.h_donor_tax_id, + &charity_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->dsgh) + { + // log incomplete command + TALER_TESTING_command_incomplete (ss->is, + cmd->label); + DONAU_donation_statement_get_cancel (ss->dsgh); + ss->dsgh = NULL; + } + GNUNET_free (ss); +} + + +struct TALER_TESTING_Command +TALER_TESTING_cmd_donation_statement_get (const char *label, + uint64_t year, + unsigned int expected_response_code) +{ + struct StatusState *ss; + ss = GNUNET_new (struct StatusState); + ss->donation_statement.year = year; + ss->expected_response_code = expected_response_code; + { + struct TALER_TESTING_Command cmd = { + .cls = ss, + .label = label, + .run = &status_run, + .cleanup = &status_cleanup + }; + + return cmd; + } +}