aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcello Stanisci <stanisci.m@gmail.com>2019-09-09 23:20:18 +0200
committerMarcello Stanisci <stanisci.m@gmail.com>2019-09-09 23:47:00 +0200
commit447d1d78ad88566577961fc9befc3d2c1888675c (patch)
tree2379abd2a39e4f0322fcb8831b02ae8f0455019e
parentcb6aab590b93e619fd5ca1fd18f3dd1fcefd5696 (diff)
downloadexchange-447d1d78ad88566577961fc9befc3d2c1888675c.tar.gz
exchange-447d1d78ad88566577961fc9befc3d2c1888675c.zip
Importing the "has_in_name" logic from MHD.
-rw-r--r--src/bank-lib/test_bank_api_with_fakebank_new.c171
-rw-r--r--src/bank-lib/testing_api_helpers.c30
-rw-r--r--src/include/taler_testing_bank_lib.h10
3 files changed, 153 insertions, 58 deletions
diff --git a/src/bank-lib/test_bank_api_with_fakebank_new.c b/src/bank-lib/test_bank_api_with_fakebank_new.c
index 046248ad8..a2f776239 100644
--- a/src/bank-lib/test_bank_api_with_fakebank_new.c
+++ b/src/bank-lib/test_bank_api_with_fakebank_new.c
@@ -40,11 +40,21 @@
40 40
41#define CONFIG_FILE "bank.conf" 41#define CONFIG_FILE "bank.conf"
42 42
43
44/** 43/**
45 * Fakebank URL. 44 * Fakebank URL.
46 */ 45 */
47char *fakebank_url; 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;
48 58
49/** 59/**
50 * Main function that will tell the interpreter what commands to 60 * Main function that will tell the interpreter what commands to
@@ -57,14 +67,14 @@ run (void *cls,
57 struct TALER_TESTING_Interpreter *is) 67 struct TALER_TESTING_Interpreter *is)
58{ 68{
59 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 69 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
60 "Fakebank serves at `%s'\n", 70 "Bank serves at `%s'\n",
61 fakebank_url); 71 bank_url);
62 extern struct TALER_BANK_AuthenticationData AUTHS[]; 72 extern struct TALER_BANK_AuthenticationData AUTHS[];
63 73
64 struct TALER_TESTING_Command commands[] = { 74 struct TALER_TESTING_Command commands[] = {
65 75
66 TALER_TESTING_cmd_bank_history ("history-0", 76 TALER_TESTING_cmd_bank_history ("history-0",
67 fakebank_url, 77 bank_url,
68 BANK_ACCOUNT_NUMBER, 78 BANK_ACCOUNT_NUMBER,
69 TALER_BANK_DIRECTION_BOTH, 79 TALER_BANK_DIRECTION_BOTH,
70 GNUNET_YES, 80 GNUNET_YES,
@@ -76,17 +86,17 @@ run (void *cls,
76 * the parameters, although it was always set as '200 OK' */ 86 * the parameters, although it was always set as '200 OK' */
77 TALER_TESTING_cmd_fakebank_transfer_with_subject 87 TALER_TESTING_cmd_fakebank_transfer_with_subject
78 ("debit-1", 88 ("debit-1",
79 "KUDOS:5.01", 89 "KUDOS:5.01",
80 fakebank_url, 90 bank_url,
81 EXCHANGE_ACCOUNT_NUMBER, 91 EXCHANGE_ACCOUNT_NUMBER,
82 BANK_ACCOUNT_NUMBER, 92 BANK_ACCOUNT_NUMBER,
83 AUTHS[EXCHANGE_ACCOUNT_NUMBER - 1].details.basic.username, 93 AUTHS[EXCHANGE_ACCOUNT_NUMBER - 1].details.basic.username,
84 AUTHS[EXCHANGE_ACCOUNT_NUMBER - 1].details.basic.password, 94 AUTHS[EXCHANGE_ACCOUNT_NUMBER - 1].details.basic.password,
85 "subject 1", 95 "subject 1",
86 "http://exchange.com/"), 96 "http://exchange.com/"),
87 97
88 TALER_TESTING_cmd_bank_history ("history-1c", 98 TALER_TESTING_cmd_bank_history ("history-1c",
89 fakebank_url, 99 bank_url,
90 BANK_ACCOUNT_NUMBER, 100 BANK_ACCOUNT_NUMBER,
91 TALER_BANK_DIRECTION_CREDIT, 101 TALER_BANK_DIRECTION_CREDIT,
92 GNUNET_YES, 102 GNUNET_YES,
@@ -94,7 +104,7 @@ run (void *cls,
94 5), 104 5),
95 105
96 TALER_TESTING_cmd_bank_history ("history-1d", 106 TALER_TESTING_cmd_bank_history ("history-1d",
97 fakebank_url, 107 bank_url,
98 BANK_ACCOUNT_NUMBER, 108 BANK_ACCOUNT_NUMBER,
99 TALER_BANK_DIRECTION_DEBIT, 109 TALER_BANK_DIRECTION_DEBIT,
100 GNUNET_YES, 110 GNUNET_YES,
@@ -103,28 +113,28 @@ run (void *cls,
103 113
104 TALER_TESTING_cmd_fakebank_transfer_with_subject 114 TALER_TESTING_cmd_fakebank_transfer_with_subject
105 ("debit-2", 115 ("debit-2",
106 "KUDOS:3.21", 116 "KUDOS:3.21",
107 fakebank_url, 117 bank_url,
108 EXCHANGE_ACCOUNT_NUMBER, // debit account. 118 EXCHANGE_ACCOUNT_NUMBER, // debit account.
109 USER_ACCOUNT_NUMBER, 119 USER_ACCOUNT_NUMBER,
110 AUTHS[EXCHANGE_ACCOUNT_NUMBER - 1].details.basic.username, 120 AUTHS[EXCHANGE_ACCOUNT_NUMBER - 1].details.basic.username,
111 AUTHS[EXCHANGE_ACCOUNT_NUMBER - 1].details.basic.password, 121 AUTHS[EXCHANGE_ACCOUNT_NUMBER - 1].details.basic.password,
112 "subject 2", 122 "subject 2",
113 "http://exchange.org/"), 123 "http://exchange.org/"),
114 124
115 TALER_TESTING_cmd_fakebank_transfer_with_subject 125 TALER_TESTING_cmd_fakebank_transfer_with_subject
116 ("credit-2", 126 ("credit-2",
117 "KUDOS:3.22", 127 "KUDOS:3.22",
118 fakebank_url, 128 bank_url,
119 USER_ACCOUNT_NUMBER, // debit account. 129 USER_ACCOUNT_NUMBER, // debit account.
120 EXCHANGE_ACCOUNT_NUMBER, 130 EXCHANGE_ACCOUNT_NUMBER,
121 AUTHS[USER_ACCOUNT_NUMBER - 1].details.basic.username, 131 AUTHS[USER_ACCOUNT_NUMBER - 1].details.basic.username,
122 AUTHS[USER_ACCOUNT_NUMBER - 1].details.basic.password, 132 AUTHS[USER_ACCOUNT_NUMBER - 1].details.basic.password,
123 "credit 2", 133 "credit 2",
124 "http://exchange.org/"), 134 "http://exchange.org/"),
125 135
126 TALER_TESTING_cmd_bank_history ("history-2b", 136 TALER_TESTING_cmd_bank_history ("history-2b",
127 fakebank_url, 137 bank_url,
128 EXCHANGE_ACCOUNT_NUMBER, 138 EXCHANGE_ACCOUNT_NUMBER,
129 TALER_BANK_DIRECTION_BOTH, 139 TALER_BANK_DIRECTION_BOTH,
130 GNUNET_YES, 140 GNUNET_YES,
@@ -132,7 +142,7 @@ run (void *cls,
132 5), 142 5),
133 143
134 TALER_TESTING_cmd_bank_history ("history-2bi", 144 TALER_TESTING_cmd_bank_history ("history-2bi",
135 fakebank_url, 145 bank_url,
136 EXCHANGE_ACCOUNT_NUMBER, 146 EXCHANGE_ACCOUNT_NUMBER,
137 TALER_BANK_DIRECTION_BOTH, 147 TALER_BANK_DIRECTION_BOTH,
138 GNUNET_YES, 148 GNUNET_YES,
@@ -152,21 +162,21 @@ run (void *cls,
152 162
153 TALER_TESTING_cmd_fakebank_transfer_with_subject 163 TALER_TESTING_cmd_fakebank_transfer_with_subject
154 ("credit-for-reject-1", 164 ("credit-for-reject-1",
155 "KUDOS:5.01", 165 "KUDOS:5.01",
156 fakebank_url, 166 bank_url,
157 BANK_ACCOUNT_NUMBER, 167 BANK_ACCOUNT_NUMBER,
158 EXCHANGE_ACCOUNT_NUMBER, 168 EXCHANGE_ACCOUNT_NUMBER,
159 AUTHS[BANK_ACCOUNT_NUMBER - 1].details.basic.username, 169 AUTHS[BANK_ACCOUNT_NUMBER - 1].details.basic.username,
160 AUTHS[BANK_ACCOUNT_NUMBER - 1].details.basic.password, 170 AUTHS[BANK_ACCOUNT_NUMBER - 1].details.basic.password,
161 "subject 3", 171 "subject 3",
162 "http://exchange.net/"), 172 "http://exchange.net/"),
163 173
164 TALER_TESTING_cmd_bank_reject ("reject-1", 174 TALER_TESTING_cmd_bank_reject ("reject-1",
165 fakebank_url, 175 bank_url,
166 "credit-for-reject-1"), 176 "credit-for-reject-1"),
167 177
168 TALER_TESTING_cmd_bank_history ("history-r1", 178 TALER_TESTING_cmd_bank_history ("history-r1",
169 fakebank_url, 179 bank_url,
170 BANK_ACCOUNT_NUMBER, 180 BANK_ACCOUNT_NUMBER,
171 TALER_BANK_DIRECTION_BOTH, 181 TALER_BANK_DIRECTION_BOTH,
172 GNUNET_YES, 182 GNUNET_YES,
@@ -174,7 +184,7 @@ run (void *cls,
174 5), 184 5),
175 185
176 TALER_TESTING_cmd_bank_history ("history-r1c", 186 TALER_TESTING_cmd_bank_history ("history-r1c",
177 fakebank_url, 187 bank_url,
178 BANK_ACCOUNT_NUMBER, 188 BANK_ACCOUNT_NUMBER,
179 TALER_BANK_DIRECTION_BOTH 189 TALER_BANK_DIRECTION_BOTH
180 | TALER_BANK_DIRECTION_CANCEL, 190 | TALER_BANK_DIRECTION_CANCEL,
@@ -184,7 +194,7 @@ run (void *cls,
184 194
185 TALER_TESTING_cmd_check_bank_transfer_with_ref 195 TALER_TESTING_cmd_check_bank_transfer_with_ref
186 ("expect-credit-reject-1", 196 ("expect-credit-reject-1",
187 "credit-for-reject-1"), 197 "credit-for-reject-1"),
188 198
189 TALER_TESTING_cmd_check_bank_empty ("expect-empty-2"), 199 TALER_TESTING_cmd_check_bank_empty ("expect-empty-2"),
190 200
@@ -195,31 +205,76 @@ run (void *cls,
195 TALER_TESTING_cmd_end () 205 TALER_TESTING_cmd_end ()
196 }; 206 };
197 207
198 TALER_TESTING_run_with_fakebank (is, 208 if (GNUNET_YES == WITH_FAKEBANK)
199 commands, 209 TALER_TESTING_run_with_fakebank (is,
200 fakebank_url); 210 commands,
211 bank_url);
212 else
213 TALER_TESTING_run (is,
214 commands);
201} 215}
202 216
203int 217int
204main (int argc, 218main (int argc,
205 char *const *argv) 219 char *const *argv)
206{ 220{
221 int rv;
222
207 /* These environment variables get in the way... */ 223 /* These environment variables get in the way... */
208 unsetenv ("XDG_DATA_HOME"); 224 unsetenv ("XDG_DATA_HOME");
209 unsetenv ("XDG_CONFIG_HOME"); 225 unsetenv ("XDG_CONFIG_HOME");
210 GNUNET_log_setup ("test-bank-api-with-fakebank-new", 226 GNUNET_log_setup ("test-bank-api-with-fakebank-new",
211 "DEBUG", 227 "DEBUG",
212 NULL); 228 NULL);
213 if (NULL == 229
214 (fakebank_url = TALER_TESTING_prepare_fakebank (CONFIG_FILE, 230 WITH_FAKEBANK = TALER_TESTING_has_in_name (argv[0],
215 "account-1"))) 231 "_with_fakebank");
216 return 77; 232
217 233 if (GNUNET_YES == WITH_FAKEBANK)
218 return (GNUNET_OK == TALER_TESTING_setup (&run, 234 {
219 NULL, 235 TALER_LOG_DEBUG ("Running against the Fakebank.\n");
220 CONFIG_FILE, 236 if (NULL == (bank_url = TALER_TESTING_prepare_fakebank
221 NULL, 237 (CONFIG_FILE,
222 GNUNET_NO)) ? 0 : 1; 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;
223} 278}
224 279
225 280
diff --git a/src/bank-lib/testing_api_helpers.c b/src/bank-lib/testing_api_helpers.c
index a047c2a71..411391e5a 100644
--- a/src/bank-lib/testing_api_helpers.c
+++ b/src/bank-lib/testing_api_helpers.c
@@ -83,6 +83,36 @@ TALER_TESTING_run_fakebank (const char *bank_url)
83 return fakebankd; 83 return fakebankd;
84} 84}
85 85
86
87/**
88 * Look for substring in a programs' name.
89 *
90 * @param prog program's name to look into
91 * @param marker chunk to find in @a prog
92 */
93int
94TALER_TESTING_has_in_name (const char *prog_name,
95 const char *marker)
96{
97 size_t name_pos;
98 size_t pos;
99
100 if (!prog_name || !marker)
101 return GNUNET_NO;
102
103 pos = 0;
104 name_pos = 0;
105 while (prog_name[pos])
106 {
107 if ('/' == prog_name[pos])
108 name_pos = pos + 1;
109 pos++;
110 }
111 if (name_pos == pos)
112 return GNUNET_YES;
113 return strstr(prog_name + name_pos, marker) != NULL;
114}
115
86/** 116/**
87 * Start the (Python) bank process. Assume the port 117 * Start the (Python) bank process. Assume the port
88 * is available and the database is clean. Use the "prepare 118 * is available and the database is clean. Use the "prepare
diff --git a/src/include/taler_testing_bank_lib.h b/src/include/taler_testing_bank_lib.h
index f72b804cd..72176d445 100644
--- a/src/include/taler_testing_bank_lib.h
+++ b/src/include/taler_testing_bank_lib.h
@@ -91,6 +91,16 @@ char *
91TALER_TESTING_prepare_bank (const char *config_filename); 91TALER_TESTING_prepare_bank (const char *config_filename);
92 92
93 93
94/**
95 * Look for substring in a programs' name.
96 *
97 * @param prog program's name to look into
98 * @param marker chunk to find in @a prog
99 */
100int
101TALER_TESTING_has_in_name (const char *prog,
102 const char *marker);
103
94/* ************** Specific interpreter commands ************ */ 104/* ************** Specific interpreter commands ************ */
95 105
96/** 106/**