Line data Source code
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_add_denom_sig.c
21 : * @brief command for testing POST to /auditor/$AUDITOR_PUB/$H_DENOM_PUB
22 : * @author Christian Grothoff
23 : */
24 : #include "taler/taler_json_lib.h"
25 : #include <gnunet/gnunet_curl_lib.h>
26 : struct AuditorAddDenomSigState;
27 : #define TALER_EXCHANGE_POST_AUDITORS_RESULT_CLOSURE \
28 : struct AuditorAddDenomSigState
29 : #include "taler/exchange/post-auditors-AUDITOR_PUB-H_DENOM_PUB.h"
30 : #include "taler/taler_testing_lib.h"
31 :
32 :
33 : /**
34 : * State for a "auditor_add" CMD.
35 : */
36 : struct AuditorAddDenomSigState
37 : {
38 :
39 : /**
40 : * Auditor enable handle while operation is running.
41 : */
42 : struct TALER_EXCHANGE_PostAuditorsHandle *dh;
43 :
44 : /**
45 : * Our interpreter.
46 : */
47 : struct TALER_TESTING_Interpreter *is;
48 :
49 : /**
50 : * Reference to command identifying denomination to add.
51 : */
52 : const char *denom_ref;
53 :
54 : /**
55 : * Expected HTTP response code.
56 : */
57 : unsigned int expected_response_code;
58 :
59 : /**
60 : * Should we make the request with a bad master_sig signature?
61 : */
62 : bool bad_sig;
63 : };
64 :
65 :
66 : /**
67 : * Callback to analyze the /management/auditor response, just used to check
68 : * if the response code is acceptable.
69 : *
70 : * @param ds closure.
71 : * @param adr response details
72 : */
73 : static void
74 0 : denom_sig_add_cb (
75 : struct AuditorAddDenomSigState *ds,
76 : const struct TALER_EXCHANGE_PostAuditorsResponse *adr)
77 : {
78 0 : const struct TALER_EXCHANGE_HttpResponse *hr = &adr->hr;
79 :
80 0 : ds->dh = NULL;
81 0 : if (ds->expected_response_code != hr->http_status)
82 : {
83 0 : TALER_TESTING_unexpected_status (ds->is,
84 : hr->http_status,
85 : ds->expected_response_code);
86 0 : return;
87 : }
88 0 : TALER_TESTING_interpreter_next (ds->is);
89 : }
90 :
91 :
92 : /**
93 : * Run the command.
94 : *
95 : * @param cls closure.
96 : * @param cmd the command to execute.
97 : * @param is the interpreter state.
98 : */
99 : static void
100 0 : auditor_add_run (void *cls,
101 : const struct TALER_TESTING_Command *cmd,
102 : struct TALER_TESTING_Interpreter *is)
103 : {
104 0 : struct AuditorAddDenomSigState *ds = cls;
105 : struct TALER_AuditorSignatureP auditor_sig;
106 : const struct TALER_EXCHANGE_DenomPublicKey *dk;
107 : const struct TALER_AuditorPublicKeyP *auditor_pub;
108 : const struct TALER_TESTING_Command *auditor_cmd;
109 : const struct TALER_TESTING_Command *exchange_cmd;
110 : const char *exchange_url;
111 : const char *auditor_url;
112 :
113 : (void) cmd;
114 : /* Get denom pub from trait */
115 : {
116 : const struct TALER_TESTING_Command *denom_cmd;
117 :
118 0 : denom_cmd = TALER_TESTING_interpreter_lookup_command (is,
119 : ds->denom_ref);
120 0 : if (NULL == denom_cmd)
121 : {
122 0 : GNUNET_break (0);
123 0 : TALER_TESTING_interpreter_fail (is);
124 0 : return;
125 : }
126 0 : GNUNET_assert (GNUNET_OK ==
127 : TALER_TESTING_get_trait_denom_pub (denom_cmd,
128 : 0,
129 : &dk));
130 : }
131 0 : ds->is = is;
132 0 : auditor_cmd = TALER_TESTING_interpreter_get_command (is,
133 : "auditor");
134 0 : if (NULL == auditor_cmd)
135 : {
136 0 : GNUNET_break (0);
137 0 : TALER_TESTING_interpreter_fail (is);
138 0 : return;
139 : }
140 0 : GNUNET_assert (GNUNET_OK ==
141 : TALER_TESTING_get_trait_auditor_pub (auditor_cmd,
142 : &auditor_pub));
143 0 : GNUNET_assert (GNUNET_OK ==
144 : TALER_TESTING_get_trait_auditor_url (auditor_cmd,
145 : &auditor_url));
146 0 : exchange_cmd = TALER_TESTING_interpreter_get_command (is,
147 : "exchange");
148 0 : if (NULL == exchange_cmd)
149 : {
150 0 : GNUNET_break (0);
151 0 : TALER_TESTING_interpreter_fail (is);
152 0 : return;
153 : }
154 0 : GNUNET_assert (GNUNET_OK ==
155 : TALER_TESTING_get_trait_exchange_url (exchange_cmd,
156 : &exchange_url));
157 0 : if (ds->bad_sig)
158 : {
159 0 : memset (&auditor_sig,
160 : 42,
161 : sizeof (auditor_sig));
162 : }
163 : else
164 : {
165 : const struct TALER_MasterPublicKeyP *master_pub;
166 : const struct TALER_AuditorPrivateKeyP *auditor_priv;
167 :
168 0 : GNUNET_assert (GNUNET_OK ==
169 : TALER_TESTING_get_trait_master_pub (exchange_cmd,
170 : &master_pub));
171 0 : GNUNET_assert (GNUNET_OK ==
172 : TALER_TESTING_get_trait_auditor_priv (auditor_cmd,
173 : &auditor_priv));
174 0 : TALER_auditor_denom_validity_sign (
175 : auditor_url,
176 0 : &dk->h_key,
177 : master_pub,
178 0 : dk->valid_from,
179 0 : dk->withdraw_valid_until,
180 0 : dk->expire_deposit,
181 0 : dk->expire_legal,
182 0 : &dk->value,
183 0 : &dk->fees,
184 : auditor_priv,
185 : &auditor_sig);
186 : }
187 0 : ds->dh = TALER_EXCHANGE_post_auditors_create (
188 : TALER_TESTING_interpreter_get_context (is),
189 : exchange_url,
190 0 : &dk->h_key,
191 : auditor_pub,
192 : &auditor_sig);
193 0 : if (NULL == ds->dh)
194 : {
195 0 : GNUNET_break (0);
196 0 : TALER_TESTING_interpreter_fail (is);
197 0 : return;
198 : }
199 0 : GNUNET_assert (TALER_EC_NONE ==
200 : TALER_EXCHANGE_post_auditors_start (ds->dh,
201 : &denom_sig_add_cb,
202 : ds));
203 : }
204 :
205 :
206 : /**
207 : * Free the state of a "auditor_add" CMD, and possibly cancel a
208 : * pending operation thereof.
209 : *
210 : * @param cls closure, must be a `struct AuditorAddDenomSigState`.
211 : * @param cmd the command which is being cleaned up.
212 : */
213 : static void
214 0 : auditor_add_cleanup (void *cls,
215 : const struct TALER_TESTING_Command *cmd)
216 : {
217 0 : struct AuditorAddDenomSigState *ds = cls;
218 :
219 0 : if (NULL != ds->dh)
220 : {
221 0 : TALER_TESTING_command_incomplete (ds->is,
222 : cmd->label);
223 0 : TALER_EXCHANGE_post_auditors_cancel (ds->dh);
224 0 : ds->dh = NULL;
225 : }
226 0 : GNUNET_free (ds);
227 0 : }
228 :
229 :
230 : struct TALER_TESTING_Command
231 0 : TALER_TESTING_cmd_auditor_add_denom_sig (const char *label,
232 : unsigned int expected_http_status,
233 : const char *denom_ref,
234 : bool bad_sig)
235 : {
236 : struct AuditorAddDenomSigState *ds;
237 :
238 0 : ds = GNUNET_new (struct AuditorAddDenomSigState);
239 0 : ds->expected_response_code = expected_http_status;
240 0 : ds->bad_sig = bad_sig;
241 0 : ds->denom_ref = denom_ref;
242 : {
243 0 : struct TALER_TESTING_Command cmd = {
244 : .cls = ds,
245 : .label = label,
246 : .run = &auditor_add_run,
247 : .cleanup = &auditor_add_cleanup
248 : };
249 :
250 0 : return cmd;
251 : }
252 : }
253 :
254 :
255 : /* end of testing_api_cmd_auditor_add_denom_sig.c */
|