donau

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

donau_testing_lib.h (8346B)


      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 bearer authorization token
     71  * @param expected_response_code expected HTTP response code.
     72  * @return the command.
     73  */
     74 struct TALER_TESTING_Command
     75 TALER_TESTING_cmd_charity_post (const char *label,
     76                                 const char *name,
     77                                 const char *url,
     78                                 const char *max_per_year,
     79                                 const struct DONAU_BearerToken *bearer,
     80                                 unsigned int expected_response_code);
     81 
     82 /**
     83  * Create a PATCH "charity" command.
     84  *
     85  * @param label the command label.
     86  * @param charity_reference reference to an existing charity command
     87  * @param name updated name for the charity
     88  * @param url updated url for the charity
     89  * @param max_per_year updated limit as amount string
     90  * @param bearer authorization token
     91  * @param expected_response_code expected HTTP response code.
     92  * @return the command.
     93  */
     94 struct TALER_TESTING_Command
     95 TALER_TESTING_cmd_charity_patch (const char *label,
     96                                  const char *charity_reference,
     97                                  const char *name,
     98                                  const char *url,
     99                                  const char *max_per_year,
    100                                  const struct DONAU_BearerToken *bearer,
    101                                  unsigned int expected_response_code);
    102 
    103 /**
    104  * Create a DELETE "charity" command.
    105  *
    106  * @param label the command label.
    107  * @param charity_reference reference for traits
    108  * @param bearer authorization token
    109  * @param expected_response_code expected HTTP response code.
    110  * @return the command.
    111  */
    112 struct TALER_TESTING_Command
    113 TALER_TESTING_cmd_charity_delete (const char *label,
    114                                   const char *charity_reference,
    115                                   const struct DONAU_BearerToken *bearer,
    116                                   unsigned int expected_response_code);
    117 
    118 /**
    119  * Create a GET "charities" command.
    120  *
    121  * @param label the command label.
    122  * @param bearer authorization token
    123  * @param expected_response_code expected HTTP response code.
    124  * @return the command.
    125  */
    126 struct TALER_TESTING_Command
    127 TALER_TESTING_cmd_charities_get (const char *label,
    128                                  const struct DONAU_BearerToken *bearer,
    129                                  unsigned int expected_response_code);
    130 
    131 /**
    132  * Create a POST "batch-issue" command.
    133  *
    134  * @param label the command label.
    135  * @param charity_reference reference for traits
    136  * @param uses_cs true for cs and false for rsa.
    137  * @param year current year (mostly)
    138  * @param donor_tax_id tax id of the donor
    139  * @param salt for tax id hash
    140  * @param expected_response_code expected HTTP response code.
    141  * @return the command.
    142  */
    143 struct TALER_TESTING_Command
    144 TALER_TESTING_cmd_issue_receipts (const char *label,
    145                                   const char *charity_reference,
    146                                   const bool uses_cs,
    147                                   const uint64_t year,
    148                                   const char *donor_tax_id,
    149                                   const char *salt,
    150                                   const char *issue_amount,
    151                                   unsigned int expected_response_code);
    152 
    153 
    154 /**
    155  * Create a POST "batch-issue" command.
    156  *
    157  * @param label the command label.
    158  * @param issue_receipt_reference reference for traits
    159  * @param year current or past year (mostly)
    160  * @param expected_response_code expected HTTP response code.
    161  * @return the command.
    162  */
    163 struct TALER_TESTING_Command
    164 TALER_TESTING_cmd_submit_receipts (const char *label,
    165                                    const char *issue_receipt_reference,
    166                                    const uint64_t year,
    167                                    unsigned int expected_response_code);
    168 
    169 
    170 /**
    171  * Create a GET "donation-statement" command.
    172  *
    173  * @param label the command label.
    174  * @param year current or past year (mostly)
    175  * @param expected_response_code expected HTTP response code.
    176  * @return the command.
    177  */
    178 struct TALER_TESTING_Command
    179 TALER_TESTING_cmd_donation_statement_get (const char *label,
    180                                           uint64_t year,
    181                                           unsigned int expected_response_code);
    182 
    183 
    184 /**
    185  * Convenience function to run a test.
    186  *
    187  * @param argv command-line arguments given
    188  * @param loglevel log level to use
    189  * @param cfg_file configuration file to use
    190  * @param[in,out] cred global credentials to initialize
    191  * @param main_cb main test function to run
    192  * @param main_cb_cls closure for @a main_cb
    193  * @return 0 on success, 77 on setup trouble, non-zero process status code otherwise
    194  */
    195 int
    196 DONAU_TESTING_main (char *const *argv,
    197                     const char *loglevel,
    198                     const char *cfg_file,
    199                     struct TALER_TESTING_Credentials *cred,
    200                     TALER_TESTING_Main main_cb,
    201                     void *main_cb_cls);
    202 
    203 /* ****************** convenience functions ************** */
    204 
    205 /**
    206  * Get donau URL from interpreter. Convenience function.
    207  *
    208  * @param is interpreter state.
    209  * @return the donau URL, or NULL on error
    210  */
    211 const char *
    212 TALER_TESTING_get_donau_url (
    213   struct TALER_TESTING_Interpreter *is);
    214 
    215 /* ****** Specific traits supported by this component ******* */
    216 
    217 
    218 /**
    219  * Call #op on all simple traits.
    220  */
    221 #define DONAU_TESTING_SIMPLE_TRAITS(op) \
    222   op (charity_priv, const struct DONAU_CharityPrivateKeyP)        \
    223   op (charity_pub, const struct DONAU_CharityPublicKeyP)        \
    224   op (charity_id, const uint64_t)        \
    225   op (donau_url, const char)                                                \
    226   op (donau_keys, struct DONAU_Keys) \
    227   op (donor_salt, const char)                                                \
    228   op (donor_tax_id, const char)                                                \
    229   op (salted_tax_id_hash, const struct DONAU_HashDonorTaxId) \
    230   op (donation_receipts, const struct DONAU_DonationReceipt*) \
    231   op (number_receipts, const size_t)
    232 
    233 
    234 /**
    235  * Call #op on all indexed traits.
    236  */
    237 #define DONAU_TESTING_INDEXED_TRAITS(op)                                          \
    238   op (donation_unit_pub, const struct DONAU_DonationUnitInformation)        \
    239   op (donau_pub, const struct TALER_ExchangePublicKeyP)
    240 
    241 DONAU_TESTING_SIMPLE_TRAITS (TALER_TESTING_MAKE_DECL_SIMPLE_TRAIT)
    242 DONAU_TESTING_INDEXED_TRAITS (TALER_TESTING_MAKE_DECL_INDEXED_TRAIT)
    243 
    244 #endif