Line data Source code
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 "platform.h"
25 : #include "taler_json_lib.h"
26 : #include <gnunet/gnunet_curl_lib.h>
27 : #include "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 0 : revoke_cleanup (void *cls,
76 : const struct TALER_TESTING_Command *cmd)
77 : {
78 0 : struct RevokeState *rs = cls;
79 :
80 0 : if (NULL != rs->revoke_proc)
81 : {
82 0 : GNUNET_break (0 ==
83 : GNUNET_OS_process_kill (rs->revoke_proc,
84 : SIGKILL));
85 0 : GNUNET_OS_process_wait (rs->revoke_proc);
86 0 : GNUNET_OS_process_destroy (rs->revoke_proc);
87 0 : rs->revoke_proc = NULL;
88 : }
89 0 : GNUNET_free (rs->dhks);
90 0 : GNUNET_free (rs);
91 0 : }
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 0 : revoke_traits (void *cls,
105 : const void **ret,
106 : const char *trait,
107 : unsigned int index)
108 : {
109 0 : 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 0 : TALER_TESTING_make_trait_process (&rs->revoke_proc),
114 0 : TALER_TESTING_trait_end ()
115 : };
116 :
117 0 : 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 0 : revoke_run (void *cls,
133 : const struct TALER_TESTING_Command *cmd,
134 : struct TALER_TESTING_Interpreter *is)
135 : {
136 0 : struct RevokeState *rs = cls;
137 : const struct TALER_TESTING_Command *coin_cmd;
138 : const struct TALER_EXCHANGE_DenomPublicKey *denom_pub;
139 :
140 0 : rs->is = is;
141 : /* Get denom pub from trait */
142 0 : coin_cmd = TALER_TESTING_interpreter_lookup_command (is,
143 : rs->coin_reference);
144 :
145 0 : if (NULL == coin_cmd)
146 : {
147 0 : GNUNET_break (0);
148 0 : TALER_TESTING_interpreter_fail (is);
149 0 : return;
150 : }
151 :
152 0 : GNUNET_assert (GNUNET_OK ==
153 : TALER_TESTING_get_trait_denom_pub (coin_cmd,
154 : 0,
155 : &denom_pub));
156 :
157 0 : GNUNET_log (GNUNET_ERROR_TYPE_INFO,
158 : "Trying to revoke denom '%s..'\n",
159 : TALER_B2S (&denom_pub->h_key));
160 :
161 0 : rs->dhks = GNUNET_STRINGS_data_to_string_alloc (
162 0 : &denom_pub->h_key,
163 : sizeof (struct GNUNET_HashCode));
164 0 : rs->revoke_proc = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
165 : NULL, NULL, NULL,
166 : "taler-exchange-offline",
167 : "taler-exchange-offline",
168 : "-c", rs->config_filename,
169 : "revoke-denomination", rs->dhks,
170 : "upload",
171 : NULL);
172 :
173 0 : if (NULL == rs->revoke_proc)
174 : {
175 0 : GNUNET_break (0);
176 0 : TALER_TESTING_interpreter_fail (is);
177 0 : return;
178 : }
179 0 : GNUNET_log (GNUNET_ERROR_TYPE_INFO,
180 : "Revoke is ongoing..\n");
181 0 : TALER_TESTING_wait_for_sigchld (is);
182 : }
183 :
184 :
185 : struct TALER_TESTING_Command
186 0 : TALER_TESTING_cmd_revoke (const char *label,
187 : unsigned int expected_response_code,
188 : const char *coin_reference,
189 : const char *config_filename)
190 : {
191 :
192 : struct RevokeState *rs;
193 :
194 0 : rs = GNUNET_new (struct RevokeState);
195 0 : rs->expected_response_code = expected_response_code;
196 0 : rs->coin_reference = coin_reference;
197 0 : rs->config_filename = config_filename;
198 : {
199 0 : struct TALER_TESTING_Command cmd = {
200 : .cls = rs,
201 : .label = label,
202 : .run = &revoke_run,
203 : .cleanup = &revoke_cleanup,
204 : .traits = &revoke_traits
205 : };
206 :
207 0 : return cmd;
208 : }
209 : }
|