aboutsummaryrefslogtreecommitdiff
path: root/src/bank-lib/test_bank_api_new2.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bank-lib/test_bank_api_new2.c')
-rw-r--r--src/bank-lib/test_bank_api_new2.c281
1 files changed, 281 insertions, 0 deletions
diff --git a/src/bank-lib/test_bank_api_new2.c b/src/bank-lib/test_bank_api_new2.c
new file mode 100644
index 000000000..a2f776239
--- /dev/null
+++ b/src/bank-lib/test_bank_api_new2.c
@@ -0,0 +1,281 @@
1/*
2 This file is part of TALER
3 Copyright (C) 2016, 2017 GNUnet e.V.
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,
8 or (at your option) any later version.
9
10 TALER is distributed in the hope that it will be useful,
11 but 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,
17 see <http://www.gnu.org/licenses/>
18*/
19
20/**
21 * @file bank/test_bank_api_with_fakebank.c
22 * @brief testcase to test bank's HTTP API
23 * interface against the fakebank
24 * @author Marcello Stanisci
25 * @author Christian Grothoff
26 */
27
28#include "platform.h"
29#include "taler_util.h"
30#include "taler_signatures.h"
31#include "taler_bank_service.h"
32#include "taler_exchange_service.h"
33#include <gnunet/gnunet_util_lib.h>
34#include <gnunet/gnunet_curl_lib.h>
35#include <microhttpd.h>
36#include "test_bank_interpreter.h"
37#include "taler_testing_lib.h"
38#include "taler_testing_bank_lib.h"
39
40
41#define CONFIG_FILE "bank.conf"
42
43/**
44 * Fakebank URL.
45 */
46static char *bank_url;
47
48/**
49 * Handle to the Py-bank daemon.
50 */
51static struct GNUNET_OS_Process *bankd;
52
53/**
54 * Flag indicating whether the test is running against the
55 * Fakebank. Set up at runtime.
56 */
57static int WITH_FAKEBANK;
58
59/**
60 * Main function that will tell the interpreter what commands to
61 * run.
62 *
63 * @param cls closure
64 */
65static void
66run (void *cls,
67 struct TALER_TESTING_Interpreter *is)
68{
69 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
70 "Bank serves at `%s'\n",
71 bank_url);
72 extern struct TALER_BANK_AuthenticationData AUTHS[];
73
74 struct TALER_TESTING_Command commands[] = {
75
76 TALER_TESTING_cmd_bank_history ("history-0",
77 bank_url,
78 BANK_ACCOUNT_NUMBER,
79 TALER_BANK_DIRECTION_BOTH,
80 GNUNET_YES,
81 NULL,
82 1),
83
84
85 /* WARNING: old API has expected http response code among
86 * the parameters, although it was always set as '200 OK' */
87 TALER_TESTING_cmd_fakebank_transfer_with_subject
88 ("debit-1",
89 "KUDOS:5.01",
90 bank_url,
91 EXCHANGE_ACCOUNT_NUMBER,
92 BANK_ACCOUNT_NUMBER,
93 AUTHS[EXCHANGE_ACCOUNT_NUMBER - 1].details.basic.username,
94 AUTHS[EXCHANGE_ACCOUNT_NUMBER - 1].details.basic.password,
95 "subject 1",
96 "http://exchange.com/"),
97
98 TALER_TESTING_cmd_bank_history ("history-1c",
99 bank_url,
100 BANK_ACCOUNT_NUMBER,
101 TALER_BANK_DIRECTION_CREDIT,
102 GNUNET_YES,
103 NULL,
104 5),
105
106 TALER_TESTING_cmd_bank_history ("history-1d",
107 bank_url,
108 BANK_ACCOUNT_NUMBER,
109 TALER_BANK_DIRECTION_DEBIT,
110 GNUNET_YES,
111 NULL,
112 5),
113
114 TALER_TESTING_cmd_fakebank_transfer_with_subject
115 ("debit-2",
116 "KUDOS:3.21",
117 bank_url,
118 EXCHANGE_ACCOUNT_NUMBER, // debit account.
119 USER_ACCOUNT_NUMBER,
120 AUTHS[EXCHANGE_ACCOUNT_NUMBER - 1].details.basic.username,
121 AUTHS[EXCHANGE_ACCOUNT_NUMBER - 1].details.basic.password,
122 "subject 2",
123 "http://exchange.org/"),
124
125 TALER_TESTING_cmd_fakebank_transfer_with_subject
126 ("credit-2",
127 "KUDOS:3.22",
128 bank_url,
129 USER_ACCOUNT_NUMBER, // debit account.
130 EXCHANGE_ACCOUNT_NUMBER,
131 AUTHS[USER_ACCOUNT_NUMBER - 1].details.basic.username,
132 AUTHS[USER_ACCOUNT_NUMBER - 1].details.basic.password,
133 "credit 2",
134 "http://exchange.org/"),
135
136 TALER_TESTING_cmd_bank_history ("history-2b",
137 bank_url,
138 EXCHANGE_ACCOUNT_NUMBER,
139 TALER_BANK_DIRECTION_BOTH,
140 GNUNET_YES,
141 NULL,
142 5),
143
144 TALER_TESTING_cmd_bank_history ("history-2bi",
145 bank_url,
146 EXCHANGE_ACCOUNT_NUMBER,
147 TALER_BANK_DIRECTION_BOTH,
148 GNUNET_YES,
149 "debit-1",
150 5),
151
152 TALER_TESTING_cmd_check_bank_transfer_with_ref ("expect-2d",
153 "credit-2"),
154
155 TALER_TESTING_cmd_check_bank_transfer_with_ref ("expect-2c",
156 "debit-2"),
157
158 TALER_TESTING_cmd_check_bank_transfer_with_ref ("expect-1",
159 "debit-1"),
160
161 TALER_TESTING_cmd_check_bank_empty ("expect-empty"),
162
163 TALER_TESTING_cmd_fakebank_transfer_with_subject
164 ("credit-for-reject-1",
165 "KUDOS:5.01",
166 bank_url,
167 BANK_ACCOUNT_NUMBER,
168 EXCHANGE_ACCOUNT_NUMBER,
169 AUTHS[BANK_ACCOUNT_NUMBER - 1].details.basic.username,
170 AUTHS[BANK_ACCOUNT_NUMBER - 1].details.basic.password,
171 "subject 3",
172 "http://exchange.net/"),
173
174 TALER_TESTING_cmd_bank_reject ("reject-1",
175 bank_url,
176 "credit-for-reject-1"),
177
178 TALER_TESTING_cmd_bank_history ("history-r1",
179 bank_url,
180 BANK_ACCOUNT_NUMBER,
181 TALER_BANK_DIRECTION_BOTH,
182 GNUNET_YES,
183 NULL,
184 5),
185
186 TALER_TESTING_cmd_bank_history ("history-r1c",
187 bank_url,
188 BANK_ACCOUNT_NUMBER,
189 TALER_BANK_DIRECTION_BOTH
190 | TALER_BANK_DIRECTION_CANCEL,
191 GNUNET_YES,
192 NULL,
193 5),
194
195 TALER_TESTING_cmd_check_bank_transfer_with_ref
196 ("expect-credit-reject-1",
197 "credit-for-reject-1"),
198
199 TALER_TESTING_cmd_check_bank_empty ("expect-empty-2"),
200
201 /**
202 * End the suite. Fixme: better to have a label for this
203 * too, as it shows a "(null)" token on logs.
204 */
205 TALER_TESTING_cmd_end ()
206 };
207
208 if (GNUNET_YES == WITH_FAKEBANK)
209 TALER_TESTING_run_with_fakebank (is,
210 commands,
211 bank_url);
212 else
213 TALER_TESTING_run (is,
214 commands);
215}
216
217int
218main (int argc,
219 char *const *argv)
220{
221 int rv;
222
223 /* These environment variables get in the way... */
224 unsetenv ("XDG_DATA_HOME");
225 unsetenv ("XDG_CONFIG_HOME");
226 GNUNET_log_setup ("test-bank-api-with-fakebank-new",
227 "DEBUG",
228 NULL);
229
230 WITH_FAKEBANK = TALER_TESTING_has_in_name (argv[0],
231 "_with_fakebank");
232
233 if (GNUNET_YES == WITH_FAKEBANK)
234 {
235 TALER_LOG_DEBUG ("Running against the Fakebank.\n");
236 if (NULL == (bank_url = TALER_TESTING_prepare_fakebank
237 (CONFIG_FILE,
238 "account-1")))
239 {
240 GNUNET_break (0);
241 return 77;
242 }
243 }
244 else
245 {
246 if (NULL == (bank_url = TALER_TESTING_prepare_bank
247 (CONFIG_FILE)))
248 {
249 GNUNET_break (0);
250 return 77;
251 }
252
253 if (NULL == (bankd = TALER_TESTING_run_bank
254 (CONFIG_FILE,
255 bank_url)))
256 {
257 GNUNET_break (0);
258 return 77;
259 }
260 }
261
262 rv = (GNUNET_OK == TALER_TESTING_setup (&run,
263 NULL,
264 CONFIG_FILE,
265 NULL,
266 GNUNET_NO)) ? 0 : 1;
267 if (GNUNET_NO == WITH_FAKEBANK)
268 {
269
270 GNUNET_OS_process_kill (bankd,
271 SIGKILL);
272 GNUNET_OS_process_wait (bankd);
273 GNUNET_OS_process_destroy (bankd);
274 GNUNET_free (bank_url);
275 }
276
277 return rv;
278}
279
280
281/* end of test_bank_api_with_fakebank_new.c */