Line data Source code
1 : /* 2 : This file is part of TALER 3 : Copyright (C) 2020 Taler Systems SA 4 : 5 : TALER is free software; you can redistribute it and/or modify it 6 : under the terms of the GNU General Public License as published by 7 : the Free Software Foundation; either version 3, or (at your 8 : 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 GNU 13 : 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 : * @file testing/testing_api_cmd_purse_delete.c 21 : * @brief command for testing /management/purse/disable. 22 : * @author Christian Grothoff 23 : */ 24 : #include "platform.h" 25 : #include "taler_json_lib.h" 26 : #include <gnunet/gnunet_curl_lib.h> 27 : #include "taler_testing_lib.h" 28 : #include "taler_signatures.h" 29 : #include "backoff.h" 30 : 31 : 32 : /** 33 : * State for a "purse_delete" CMD. 34 : */ 35 : struct PurseDeleteState 36 : { 37 : 38 : /** 39 : * Purse delete handle while operation is running. 40 : */ 41 : struct TALER_EXCHANGE_PurseDeleteHandle *pdh; 42 : 43 : /** 44 : * Our interpreter. 45 : */ 46 : struct TALER_TESTING_Interpreter *is; 47 : 48 : /** 49 : * Expected HTTP response code. 50 : */ 51 : unsigned int expected_response_code; 52 : 53 : /** 54 : * Command that created the purse we now want to 55 : * delete. 56 : */ 57 : const char *purse_cmd; 58 : }; 59 : 60 : 61 : /** 62 : * Callback to analyze the DELETE /purses/$PID response, just used to check if 63 : * the response code is acceptable. 64 : * 65 : * @param cls closure. 66 : * @param pdr HTTP response details 67 : */ 68 : static void 69 2 : purse_delete_cb (void *cls, 70 : const struct TALER_EXCHANGE_PurseDeleteResponse *pdr) 71 : { 72 2 : struct PurseDeleteState *pds = cls; 73 : 74 2 : pds->pdh = NULL; 75 2 : if (pds->expected_response_code != pdr->hr.http_status) 76 : { 77 0 : TALER_TESTING_unexpected_status (pds->is, 78 : pdr->hr.http_status, 79 : pds->expected_response_code); 80 0 : return; 81 : } 82 2 : TALER_TESTING_interpreter_next (pds->is); 83 : } 84 : 85 : 86 : /** 87 : * Run the command. 88 : * 89 : * @param cls closure. 90 : * @param cmd the command to execute. 91 : * @param is the interpreter state. 92 : */ 93 : static void 94 2 : purse_delete_run (void *cls, 95 : const struct TALER_TESTING_Command *cmd, 96 : struct TALER_TESTING_Interpreter *is) 97 : { 98 2 : struct PurseDeleteState *pds = cls; 99 : const struct TALER_PurseContractPrivateKeyP *purse_priv; 100 : const struct TALER_TESTING_Command *ref; 101 : const char *exchange_url; 102 : 103 : (void) cmd; 104 2 : exchange_url = TALER_TESTING_get_exchange_url (is); 105 2 : if (NULL == exchange_url) 106 : { 107 0 : GNUNET_break (0); 108 0 : return; 109 : } 110 2 : ref = TALER_TESTING_interpreter_lookup_command (is, 111 : pds->purse_cmd); 112 2 : if (NULL == ref) 113 : { 114 0 : GNUNET_break (0); 115 0 : TALER_TESTING_interpreter_fail (is); 116 0 : return; 117 : } 118 2 : if (GNUNET_OK != 119 2 : TALER_TESTING_get_trait_purse_priv (ref, 120 : &purse_priv)) 121 : { 122 0 : GNUNET_break (0); 123 0 : TALER_TESTING_interpreter_fail (is); 124 0 : return; 125 : } 126 2 : pds->is = is; 127 2 : pds->pdh = TALER_EXCHANGE_purse_delete ( 128 : TALER_TESTING_interpreter_get_context (is), 129 : exchange_url, 130 : purse_priv, 131 : &purse_delete_cb, 132 : pds); 133 2 : if (NULL == pds->pdh) 134 : { 135 0 : GNUNET_break (0); 136 0 : TALER_TESTING_interpreter_fail (is); 137 0 : return; 138 : } 139 : } 140 : 141 : 142 : /** 143 : * Free the state of a "purse_delete" CMD, and possibly cancel a 144 : * pending operation thereof. 145 : * 146 : * @param cls closure, must be a `struct PurseDeleteState`. 147 : * @param cmd the command which is being cleaned up. 148 : */ 149 : static void 150 2 : purse_delete_cleanup (void *cls, 151 : const struct TALER_TESTING_Command *cmd) 152 : { 153 2 : struct PurseDeleteState *pds = cls; 154 : 155 2 : if (NULL != pds->pdh) 156 : { 157 0 : TALER_TESTING_command_incomplete (pds->is, 158 : cmd->label); 159 0 : TALER_EXCHANGE_purse_delete_cancel (pds->pdh); 160 0 : pds->pdh = NULL; 161 : } 162 2 : GNUNET_free (pds); 163 2 : } 164 : 165 : 166 : struct TALER_TESTING_Command 167 2 : TALER_TESTING_cmd_purse_delete (const char *label, 168 : unsigned int expected_http_status, 169 : const char *purse_cmd) 170 : { 171 : struct PurseDeleteState *ds; 172 : 173 2 : ds = GNUNET_new (struct PurseDeleteState); 174 2 : ds->expected_response_code = expected_http_status; 175 2 : ds->purse_cmd = purse_cmd; 176 : { 177 2 : struct TALER_TESTING_Command cmd = { 178 : .cls = ds, 179 : .label = label, 180 : .run = &purse_delete_run, 181 : .cleanup = &purse_delete_cleanup 182 : }; 183 : 184 2 : return cmd; 185 : } 186 : } 187 : 188 : 189 : /* end of testing_api_cmd_purse_delete.c */