Line data Source code
1 : /* 2 : This file is part of TALER 3 : Copyright (C) 2022 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_template.c 21 : * @brief command to test DELETE /templates/$ID 22 : * @author Priscilla HUANG 23 : */ 24 : #include "platform.h" 25 : #include <taler/taler_exchange_service.h> 26 : #include <taler/taler_testing_lib.h> 27 : #include "taler_merchant_service.h" 28 : #include "taler_merchant_testing_lib.h" 29 : 30 : 31 : /** 32 : * State of a "DELETE /templates/$ID" CMD. 33 : */ 34 : struct DeleteTemplateState 35 : { 36 : 37 : /** 38 : * Handle for a "DELETE template" request. 39 : */ 40 : struct TALER_MERCHANT_TemplateDeleteHandle *tdh; 41 : 42 : /** 43 : * The interpreter state. 44 : */ 45 : struct TALER_TESTING_Interpreter *is; 46 : 47 : /** 48 : * Base URL of the merchant serving the request. 49 : */ 50 : const char *merchant_url; 51 : 52 : /** 53 : * ID of the template to run DELETE for. 54 : */ 55 : const char *template_id; 56 : 57 : /** 58 : * Expected HTTP response code. 59 : */ 60 : unsigned int http_status; 61 : 62 : }; 63 : 64 : 65 : /** 66 : * Callback for a /delete/templates/$ID operation. 67 : * 68 : * @param cls closure for this function 69 : * @param hr response being processed 70 : */ 71 : static void 72 4 : delete_template_cb (void *cls, 73 : const struct TALER_MERCHANT_HttpResponse *hr) 74 : { 75 4 : struct DeleteTemplateState *dis = cls; 76 : 77 4 : dis->tdh = NULL; 78 4 : if (dis->http_status != hr->http_status) 79 : { 80 0 : TALER_TESTING_unexpected_status_with_body (dis->is, 81 : hr->http_status, 82 : dis->http_status, 83 : hr->reply); 84 0 : return; 85 : } 86 4 : switch (hr->http_status) 87 : { 88 2 : case MHD_HTTP_NO_CONTENT: 89 2 : break; 90 0 : case MHD_HTTP_UNAUTHORIZED: 91 0 : break; 92 2 : case MHD_HTTP_NOT_FOUND: 93 2 : break; 94 0 : case MHD_HTTP_CONFLICT: 95 0 : break; 96 0 : default: 97 0 : GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 98 : "Unhandled HTTP status %u for DELETE template.\n", 99 : hr->http_status); 100 : } 101 4 : TALER_TESTING_interpreter_next (dis->is); 102 : } 103 : 104 : 105 : /** 106 : * Run the "DELETE template" CMD. 107 : * 108 : * 109 : * @param cls closure. 110 : * @param cmd command being run now. 111 : * @param is interpreter state. 112 : */ 113 : static void 114 4 : delete_template_run (void *cls, 115 : const struct TALER_TESTING_Command *cmd, 116 : struct TALER_TESTING_Interpreter *is) 117 : { 118 4 : struct DeleteTemplateState *dis = cls; 119 : 120 4 : dis->is = is; 121 4 : dis->tdh = TALER_MERCHANT_template_delete ( 122 : TALER_TESTING_interpreter_get_context (is), 123 : dis->merchant_url, 124 : dis->template_id, 125 : &delete_template_cb, 126 : dis); 127 4 : GNUNET_assert (NULL != dis->tdh); 128 4 : } 129 : 130 : 131 : /** 132 : * Free the state of a "DELETE template" CMD, and possibly 133 : * cancel a pending operation thereof. 134 : * 135 : * @param cls closure. 136 : * @param cmd command being run. 137 : */ 138 : static void 139 4 : delete_template_cleanup (void *cls, 140 : const struct TALER_TESTING_Command *cmd) 141 : { 142 4 : struct DeleteTemplateState *dis = cls; 143 : 144 4 : if (NULL != dis->tdh) 145 : { 146 0 : GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 147 : "DELETE /templates/$ID operation did not complete\n"); 148 0 : TALER_MERCHANT_template_delete_cancel (dis->tdh); 149 : } 150 4 : GNUNET_free (dis); 151 4 : } 152 : 153 : 154 : struct TALER_TESTING_Command 155 4 : TALER_TESTING_cmd_merchant_delete_template (const char *label, 156 : const char *merchant_url, 157 : const char *template_id, 158 : unsigned int http_status) 159 : { 160 : struct DeleteTemplateState *dis; 161 : 162 4 : dis = GNUNET_new (struct DeleteTemplateState); 163 4 : dis->merchant_url = merchant_url; 164 4 : dis->template_id = template_id; 165 4 : dis->http_status = http_status; 166 : { 167 4 : struct TALER_TESTING_Command cmd = { 168 : .cls = dis, 169 : .label = label, 170 : .run = &delete_template_run, 171 : .cleanup = &delete_template_cleanup 172 : }; 173 : 174 4 : return cmd; 175 : } 176 : } 177 : 178 : 179 : /* end of testing_api_cmd_delete_template.c */