donau_testing_lib.h (8555B)
1 /* 2 This file is part of TALER 3 (C) 2018-2023 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as 7 published by the Free Software Foundation; either version 3, or 8 (at your option) any later version. 9 10 TALER is distributed in the hope that it will be useful, but 11 WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public 16 License along with TALER; see the file COPYING. If not, see 17 <http://www.gnu.org/licenses/> 18 */ 19 20 /** 21 * @file include/donau_testing_lib.h 22 * @brief API for writing an interpreter to test Taler components 23 * @author Christian Grothoff <christian@grothoff.org> 24 * @author Marcello Stanisci 25 * @author Lukas Matyja 26 * 27 */ 28 #ifndef DONAU_TESTING_LIB_H 29 #define DONAU_TESTING_LIB_H 30 31 #include <stdint.h> 32 #include <taler/taler_testing_lib.h> 33 #include "donau_service.h" 34 35 36 /** 37 * Connects to the exchange. 38 * 39 * @param label command label 40 * @param cfg configuration to use 41 * @param wait_for_keys block until we got /keys 42 * @return the command. 43 */ 44 struct TALER_TESTING_Command 45 TALER_TESTING_cmd_get_donau ( 46 const char *label, 47 const struct GNUNET_CONFIGURATION_Handle *cfg, 48 bool wait_for_keys); 49 50 51 /** 52 * Create a GET "charity" command. 53 * 54 * @param label the command label. 55 * @param charity_reference reference for traits 56 * @param expected_response_code expected HTTP response code. 57 * @return the command. 58 */ 59 struct TALER_TESTING_Command 60 TALER_TESTING_cmd_charity_get (const char *label, 61 const char *charity_reference, 62 unsigned int expected_response_code); 63 64 /** 65 * Create a POST "charity" command. 66 * 67 * @param label the command label. 68 * @param name of the charity 69 * @param url of the charity 70 * @param max_per_year per-year donation limit as amount string 71 * @param bearer authorization token 72 * @param expected_response_code expected HTTP response code. 73 * @return the command. 74 */ 75 struct TALER_TESTING_Command 76 TALER_TESTING_cmd_charity_post (const char *label, 77 const char *name, 78 const char *url, 79 const char *max_per_year, 80 const struct DONAU_BearerToken *bearer, 81 unsigned int expected_response_code); 82 83 /** 84 * Create a PATCH "charity" command. 85 * 86 * @param label the command label. 87 * @param charity_reference reference to an existing charity command 88 * @param name updated name for the charity 89 * @param url updated url for the charity 90 * @param max_per_year updated limit as amount string 91 * @param bearer authorization token 92 * @param expected_response_code expected HTTP response code. 93 * @return the command. 94 */ 95 struct TALER_TESTING_Command 96 TALER_TESTING_cmd_charity_patch (const char *label, 97 const char *charity_reference, 98 const char *name, 99 const char *url, 100 const char *max_per_year, 101 const struct DONAU_BearerToken *bearer, 102 unsigned int expected_response_code); 103 104 /** 105 * Create a DELETE "charity" command. 106 * 107 * @param label the command label. 108 * @param charity_reference reference for traits 109 * @param bearer authorization token 110 * @param expected_response_code expected HTTP response code. 111 * @return the command. 112 */ 113 struct TALER_TESTING_Command 114 TALER_TESTING_cmd_charity_delete (const char *label, 115 const char *charity_reference, 116 const struct DONAU_BearerToken *bearer, 117 unsigned int expected_response_code); 118 119 /** 120 * Create a GET "charities" command. 121 * 122 * @param label the command label. 123 * @param bearer authorization token 124 * @param expected_response_code expected HTTP response code. 125 * @return the command. 126 */ 127 struct TALER_TESTING_Command 128 TALER_TESTING_cmd_charities_get (const char *label, 129 const struct DONAU_BearerToken *bearer, 130 unsigned int expected_response_code); 131 132 /** 133 * Create a POST "batch-issue" command. 134 * 135 * @param label the command label. 136 * @param charity_reference reference for traits 137 * @param uses_cs true for cs and false for rsa. 138 * @param year current year (mostly) 139 * @param donor_tax_id tax id of the donor 140 * @param salt for tax id hash 141 * @param issue_amount donation amount string used for the receipt batch 142 * @param expected_response_code expected HTTP response code. 143 * @return the command. 144 */ 145 struct TALER_TESTING_Command 146 TALER_TESTING_cmd_issue_receipts (const char *label, 147 const char *charity_reference, 148 const bool uses_cs, 149 const uint64_t year, 150 const char *donor_tax_id, 151 const char *salt, 152 const char *issue_amount, 153 unsigned int expected_response_code); 154 155 156 /** 157 * Create a POST "batch-issue" command. 158 * 159 * @param label the command label. 160 * @param issue_receipt_reference reference for traits 161 * @param year current or past year (mostly) 162 * @param expected_response_code expected HTTP response code. 163 * @return the command. 164 */ 165 struct TALER_TESTING_Command 166 TALER_TESTING_cmd_submit_receipts (const char *label, 167 const char *issue_receipt_reference, 168 const uint64_t year, 169 unsigned int expected_response_code); 170 171 172 /** 173 * Create a GET "donation-statement" command. 174 * 175 * @param label the command label. 176 * @param year current or past year (mostly) 177 * @param expected_response_code expected HTTP response code. 178 * @return the command. 179 */ 180 struct TALER_TESTING_Command 181 TALER_TESTING_cmd_donation_statement_get (const char *label, 182 uint64_t year, 183 unsigned int expected_response_code); 184 185 186 /** 187 * Convenience function to run a test. 188 * 189 * @param argv command-line arguments given 190 * @param loglevel log level to use 191 * @param cfg_file configuration file to use 192 * @param[in,out] cred global credentials to initialize 193 * @param main_cb main test function to run 194 * @param main_cb_cls closure for @a main_cb 195 * @return 0 on success, 77 on setup trouble, non-zero process status code otherwise 196 */ 197 int 198 DONAU_TESTING_main (char *const *argv, 199 const char *loglevel, 200 const char *cfg_file, 201 struct TALER_TESTING_Credentials *cred, 202 TALER_TESTING_Main main_cb, 203 void *main_cb_cls); 204 205 /* ****************** convenience functions ************** */ 206 207 /** 208 * Get donau URL from interpreter. Convenience function. 209 * 210 * @param is interpreter state. 211 * @return the donau URL, or NULL on error 212 */ 213 const char * 214 TALER_TESTING_get_donau_url ( 215 struct TALER_TESTING_Interpreter *is); 216 217 /* ****** Specific traits supported by this component ******* */ 218 219 220 /** 221 * Call #op on all simple traits. 222 */ 223 #define DONAU_TESTING_SIMPLE_TRAITS(op) \ 224 op (charity_priv, const struct DONAU_CharityPrivateKeyP) \ 225 op (charity_pub, const struct DONAU_CharityPublicKeyP) \ 226 op (charity_id, const uint64_t) \ 227 op (donau_url, const char) \ 228 op (donau_keys, struct DONAU_Keys) \ 229 op (donor_salt, const char) \ 230 op (donor_tax_id, const char) \ 231 op (salted_tax_id_hash, const struct DONAU_HashDonorTaxId) \ 232 op (donation_receipts, const struct DONAU_DonationReceipt*) \ 233 op (number_receipts, const size_t) 234 235 236 /** 237 * Call #op on all indexed traits. 238 */ 239 #define DONAU_TESTING_INDEXED_TRAITS(op) \ 240 op (donation_unit_pub, const struct DONAU_DonationUnitInformation) \ 241 op (donau_pub, const struct TALER_ExchangePublicKeyP) 242 243 DONAU_TESTING_SIMPLE_TRAITS (TALER_TESTING_MAKE_DECL_SIMPLE_TRAIT) 244 DONAU_TESTING_INDEXED_TRAITS (TALER_TESTING_MAKE_DECL_INDEXED_TRAIT) 245 246 #endif