Line data Source code
1 : /*
2 : This file is part of TALER
3 : Copyright (C) 2023 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_api_cmd_delete_account.c
21 : * @brief command to test DELETE /account/$H_WIRE
22 : * @author Christian Grothoff
23 : */
24 : #include "platform.h"
25 : #include <taler/taler_exchange_service.h>
26 : #include <taler/taler_testing_lib.h>
27 : #include "taler_merchant_service.h"
28 : #include "taler_merchant_testing_lib.h"
29 :
30 :
31 : /**
32 : * State of a "DELETE /accounts/$H_WIRE" CMD.
33 : */
34 : struct DeleteAccountState
35 : {
36 :
37 : /**
38 : * Handle for a "DELETE account" request.
39 : */
40 : struct TALER_MERCHANT_AccountDeleteHandle *adh;
41 :
42 : /**
43 : * The interpreter state.
44 : */
45 : struct TALER_TESTING_Interpreter *is;
46 :
47 : /**
48 : * Base URL of the merchant serving the request.
49 : */
50 : const char *merchant_url;
51 :
52 : /**
53 : * ID of the command to get account details from.
54 : */
55 : const char *create_account_ref;
56 :
57 : /**
58 : * Expected HTTP response code.
59 : */
60 : unsigned int http_status;
61 :
62 : };
63 :
64 :
65 : /**
66 : * Callback for a DELETE /account/$H_WIRE operation.
67 : *
68 : * @param cls closure for this function
69 : * @param adr response being processed
70 : */
71 : static void
72 0 : delete_account_cb (void *cls,
73 : const struct TALER_MERCHANT_AccountDeleteResponse *adr)
74 : {
75 0 : struct DeleteAccountState *das = cls;
76 :
77 0 : das->adh = NULL;
78 0 : if (das->http_status != adr->hr.http_status)
79 : {
80 0 : GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
81 : "Unexpected response code %u (%d) to command %s\n",
82 : adr->hr.http_status,
83 : (int) adr->hr.ec,
84 : TALER_TESTING_interpreter_get_current_label (das->is));
85 0 : TALER_TESTING_interpreter_fail (das->is);
86 0 : return;
87 : }
88 0 : switch (adr->hr.http_status)
89 : {
90 0 : case MHD_HTTP_NO_CONTENT:
91 0 : break;
92 0 : case MHD_HTTP_UNAUTHORIZED:
93 0 : break;
94 0 : case MHD_HTTP_NOT_FOUND:
95 0 : break;
96 0 : case MHD_HTTP_CONFLICT:
97 0 : break;
98 0 : default:
99 0 : GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
100 : "Unhandled HTTP status %u for DELETE account.\n",
101 : adr->hr.http_status);
102 : }
103 0 : TALER_TESTING_interpreter_next (das->is);
104 : }
105 :
106 :
107 : /**
108 : * Run the "DELETE account" CMD.
109 : *
110 : * @param cls closure.
111 : * @param cmd command being run now.
112 : * @param is interpreter state.
113 : */
114 : static void
115 0 : delete_account_run (void *cls,
116 : const struct TALER_TESTING_Command *cmd,
117 : struct TALER_TESTING_Interpreter *is)
118 : {
119 0 : struct DeleteAccountState *das = cls;
120 : const struct TALER_TESTING_Command *ref;
121 : const struct TALER_MerchantWireHashP *h_wire;
122 : const char *merchant_url;
123 :
124 0 : das->is = is;
125 0 : ref = TALER_TESTING_interpreter_lookup_command (is,
126 : das->create_account_ref);
127 0 : if (NULL == ref)
128 : {
129 0 : GNUNET_break (0);
130 0 : TALER_TESTING_FAIL (is);
131 : return;
132 : }
133 0 : if (GNUNET_OK !=
134 0 : TALER_TESTING_get_trait_merchant_base_url (ref,
135 : &merchant_url))
136 : {
137 0 : GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
138 : "Command %s lacked merchant base URL\n",
139 : das->create_account_ref);
140 0 : GNUNET_break (0);
141 0 : TALER_TESTING_FAIL (is);
142 : return;
143 : }
144 0 : if (GNUNET_OK !=
145 0 : TALER_TESTING_get_trait_h_wires (ref,
146 : 0,
147 : &h_wire))
148 : {
149 0 : GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
150 : "Command %s did not return H_WIRE\n",
151 : das->create_account_ref);
152 0 : GNUNET_break (0);
153 0 : TALER_TESTING_FAIL (is);
154 : return;
155 : }
156 0 : GNUNET_assert (NULL != h_wire);
157 0 : das->adh = TALER_MERCHANT_account_delete (
158 : TALER_TESTING_interpreter_get_context (is),
159 : merchant_url,
160 : h_wire,
161 : &delete_account_cb,
162 : das);
163 0 : GNUNET_assert (NULL != das->adh);
164 : }
165 :
166 :
167 : /**
168 : * Free the state of a "DELETE account" CMD, and possibly
169 : * cancel a pending operation thereof.
170 : *
171 : * @param cls closure.
172 : * @param cmd command being run.
173 : */
174 : static void
175 0 : delete_account_cleanup (void *cls,
176 : const struct TALER_TESTING_Command *cmd)
177 : {
178 0 : struct DeleteAccountState *das = cls;
179 :
180 0 : if (NULL != das->adh)
181 : {
182 0 : GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
183 : "DELETE /accounts/$ID operation did not complete\n");
184 0 : TALER_MERCHANT_account_delete_cancel (das->adh);
185 : }
186 0 : GNUNET_free (das);
187 0 : }
188 :
189 :
190 : struct TALER_TESTING_Command
191 0 : TALER_TESTING_cmd_merchant_delete_account (const char *label,
192 : const char *create_account_ref,
193 : unsigned int http_status)
194 : {
195 : struct DeleteAccountState *das;
196 :
197 0 : das = GNUNET_new (struct DeleteAccountState);
198 0 : das->create_account_ref = create_account_ref;
199 0 : das->http_status = http_status;
200 : {
201 0 : struct TALER_TESTING_Command cmd = {
202 : .cls = das,
203 : .label = label,
204 : .run = &delete_account_run,
205 : .cleanup = &delete_account_cleanup
206 : };
207 :
208 0 : return cmd;
209 : }
210 : }
211 :
212 :
213 : /* end of testing_api_cmd_delete_account.c */
|