diff options
Diffstat (limited to 'src/bank-lib/test_bank_api_new.c')
-rw-r--r-- | src/bank-lib/test_bank_api_new.c | 283 |
1 files changed, 163 insertions, 120 deletions
diff --git a/src/bank-lib/test_bank_api_new.c b/src/bank-lib/test_bank_api_new.c index 17acac9bc..5c7920b76 100644 --- a/src/bank-lib/test_bank_api_new.c +++ b/src/bank-lib/test_bank_api_new.c | |||
@@ -3,14 +3,14 @@ | |||
3 | Copyright (C) 2016, 2017 GNUnet e.V. | 3 | Copyright (C) 2016, 2017 GNUnet e.V. |
4 | 4 | ||
5 | TALER is free software; you can redistribute it and/or modify | 5 | TALER is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | published by the Free Software Foundation; either version 3, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | TALER is distributed in the hope that it will be useful, but | 10 | TALER is distributed in the hope that it will be useful, |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public | 15 | You should have received a copy of the GNU General Public |
16 | License along with TALER; see the file COPYING. If not, | 16 | License along with TALER; see the file COPYING. If not, |
@@ -18,61 +18,43 @@ | |||
18 | */ | 18 | */ |
19 | 19 | ||
20 | /** | 20 | /** |
21 | * @file bank/test_bank_api_new.c | 21 | * @file bank/test_bank_api_with_fakebank.c |
22 | * @brief testcase to test bank's HTTP API | 22 | * @brief testcase to test bank's HTTP API |
23 | * interface against the "real" bank | 23 | * interface against the fakebank |
24 | * @author Christian Grothoff | ||
25 | * @author Marcello Stanisci | 24 | * @author Marcello Stanisci |
25 | * @author Christian Grothoff | ||
26 | */ | 26 | */ |
27 | 27 | ||
28 | #include "platform.h" | 28 | #include "platform.h" |
29 | #include "taler_util.h" | 29 | #include "taler_util.h" |
30 | #include "taler_signatures.h" | 30 | #include "taler_signatures.h" |
31 | #include "taler_bank_service.h" | 31 | #include "taler_bank_service.h" |
32 | #include "taler_exchange_service.h" | ||
32 | #include <gnunet/gnunet_util_lib.h> | 33 | #include <gnunet/gnunet_util_lib.h> |
33 | #include <gnunet/gnunet_curl_lib.h> | 34 | #include <gnunet/gnunet_curl_lib.h> |
34 | #include <microhttpd.h> | 35 | #include <microhttpd.h> |
35 | #include "taler_exchange_service.h" | ||
36 | #include "test_bank_interpreter.h" | 36 | #include "test_bank_interpreter.h" |
37 | #include "taler_testing_lib.h" | 37 | #include "taler_testing_lib.h" |
38 | #include "taler_testing_bank_lib.h" | 38 | #include "taler_testing_bank_lib.h" |
39 | 39 | ||
40 | |||
40 | #define CONFIG_FILE "bank.conf" | 41 | #define CONFIG_FILE "bank.conf" |
41 | 42 | ||
42 | /** | 43 | /** |
43 | * Add seconds. | 44 | * Fakebank URL. |
44 | * | ||
45 | * @param base absolute time to add seconds to. | ||
46 | * @param relative number of seconds to add. | ||
47 | * @return a new absolute time, modified according to @e relative. | ||
48 | */ | ||
49 | #define ADDSECS(base, secs) \ | ||
50 | GNUNET_TIME_absolute_add \ | ||
51 | (base, \ | ||
52 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \ | ||
53 | secs)) | ||
54 | /** | ||
55 | * Subtract seconds. | ||
56 | * | ||
57 | * @param base absolute time to subtract seconds to. | ||
58 | * @param secs relative number of _seconds_ to subtract. | ||
59 | * @return a new absolute time, modified according to @e relative. | ||
60 | */ | 45 | */ |
61 | #define SUBSECS(base, secs) \ | 46 | static char *bank_url; |
62 | GNUNET_TIME_absolute_subtract \ | 47 | |
63 | (base, \ | ||
64 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \ | ||
65 | secs)) | ||
66 | /** | 48 | /** |
67 | * Bank process. | 49 | * Handle to the Py-bank daemon. |
68 | */ | 50 | */ |
69 | struct GNUNET_OS_Process *bankd; | 51 | static struct GNUNET_OS_Process *bankd; |
70 | 52 | ||
71 | /** | 53 | /** |
72 | * Bank URL. | 54 | * Flag indicating whether the test is running against the |
55 | * Fakebank. Set up at runtime. | ||
73 | */ | 56 | */ |
74 | char *bank_url; | 57 | static int WITH_FAKEBANK; |
75 | |||
76 | 58 | ||
77 | /** | 59 | /** |
78 | * Main function that will tell the interpreter what commands to | 60 | * Main function that will tell the interpreter what commands to |
@@ -84,91 +66,120 @@ static void | |||
84 | run (void *cls, | 66 | run (void *cls, |
85 | struct TALER_TESTING_Interpreter *is) | 67 | struct TALER_TESTING_Interpreter *is) |
86 | { | 68 | { |
69 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
70 | "Bank serves at `%s'\n", | ||
71 | bank_url); | ||
87 | extern struct TALER_BANK_AuthenticationData AUTHS[]; | 72 | extern struct TALER_BANK_AuthenticationData AUTHS[]; |
88 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); | 73 | |
89 | struct TALER_TESTING_Command commands[] = { | 74 | struct TALER_TESTING_Command commands[] = { |
75 | |||
90 | TALER_TESTING_cmd_bank_history ("history-0", | 76 | TALER_TESTING_cmd_bank_history ("history-0", |
91 | bank_url, | 77 | bank_url, |
92 | EXCHANGE_ACCOUNT_NUMBER, | 78 | BANK_ACCOUNT_NUMBER, |
93 | TALER_BANK_DIRECTION_BOTH, | 79 | TALER_BANK_DIRECTION_BOTH, |
94 | GNUNET_NO, | 80 | GNUNET_YES, |
95 | NULL, /* start */ | 81 | NULL, |
96 | 5), | 82 | 1), |
97 | TALER_TESTING_cmd_bank_history_range_with_dates | 83 | |
98 | ("history-0-range", | 84 | /* WARNING: old API has expected http response code among |
99 | bank_url, | 85 | * the parameters, although it was always set as '200 OK' */ |
100 | EXCHANGE_ACCOUNT_NUMBER, | ||
101 | TALER_BANK_DIRECTION_BOTH, | ||
102 | GNUNET_NO, | ||
103 | SUBSECS (now, | ||
104 | 5), | ||
105 | ADDSECS (now, | ||
106 | 5)), | ||
107 | TALER_TESTING_cmd_fakebank_transfer_with_subject | ||
108 | ("deposit-1", | ||
109 | "KUDOS:5.01", | ||
110 | bank_url, | ||
111 | BANK_ACCOUNT_NUMBER, | ||
112 | EXCHANGE_ACCOUNT_NUMBER, | ||
113 | AUTHS[BANK_ACCOUNT_NUMBER - 1].details.basic.username, | ||
114 | AUTHS[BANK_ACCOUNT_NUMBER - 1].details.basic.password, | ||
115 | "subject 1", | ||
116 | "http://exchange.com/"), | ||
117 | /* bank gives to exchange */ | ||
118 | TALER_TESTING_cmd_fakebank_transfer_with_subject | 86 | TALER_TESTING_cmd_fakebank_transfer_with_subject |
119 | ("deposit-2", | 87 | ("debit-1", |
120 | "KUDOS:5.01", | 88 | "KUDOS:5.01", |
121 | bank_url, | 89 | bank_url, |
122 | BANK_ACCOUNT_NUMBER, | 90 | EXCHANGE_ACCOUNT_NUMBER, |
123 | EXCHANGE_ACCOUNT_NUMBER, | 91 | BANK_ACCOUNT_NUMBER, |
124 | AUTHS[BANK_ACCOUNT_NUMBER - 1].details.basic.username, | 92 | AUTHS[EXCHANGE_ACCOUNT_NUMBER - 1].details.basic.username, |
125 | AUTHS[BANK_ACCOUNT_NUMBER - 1].details.basic.password, | 93 | AUTHS[EXCHANGE_ACCOUNT_NUMBER - 1].details.basic.password, |
126 | "subject 2", | 94 | "subject 1", |
127 | "http://exchange.com/"), | 95 | "http://exchange.com/"), |
96 | |||
128 | TALER_TESTING_cmd_bank_history ("history-1c", | 97 | TALER_TESTING_cmd_bank_history ("history-1c", |
129 | bank_url, | 98 | bank_url, |
130 | EXCHANGE_ACCOUNT_NUMBER, | 99 | BANK_ACCOUNT_NUMBER, |
131 | TALER_BANK_DIRECTION_CREDIT, | 100 | TALER_BANK_DIRECTION_CREDIT, |
132 | GNUNET_YES, | 101 | GNUNET_YES, |
133 | NULL, | 102 | NULL, |
134 | 5), | 103 | 5), |
104 | |||
135 | TALER_TESTING_cmd_bank_history ("history-1d", | 105 | TALER_TESTING_cmd_bank_history ("history-1d", |
136 | bank_url, | 106 | bank_url, |
137 | EXCHANGE_ACCOUNT_NUMBER, | 107 | BANK_ACCOUNT_NUMBER, |
138 | TALER_BANK_DIRECTION_DEBIT, | 108 | TALER_BANK_DIRECTION_DEBIT, |
139 | GNUNET_YES, | 109 | GNUNET_YES, |
140 | NULL, | 110 | NULL, |
141 | 5), | 111 | 5), |
142 | TALER_TESTING_cmd_bank_history ("history-1dr", | 112 | |
113 | TALER_TESTING_cmd_fakebank_transfer_with_subject | ||
114 | ("debit-2", | ||
115 | "KUDOS:3.21", | ||
116 | bank_url, | ||
117 | EXCHANGE_ACCOUNT_NUMBER, // debit account. | ||
118 | USER_ACCOUNT_NUMBER, | ||
119 | AUTHS[EXCHANGE_ACCOUNT_NUMBER - 1].details.basic.username, | ||
120 | AUTHS[EXCHANGE_ACCOUNT_NUMBER - 1].details.basic.password, | ||
121 | "subject 2", | ||
122 | "http://exchange.org/"), | ||
123 | |||
124 | TALER_TESTING_cmd_fakebank_transfer_with_subject | ||
125 | ("credit-2", | ||
126 | "KUDOS:3.22", | ||
127 | bank_url, | ||
128 | USER_ACCOUNT_NUMBER, // debit account. | ||
129 | EXCHANGE_ACCOUNT_NUMBER, | ||
130 | AUTHS[USER_ACCOUNT_NUMBER - 1].details.basic.username, | ||
131 | AUTHS[USER_ACCOUNT_NUMBER - 1].details.basic.password, | ||
132 | "credit 2", | ||
133 | "http://exchange.org/"), | ||
134 | |||
135 | TALER_TESTING_cmd_bank_history ("history-2b", | ||
143 | bank_url, | 136 | bank_url, |
144 | EXCHANGE_ACCOUNT_NUMBER, | 137 | EXCHANGE_ACCOUNT_NUMBER, |
145 | TALER_BANK_DIRECTION_DEBIT, | 138 | TALER_BANK_DIRECTION_BOTH, |
146 | GNUNET_YES, | 139 | GNUNET_YES, |
147 | NULL, | 140 | NULL, |
148 | 5), | 141 | 5), |
149 | TALER_TESTING_cmd_bank_history ("history-2fwd", | 142 | |
143 | TALER_TESTING_cmd_bank_history ("history-2bi", | ||
150 | bank_url, | 144 | bank_url, |
151 | EXCHANGE_ACCOUNT_NUMBER, | 145 | EXCHANGE_ACCOUNT_NUMBER, |
152 | TALER_BANK_DIRECTION_DEBIT, | 146 | TALER_BANK_DIRECTION_BOTH, |
153 | GNUNET_YES, | 147 | GNUNET_YES, |
154 | "deposit-1", | 148 | "debit-1", |
155 | 5), | 149 | 5), |
156 | /** | 150 | |
157 | * Just check that the two transactions show up. | 151 | TALER_TESTING_cmd_fakebank_transfer_with_subject |
158 | */ | 152 | ("credit-for-reject-1", |
159 | TALER_TESTING_cmd_bank_history_range_with_dates | 153 | "KUDOS:1.01", |
160 | ("history-2-range", | 154 | bank_url, |
161 | bank_url, | 155 | BANK_ACCOUNT_NUMBER, |
162 | EXCHANGE_ACCOUNT_NUMBER, | 156 | EXCHANGE_ACCOUNT_NUMBER, |
163 | TALER_BANK_DIRECTION_BOTH, | 157 | AUTHS[BANK_ACCOUNT_NUMBER - 1].details.basic.username, |
164 | GNUNET_NO, | 158 | AUTHS[BANK_ACCOUNT_NUMBER - 1].details.basic.password, |
165 | SUBSECS (now, | 159 | "subject 3", |
166 | 50), | 160 | "http://exchange.net/"), |
167 | ADDSECS (now, | 161 | |
168 | 5)), | ||
169 | TALER_TESTING_cmd_bank_reject ("reject-1", | 162 | TALER_TESTING_cmd_bank_reject ("reject-1", |
170 | bank_url, | 163 | bank_url, |
171 | "deposit-1"), | 164 | "credit-for-reject-1"), |
165 | |||
166 | TALER_TESTING_cmd_bank_history ("history-r1", | ||
167 | bank_url, | ||
168 | BANK_ACCOUNT_NUMBER, | ||
169 | TALER_BANK_DIRECTION_BOTH, | ||
170 | GNUNET_YES, | ||
171 | NULL, | ||
172 | 5), | ||
173 | |||
174 | TALER_TESTING_cmd_bank_history ("history-r1c", | ||
175 | bank_url, | ||
176 | BANK_ACCOUNT_NUMBER, | ||
177 | TALER_BANK_DIRECTION_BOTH | ||
178 | | TALER_BANK_DIRECTION_CANCEL, | ||
179 | GNUNET_YES, | ||
180 | NULL, | ||
181 | 5), | ||
182 | |||
172 | /** | 183 | /** |
173 | * End the suite. Fixme: better to have a label for this | 184 | * End the suite. Fixme: better to have a label for this |
174 | * too, as it shows a "(null)" token on logs. | 185 | * too, as it shows a "(null)" token on logs. |
@@ -176,44 +187,76 @@ run (void *cls, | |||
176 | TALER_TESTING_cmd_end () | 187 | TALER_TESTING_cmd_end () |
177 | }; | 188 | }; |
178 | 189 | ||
179 | TALER_TESTING_run (is, commands); | 190 | if (GNUNET_YES == WITH_FAKEBANK) |
191 | TALER_TESTING_run_with_fakebank (is, | ||
192 | commands, | ||
193 | bank_url); | ||
194 | else | ||
195 | TALER_TESTING_run (is, | ||
196 | commands); | ||
180 | } | 197 | } |
181 | 198 | ||
182 | |||
183 | /* Pacifies "make check" */ | ||
184 | int | 199 | int |
185 | main (int argc, | 200 | main (int argc, |
186 | char *const *argv) | 201 | char *const *argv) |
187 | { | 202 | { |
188 | unsigned int ret; | 203 | int rv; |
189 | /* These environment variables get in the way... */ | 204 | /* These environment variables get in the way... */ |
190 | unsetenv ("XDG_DATA_HOME"); | 205 | unsetenv ("XDG_DATA_HOME"); |
191 | unsetenv ("XDG_CONFIG_HOME"); | 206 | unsetenv ("XDG_CONFIG_HOME"); |
192 | GNUNET_log_setup ("test-bank-api-new", "DEBUG", NULL); | 207 | GNUNET_log_setup ("test-bank-api-with-(fake)bank-new", |
208 | "DEBUG", | ||
209 | NULL); | ||
193 | 210 | ||
194 | if (NULL == | 211 | WITH_FAKEBANK = TALER_TESTING_has_in_name (argv[0], |
195 | (bank_url = TALER_TESTING_prepare_bank (CONFIG_FILE))) | 212 | "_with_fakebank"); |
196 | return 77; | 213 | if (GNUNET_YES == WITH_FAKEBANK) |
214 | { | ||
215 | TALER_LOG_DEBUG ("Running against the Fakebank.\n"); | ||
216 | if (NULL == (bank_url = TALER_TESTING_prepare_fakebank | ||
217 | (CONFIG_FILE, | ||
218 | "account-1"))) | ||
219 | { | ||
220 | GNUNET_break (0); | ||
221 | return 77; | ||
222 | } | ||
223 | } | ||
224 | else | ||
225 | { | ||
226 | TALER_LOG_DEBUG ("Running against the Pybank.\n"); | ||
227 | if (NULL == (bank_url = TALER_TESTING_prepare_bank | ||
228 | (CONFIG_FILE))) | ||
229 | { | ||
230 | GNUNET_break (0); | ||
231 | return 77; | ||
232 | } | ||
197 | 233 | ||
198 | if (NULL == (bankd = | 234 | if (NULL == (bankd = TALER_TESTING_run_bank |
199 | TALER_TESTING_run_bank (CONFIG_FILE, bank_url))) | 235 | (CONFIG_FILE, |
200 | return 77; | 236 | bank_url))) |
237 | { | ||
238 | GNUNET_break (0); | ||
239 | return 77; | ||
240 | } | ||
241 | } | ||
201 | 242 | ||
202 | ret = TALER_TESTING_setup (&run, | 243 | rv = (GNUNET_OK == TALER_TESTING_setup (&run, |
203 | NULL, | 244 | NULL, |
204 | CONFIG_FILE, | 245 | CONFIG_FILE, |
205 | NULL, | 246 | NULL, |
206 | GNUNET_NO); // means no exchange. | 247 | GNUNET_NO)) ? 0 : 1; |
248 | if (GNUNET_NO == WITH_FAKEBANK) | ||
249 | { | ||
207 | 250 | ||
208 | GNUNET_OS_process_kill (bankd, SIGKILL); | 251 | GNUNET_OS_process_kill (bankd, |
209 | GNUNET_OS_process_wait (bankd); | 252 | SIGKILL); |
210 | GNUNET_OS_process_destroy (bankd); | 253 | GNUNET_OS_process_wait (bankd); |
211 | GNUNET_free (bank_url); | 254 | GNUNET_OS_process_destroy (bankd); |
212 | 255 | GNUNET_free (bank_url); | |
213 | if (GNUNET_OK == ret) | 256 | } |
214 | return 0; | 257 | |
215 | 258 | return rv; | |
216 | return 1; | ||
217 | } | 259 | } |
218 | 260 | ||
219 | /* end of test_bank_api_new.c */ | 261 | |
262 | /* end of test_bank_api_with_fakebank_new.c */ | ||