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