testing_api_cmd_revoke.c (5596B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2014-2018 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/testing_api_cmd_revoke.c 21 * @brief Implement the revoke test command. 22 * @author Marcello Stanisci 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 29 30 /** 31 * State for a "revoke" CMD. 32 */ 33 struct RevokeState 34 { 35 /** 36 * Expected HTTP status code. 37 */ 38 unsigned int expected_response_code; 39 40 /** 41 * Command that offers a denomination to revoke. 42 */ 43 const char *coin_reference; 44 45 /** 46 * The interpreter state. 47 */ 48 struct TALER_TESTING_Interpreter *is; 49 50 /** 51 * The revoke process handle. 52 */ 53 struct GNUNET_OS_Process *revoke_proc; 54 55 /** 56 * Configuration file name. 57 */ 58 const char *config_filename; 59 60 /** 61 * Encoding of the denomination (to revoke) public key hash. 62 */ 63 char *dhks; 64 65 }; 66 67 68 /** 69 * Cleanup the state. 70 * 71 * @param cls closure, must be a `struct RevokeState`. 72 * @param cmd the command which is being cleaned up. 73 */ 74 static void 75 revoke_cleanup (void *cls, 76 const struct TALER_TESTING_Command *cmd) 77 { 78 struct RevokeState *rs = cls; 79 80 if (NULL != rs->revoke_proc) 81 { 82 GNUNET_break (0 == 83 GNUNET_OS_process_kill (rs->revoke_proc, 84 SIGKILL)); 85 GNUNET_OS_process_wait (rs->revoke_proc); 86 GNUNET_OS_process_destroy (rs->revoke_proc); 87 rs->revoke_proc = NULL; 88 } 89 GNUNET_free (rs->dhks); 90 GNUNET_free (rs); 91 } 92 93 94 /** 95 * Offer internal data from a "revoke" CMD to other CMDs. 96 * 97 * @param cls closure 98 * @param[out] ret result (could be anything) 99 * @param trait name of the trait 100 * @param index index number of the object to offer. 101 * @return #GNUNET_OK on success 102 */ 103 static enum GNUNET_GenericReturnValue 104 revoke_traits (void *cls, 105 const void **ret, 106 const char *trait, 107 unsigned int index) 108 { 109 struct RevokeState *rs = cls; 110 struct TALER_TESTING_Trait traits[] = { 111 /* Needed by the handler which waits the proc' 112 * death and calls the next command */ 113 TALER_TESTING_make_trait_process (&rs->revoke_proc), 114 TALER_TESTING_trait_end () 115 }; 116 117 return TALER_TESTING_get_trait (traits, 118 ret, 119 trait, 120 index); 121 } 122 123 124 /** 125 * Run the "revoke" command. 126 * 127 * @param cls closure. 128 * @param cmd the command to execute. 129 * @param is the interpreter state. 130 */ 131 static void 132 revoke_run (void *cls, 133 const struct TALER_TESTING_Command *cmd, 134 struct TALER_TESTING_Interpreter *is) 135 { 136 struct RevokeState *rs = cls; 137 const struct TALER_TESTING_Command *coin_cmd; 138 const struct TALER_EXCHANGE_DenomPublicKey *denom_pub; 139 140 rs->is = is; 141 /* Get denom pub from trait */ 142 coin_cmd = TALER_TESTING_interpreter_lookup_command (is, 143 rs->coin_reference); 144 if (NULL == coin_cmd) 145 { 146 GNUNET_break (0); 147 TALER_TESTING_interpreter_fail (is); 148 return; 149 } 150 GNUNET_assert (GNUNET_OK == 151 TALER_TESTING_get_trait_denom_pub (coin_cmd, 152 0, 153 &denom_pub)); 154 155 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 156 "Trying to revoke denom '%s..'\n", 157 TALER_B2S (&denom_pub->h_key)); 158 159 rs->dhks = GNUNET_STRINGS_data_to_string_alloc ( 160 &denom_pub->h_key, 161 sizeof (struct GNUNET_HashCode)); 162 rs->revoke_proc = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL, 163 NULL, NULL, NULL, 164 "taler-exchange-offline", 165 "taler-exchange-offline", 166 "-c", rs->config_filename, 167 "revoke-denomination", rs->dhks, 168 "upload", 169 NULL); 170 171 if (NULL == rs->revoke_proc) 172 { 173 GNUNET_break (0); 174 TALER_TESTING_interpreter_fail (is); 175 return; 176 } 177 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 178 "Revoke is ongoing..\n"); 179 TALER_TESTING_wait_for_sigchld (is); 180 } 181 182 183 struct TALER_TESTING_Command 184 TALER_TESTING_cmd_revoke (const char *label, 185 unsigned int expected_response_code, 186 const char *coin_reference, 187 const char *config_filename) 188 { 189 190 struct RevokeState *rs; 191 192 rs = GNUNET_new (struct RevokeState); 193 rs->expected_response_code = expected_response_code; 194 rs->coin_reference = coin_reference; 195 rs->config_filename = config_filename; 196 { 197 struct TALER_TESTING_Command cmd = { 198 .cls = rs, 199 .label = label, 200 .run = &revoke_run, 201 .cleanup = &revoke_cleanup, 202 .traits = &revoke_traits 203 }; 204 205 return cmd; 206 } 207 }