testing_api_cmd_delete_transfer.c (5432B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2021 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 * @file testing_api_cmd_delete_transfer.c 21 * @brief command to test DELETE /transfers/$TRANSFER_ID 22 * @author Jonathan Buchanan 23 */ 24 #include "taler/platform.h" 25 #include <taler/taler_exchange_service.h> 26 #include <taler/taler_testing_lib.h> 27 #include "taler/taler_merchant_service.h" 28 #include "taler/taler_merchant_testing_lib.h" 29 #include <taler/taler-merchant/delete-private-transfers-TID.h> 30 31 32 /** 33 * State of a "DELETE /transfer/$TRANSFER_ID" CMD. 34 */ 35 struct DeleteTransferState 36 { 37 38 /** 39 * Handle for a "DELETE transfer" request. 40 */ 41 struct TALER_MERCHANT_DeletePrivateTransferHandle *tdh; 42 43 /** 44 * The interpreter state. 45 */ 46 struct TALER_TESTING_Interpreter *is; 47 48 /** 49 * Base URL of the merchant serving the request. 50 */ 51 const char *merchant_url; 52 53 /** 54 * Ref to cmd with ID of the transfer to run DELETE for. 55 */ 56 const char *transfer_ref; 57 58 /** 59 * Expected HTTP response code. 60 */ 61 unsigned int http_status; 62 63 }; 64 65 66 /** 67 * Callback for a DELETE /transfers/$ID operation. 68 * 69 * @param cls closure for this function 70 * @param hr response being processed 71 */ 72 static void 73 delete_transfer_cb (void *cls, 74 const struct TALER_MERCHANT_DeletePrivateTransferResponse * 75 dtr) 76 { 77 struct DeleteTransferState *dts = cls; 78 79 dts->tdh = NULL; 80 if (dts->http_status != dtr->hr.http_status) 81 { 82 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 83 "Unexpected response code %u (%d) to command %s\n", 84 dtr->hr.http_status, 85 (int) dtr->hr.ec, 86 TALER_TESTING_interpreter_get_current_label (dts->is)); 87 TALER_TESTING_interpreter_fail (dts->is); 88 return; 89 } 90 switch (dtr->hr.http_status) 91 { 92 case MHD_HTTP_NO_CONTENT: 93 break; 94 case MHD_HTTP_UNAUTHORIZED: 95 break; 96 case MHD_HTTP_NOT_FOUND: 97 break; 98 case MHD_HTTP_CONFLICT: 99 break; 100 default: 101 GNUNET_break (0); 102 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 103 "Unhandled HTTP status %u for DELETE transfer.\n", 104 dtr->hr.http_status); 105 } 106 TALER_TESTING_interpreter_next (dts->is); 107 } 108 109 110 /** 111 * Run the "DELETE transfer" CMD. 112 * 113 * 114 * @param cls closure. 115 * @param cmd command being run now. 116 * @param is interpreter state. 117 */ 118 static void 119 delete_transfer_run (void *cls, 120 const struct TALER_TESTING_Command *cmd, 121 struct TALER_TESTING_Interpreter *is) 122 { 123 struct DeleteTransferState *dts = cls; 124 const struct TALER_TESTING_Command *ref; 125 const uint64_t *tid; 126 127 dts->is = is; 128 ref = TALER_TESTING_interpreter_lookup_command (is, 129 dts->transfer_ref); 130 if (NULL == ref) 131 { 132 GNUNET_break (0); 133 TALER_TESTING_interpreter_fail (dts->is); 134 return; 135 } 136 if (GNUNET_OK != 137 TALER_TESTING_get_trait_bank_row (ref, 138 &tid)) 139 { 140 GNUNET_break (0); 141 TALER_TESTING_interpreter_fail (dts->is); 142 return; 143 } 144 if (0 == tid) 145 { 146 GNUNET_break (0); 147 TALER_TESTING_interpreter_fail (dts->is); 148 return; 149 } 150 dts->tdh = TALER_MERCHANT_delete_private_transfer_create ( 151 TALER_TESTING_interpreter_get_context (is), 152 dts->merchant_url, 153 *tid); 154 { 155 enum TALER_ErrorCode ec; 156 157 ec = TALER_MERCHANT_delete_private_transfer_start (dts->tdh, 158 &delete_transfer_cb, 159 dts); 160 GNUNET_assert (TALER_EC_NONE == ec); 161 } 162 } 163 164 165 /** 166 * Free the state of a "DELETE transfer" CMD, and possibly 167 * cancel a pending operation thereof. 168 * 169 * @param cls closure. 170 * @param cmd command being run. 171 */ 172 static void 173 delete_transfer_cleanup (void *cls, 174 const struct TALER_TESTING_Command *cmd) 175 { 176 struct DeleteTransferState *dts = cls; 177 178 if (NULL != dts->tdh) 179 { 180 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 181 "DELETE /transfers/$TRANSFER_ID operation did not complete\n"); 182 TALER_MERCHANT_delete_private_transfer_cancel (dts->tdh); 183 } 184 GNUNET_free (dts); 185 } 186 187 188 struct TALER_TESTING_Command 189 TALER_TESTING_cmd_merchant_delete_transfer (const char *label, 190 const char *merchant_url, 191 const char *transfer_ref, 192 unsigned int http_status) 193 { 194 struct DeleteTransferState *dts; 195 196 dts = GNUNET_new (struct DeleteTransferState); 197 dts->merchant_url = merchant_url; 198 dts->transfer_ref = transfer_ref; 199 dts->http_status = http_status; 200 { 201 struct TALER_TESTING_Command cmd = { 202 .cls = dts, 203 .label = label, 204 .run = &delete_transfer_run, 205 .cleanup = &delete_transfer_cleanup 206 }; 207 208 return cmd; 209 } 210 }