testing_api_cmd_auditor_del.c (5780B)
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_auditor_del.c 21 * @brief command for testing /management/auditor/disable. 22 * @author Christian Grothoff 23 */ 24 #include "taler/platform.h" 25 #include "taler/taler_json_lib.h" 26 #include <gnunet/gnunet_curl_lib.h> 27 #include "taler/taler_testing_lib.h" 28 #include "taler/taler_signatures.h" 29 #include "taler/backoff.h" 30 31 32 /** 33 * State for a "auditor_del" CMD. 34 */ 35 struct AuditorDelState 36 { 37 38 /** 39 * Auditor enable handle while operation is running. 40 */ 41 struct TALER_EXCHANGE_PostManagementAuditorsDisableHandle *dh; 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 * Should we make the request with a bad master_sig signature? 55 */ 56 bool bad_sig; 57 }; 58 59 60 /** 61 * Callback to analyze the /management/auditors response, just used to check 62 * if the response code is acceptable. 63 * 64 * @param cls closure. 65 * @param adr response details 66 */ 67 static void 68 auditor_del_cb ( 69 void *cls, 70 const struct TALER_EXCHANGE_PostManagementAuditorsDisableResponse *adr) 71 72 { 73 struct AuditorDelState *ds = cls; 74 const struct TALER_EXCHANGE_HttpResponse *hr = &adr->hr; 75 76 ds->dh = NULL; 77 if (ds->expected_response_code != hr->http_status) 78 { 79 TALER_TESTING_unexpected_status (ds->is, 80 hr->http_status, 81 ds->expected_response_code); 82 return; 83 } 84 TALER_TESTING_interpreter_next (ds->is); 85 } 86 87 88 /** 89 * Run the command. 90 * 91 * @param cls closure. 92 * @param cmd the command to execute. 93 * @param is the interpreter state. 94 */ 95 static void 96 auditor_del_run (void *cls, 97 const struct TALER_TESTING_Command *cmd, 98 struct TALER_TESTING_Interpreter *is) 99 { 100 struct AuditorDelState *ds = cls; 101 struct TALER_MasterSignatureP master_sig; 102 struct GNUNET_TIME_Timestamp now; 103 const struct TALER_AuditorPublicKeyP *auditor_pub; 104 const struct TALER_TESTING_Command *auditor_cmd; 105 const struct TALER_TESTING_Command *exchange_cmd; 106 const char *exchange_url; 107 108 (void) cmd; 109 now = GNUNET_TIME_timestamp_get (); 110 ds->is = is; 111 auditor_cmd = TALER_TESTING_interpreter_get_command (is, 112 "auditor"); 113 if (NULL == auditor_cmd) 114 { 115 GNUNET_break (0); 116 TALER_TESTING_interpreter_fail (is); 117 return; 118 } 119 GNUNET_assert (GNUNET_OK == 120 TALER_TESTING_get_trait_auditor_pub (auditor_cmd, 121 &auditor_pub)); 122 exchange_cmd = TALER_TESTING_interpreter_get_command (is, 123 "exchange"); 124 if (NULL == exchange_cmd) 125 { 126 GNUNET_break (0); 127 TALER_TESTING_interpreter_fail (is); 128 return; 129 } 130 GNUNET_assert (GNUNET_OK == 131 TALER_TESTING_get_trait_exchange_url (exchange_cmd, 132 &exchange_url)); 133 if (ds->bad_sig) 134 { 135 memset (&master_sig, 136 42, 137 sizeof (master_sig)); 138 } 139 else 140 { 141 const struct TALER_MasterPrivateKeyP *master_priv; 142 143 GNUNET_assert (GNUNET_OK == 144 TALER_TESTING_get_trait_master_priv (exchange_cmd, 145 &master_priv)); 146 TALER_exchange_offline_auditor_del_sign (auditor_pub, 147 now, 148 master_priv, 149 &master_sig); 150 } 151 ds->dh = TALER_EXCHANGE_post_management_auditors_disable_create ( 152 TALER_TESTING_interpreter_get_context (is), 153 exchange_url, 154 auditor_pub, 155 now, 156 &master_sig); 157 if (NULL == ds->dh) 158 { 159 GNUNET_break (0); 160 TALER_TESTING_interpreter_fail (is); 161 return; 162 } 163 TALER_EXCHANGE_post_management_auditors_disable_start (ds->dh, &auditor_del_cb, ds); 164 } 165 166 167 /** 168 * Free the state of a "auditor_del" CMD, and possibly cancel a 169 * pending operation thereof. 170 * 171 * @param cls closure, must be a `struct AuditorDelState`. 172 * @param cmd the command which is being cleaned up. 173 */ 174 static void 175 auditor_del_cleanup (void *cls, 176 const struct TALER_TESTING_Command *cmd) 177 { 178 struct AuditorDelState *ds = cls; 179 180 if (NULL != ds->dh) 181 { 182 TALER_TESTING_command_incomplete (ds->is, 183 cmd->label); 184 TALER_EXCHANGE_post_management_auditors_disable_cancel (ds->dh); 185 ds->dh = NULL; 186 } 187 GNUNET_free (ds); 188 } 189 190 191 struct TALER_TESTING_Command 192 TALER_TESTING_cmd_auditor_del (const char *label, 193 unsigned int expected_http_status, 194 bool bad_sig) 195 { 196 struct AuditorDelState *ds; 197 198 ds = GNUNET_new (struct AuditorDelState); 199 ds->expected_response_code = expected_http_status; 200 ds->bad_sig = bad_sig; 201 { 202 struct TALER_TESTING_Command cmd = { 203 .cls = ds, 204 .label = label, 205 .run = &auditor_del_run, 206 .cleanup = &auditor_del_cleanup 207 }; 208 209 return cmd; 210 } 211 } 212 213 214 /* end of testing_api_cmd_auditor_del.c */