diff options
Diffstat (limited to 'src/cli/test_anastasis_reducer_enter_secret.sh')
-rwxr-xr-x | src/cli/test_anastasis_reducer_enter_secret.sh | 417 |
1 files changed, 417 insertions, 0 deletions
diff --git a/src/cli/test_anastasis_reducer_enter_secret.sh b/src/cli/test_anastasis_reducer_enter_secret.sh new file mode 100755 index 0000000..dadd8d0 --- /dev/null +++ b/src/cli/test_anastasis_reducer_enter_secret.sh | |||
@@ -0,0 +1,417 @@ | |||
1 | #!/bin/bash | ||
2 | ## Coloring style Text shell script | ||
3 | COLOR='\033[0;35m' | ||
4 | NOCOLOR='\033[0m' | ||
5 | BOLD="$(tput bold)" | ||
6 | NORM="$(tput sgr0)" | ||
7 | |||
8 | set -eu | ||
9 | |||
10 | # Exit, with status code "skip" (no 'real' failure) | ||
11 | function exit_skip() { | ||
12 | echo " SKIP: $1" | ||
13 | exit 77 | ||
14 | } | ||
15 | |||
16 | # Exit, with error message (hard failure) | ||
17 | function exit_fail() { | ||
18 | echo " FAIL: $1" | ||
19 | exit 1 | ||
20 | } | ||
21 | |||
22 | # Cleanup to run whenever we exit | ||
23 | function cleanup() | ||
24 | { | ||
25 | for n in `jobs -p` | ||
26 | do | ||
27 | kill $n 2> /dev/null || true | ||
28 | done | ||
29 | rm -rf $CONF $WALLET_DB $TFILE $UFILE $TMP_DIR | ||
30 | wait | ||
31 | } | ||
32 | |||
33 | CONF_1="test_anastasis_reducer_1.conf" | ||
34 | CONF_2="test_anastasis_reducer_2.conf" | ||
35 | CONF_3="test_anastasis_reducer_3.conf" | ||
36 | CONF_4="test_anastasis_reducer_4.conf" | ||
37 | |||
38 | # Exchange configuration file will be edited, so we create one | ||
39 | # from the template. | ||
40 | CONF=`mktemp test_reducerXXXXXX.conf` | ||
41 | cp test_reducer.conf $CONF | ||
42 | |||
43 | TMP_DIR=`mktemp -d keys-tmp-XXXXXX` | ||
44 | WALLET_DB=`mktemp test_reducer_walletXXXXXX.json` | ||
45 | TFILE=`mktemp test_reducer_statePPXXXXXX` | ||
46 | UFILE=`mktemp test_reducer_stateBFXXXXXX` | ||
47 | |||
48 | # Install cleanup handler (except for kill -9) | ||
49 | trap cleanup EXIT | ||
50 | |||
51 | # Check we can actually run | ||
52 | echo -n "Testing for jq" | ||
53 | jq -h > /dev/null || exit_skip "jq required" | ||
54 | echo " FOUND" | ||
55 | echo -n "Testing for anastasis-reducer ..." | ||
56 | anastasis-reducer -h > /dev/null || exit_skip "anastasis-reducer required" | ||
57 | echo " FOUND" | ||
58 | |||
59 | echo -n "Testing for taler" | ||
60 | taler-exchange-httpd -h > /dev/null || exit_skip " taler-exchange required" | ||
61 | taler-merchant-httpd -h > /dev/null || exit_skip " taler-merchant required" | ||
62 | echo " FOUND" | ||
63 | |||
64 | echo -n "Testing for taler-bank-manage" | ||
65 | taler-bank-manage --help >/dev/null </dev/null || exit_skip " MISSING" | ||
66 | echo " FOUND" | ||
67 | echo -n "Testing for taler-wallet-cli" | ||
68 | taler-wallet-cli -v >/dev/null </dev/null || exit_skip " MISSING" | ||
69 | echo " FOUND" | ||
70 | |||
71 | echo -n "Testing for anastasis-httpd" | ||
72 | anastasis-httpd -h >/dev/null </dev/null || exit_skip " MISSING" | ||
73 | echo " FOUND" | ||
74 | |||
75 | echo -n "Initialize anastasis database ..." | ||
76 | # Name of the Postgres database we will use for the script. | ||
77 | # Will be dropped, do NOT use anything that might be used | ||
78 | # elsewhere | ||
79 | TARGET_DB_1=`anastasis-config -c $CONF_1 -s stasis-postgres -o CONFIG | sed -e "s/^postgres:\/\/\///"` | ||
80 | TARGET_DB_2=`anastasis-config -c $CONF_2 -s stasis-postgres -o CONFIG | sed -e "s/^postgres:\/\/\///"` | ||
81 | TARGET_DB_3=`anastasis-config -c $CONF_3 -s stasis-postgres -o CONFIG | sed -e "s/^postgres:\/\/\///"` | ||
82 | TARGET_DB_4=`anastasis-config -c $CONF_4 -s stasis-postgres -o CONFIG | sed -e "s/^postgres:\/\/\///"` | ||
83 | |||
84 | dropdb $TARGET_DB_1 >/dev/null 2>/dev/null || true | ||
85 | createdb $TARGET_DB_1 || exit_skip "Could not create database $TARGET_DB_1" | ||
86 | anastasis-dbinit -c $CONF_1 2> anastasis-dbinit_1.log | ||
87 | dropdb $TARGET_DB_2 >/dev/null 2>/dev/null || true | ||
88 | createdb $TARGET_DB_2 || exit_skip "Could not create database $TARGET_DB_2" | ||
89 | anastasis-dbinit -c $CONF_2 2> anastasis-dbinit_2.log | ||
90 | dropdb $TARGET_DB_3 >/dev/null 2>/dev/null || true | ||
91 | createdb $TARGET_DB_3 || exit_skip "Could not create database $TARGET_DB_3" | ||
92 | anastasis-dbinit -c $CONF_3 2> anastasis-dbinit_3.log | ||
93 | dropdb $TARGET_DB_4 >/dev/null 2>/dev/null || true | ||
94 | createdb $TARGET_DB_4 || exit_skip "Could not create database $TARGET_DB_4" | ||
95 | anastasis-dbinit -c $CONF_4 2> anastasis-dbinit_4.log | ||
96 | |||
97 | echo " OK" | ||
98 | |||
99 | echo -n "Generating Taler auditor, exchange and merchant configurations ..." | ||
100 | |||
101 | DATA_DIR=`taler-config -f -c $CONF -s PATHS -o TALER_HOME` | ||
102 | rm -rf $DATA_DIR | ||
103 | |||
104 | # obtain key configuration data | ||
105 | MASTER_PRIV_FILE=`taler-config -f -c $CONF -s EXCHANGE -o MASTER_PRIV_FILE` | ||
106 | MASTER_PRIV_DIR=`dirname $MASTER_PRIV_FILE` | ||
107 | mkdir -p $MASTER_PRIV_DIR | ||
108 | gnunet-ecc -g1 $MASTER_PRIV_FILE > /dev/null 2> /dev/null | ||
109 | MASTER_PUB=`gnunet-ecc -p $MASTER_PRIV_FILE` | ||
110 | EXCHANGE_URL=`taler-config -c $CONF -s EXCHANGE -o BASE_URL` | ||
111 | MERCHANT_PORT=`taler-config -c $CONF -s MERCHANT -o PORT` | ||
112 | MERCHANT_URL=http://localhost:${MERCHANT_PORT}/ | ||
113 | BANK_PORT=`taler-config -c $CONF -s BANK -o HTTP_PORT` | ||
114 | BANK_URL=http://localhost:${BANK_PORT}/ | ||
115 | AUDITOR_URL=http://localhost:8083/ | ||
116 | AUDITOR_PRIV_FILE=`taler-config -f -c $CONF -s AUDITOR -o AUDITOR_PRIV_FILE` | ||
117 | AUDITOR_PRIV_DIR=`dirname $AUDITOR_PRIV_FILE` | ||
118 | mkdir -p $AUDITOR_PRIV_DIR | ||
119 | gnunet-ecc -g1 $AUDITOR_PRIV_FILE > /dev/null 2> /dev/null | ||
120 | AUDITOR_PUB=`gnunet-ecc -p $AUDITOR_PRIV_FILE` | ||
121 | |||
122 | # patch configuration | ||
123 | TALER_DB=talercheck | ||
124 | taler-config -c $CONF -s exchange -o MASTER_PUBLIC_KEY -V $MASTER_PUB | ||
125 | taler-config -c $CONF -s merchant-exchange-default -o MASTER_KEY -V $MASTER_PUB | ||
126 | taler-config -c $CONF -s exchangedb-postgres -o CONFIG -V postgres:///$TALER_DB | ||
127 | taler-config -c $CONF -s auditordb-postgres -o CONFIG -V postgres:///$TALER_DB | ||
128 | taler-config -c $CONF -s merchantdb-postgres -o CONFIG -V postgres:///$TALER_DB | ||
129 | taler-config -c $CONF -s bank -o database -V postgres:///$TALER_DB | ||
130 | taler-config -c $CONF -s exchange -o KEYDIR -V "${TMP_DIR}/keydir/" | ||
131 | taler-config -c $CONF -s exchange -o REVOCATION_DIR -V "${TMP_DIR}/revdir/" | ||
132 | |||
133 | echo " OK" | ||
134 | |||
135 | echo -n "Setting up exchange ..." | ||
136 | |||
137 | # reset database | ||
138 | dropdb $TALER_DB >/dev/null 2>/dev/null || true | ||
139 | createdb $TALER_DB || exit_skip "Could not create database $TALER_DB" | ||
140 | taler-exchange-dbinit -c $CONF | ||
141 | taler-merchant-dbinit -c $CONF | ||
142 | taler-auditor-dbinit -c $CONF | ||
143 | taler-auditor-exchange -c $CONF -m $MASTER_PUB -u $EXCHANGE_URL | ||
144 | |||
145 | echo " OK" | ||
146 | |||
147 | # Launch services | ||
148 | echo -n "Launching taler services ..." | ||
149 | taler-bank-manage-testing $CONF postgres:///$TALER_DB serve > taler-bank.log 2> taler-bank.err & | ||
150 | taler-exchange-secmod-eddsa -c $CONF 2> taler-exchange-secmod-eddsa.log & | ||
151 | taler-exchange-secmod-rsa -c $CONF 2> taler-exchange-secmod-rsa.log & | ||
152 | taler-exchange-httpd -c $CONF 2> taler-exchange-httpd.log & | ||
153 | taler-merchant-httpd -c $CONF -L INFO 2> taler-merchant-httpd.log & | ||
154 | taler-exchange-wirewatch -c $CONF 2> taler-exchange-wirewatch.log & | ||
155 | taler-auditor-httpd -L INFO -c $CONF 2> taler-auditor-httpd.log & | ||
156 | |||
157 | echo " OK" | ||
158 | |||
159 | echo -n "Launching anastasis services ..." | ||
160 | PREFIX="" #valgrind | ||
161 | $PREFIX anastasis-httpd -c $CONF_1 2> anastasis-httpd_1.log & | ||
162 | $PREFIX anastasis-httpd -c $CONF_2 2> anastasis-httpd_2.log & | ||
163 | $PREFIX anastasis-httpd -c $CONF_3 2> anastasis-httpd_3.log & | ||
164 | $PREFIX anastasis-httpd -c $CONF_4 2> anastasis-httpd_4.log & | ||
165 | |||
166 | # Wait for bank to be available (usually the slowest) | ||
167 | for n in `seq 1 50` | ||
168 | do | ||
169 | echo -n "." | ||
170 | sleep 0.2 | ||
171 | OK=0 | ||
172 | # bank | ||
173 | wget --tries=1 --timeout=1 http://localhost:8082/ -o /dev/null -O /dev/null >/dev/null || continue | ||
174 | OK=1 | ||
175 | break | ||
176 | done | ||
177 | |||
178 | if [ 1 != $OK ] | ||
179 | then | ||
180 | exit_skip "Failed to launch services (bank)" | ||
181 | fi | ||
182 | |||
183 | # Wait for all other taler services to be available | ||
184 | for n in `seq 1 50` | ||
185 | do | ||
186 | echo -n "." | ||
187 | sleep 0.1 | ||
188 | OK=0 | ||
189 | # exchange | ||
190 | wget --tries=1 --timeout=1 http://localhost:8081/seed -o /dev/null -O /dev/null >/dev/null || continue | ||
191 | # merchant | ||
192 | wget --tries=1 --timeout=1 http://localhost:9966/ -o /dev/null -O /dev/null >/dev/null || continue | ||
193 | # auditor | ||
194 | wget --tries=1 --timeout=1 http://localhost:8083/ -o /dev/null -O /dev/null >/dev/null || continue | ||
195 | OK=1 | ||
196 | break | ||
197 | done | ||
198 | |||
199 | if [ 1 != $OK ] | ||
200 | then | ||
201 | exit_skip "Failed to launch taler services" | ||
202 | fi | ||
203 | |||
204 | echo "OK" | ||
205 | |||
206 | echo -n "Setting up keys ..." | ||
207 | taler-exchange-offline -c $CONF \ | ||
208 | download \ | ||
209 | sign \ | ||
210 | enable-account payto://x-taler-bank/localhost/Exchange \ | ||
211 | enable-auditor $AUDITOR_PUB $AUDITOR_URL "TESTKUDOS Auditor" \ | ||
212 | wire-fee now x-taler-bank TESTKUDOS:0.01 TESTKUDOS:0.01 \ | ||
213 | upload &> taler-exchange-offline.log | ||
214 | |||
215 | echo -n "." | ||
216 | |||
217 | for n in `seq 1 3` | ||
218 | do | ||
219 | echo -n "." | ||
220 | OK=0 | ||
221 | wget --tries=1 --timeout=1 http://localhost:8081/keys -o /dev/null -O /dev/null >/dev/null || continue | ||
222 | OK=1 | ||
223 | break | ||
224 | done | ||
225 | |||
226 | if [ 1 != $OK ] | ||
227 | then | ||
228 | exit_skip "Failed to setup keys" | ||
229 | fi | ||
230 | |||
231 | echo " OK" | ||
232 | |||
233 | echo -n "Setting up auditor signatures ..." | ||
234 | taler-auditor-offline -c $CONF \ | ||
235 | download sign upload &> taler-auditor-offline.log | ||
236 | echo " OK" | ||
237 | |||
238 | echo -n "Waiting for anastasis services ..." | ||
239 | |||
240 | # Wait for anastasis services to be available | ||
241 | for n in `seq 1 50` | ||
242 | do | ||
243 | echo -n "." | ||
244 | sleep 0.1 | ||
245 | OK=0 | ||
246 | # anastasis_01 | ||
247 | wget --tries=1 --timeout=1 http://localhost:8086/ -o /dev/null -O /dev/null >/dev/null || continue | ||
248 | # anastasis_02 | ||
249 | wget --tries=1 --timeout=1 http://localhost:8087/ -o /dev/null -O /dev/null >/dev/null || continue | ||
250 | # anastasis_03 | ||
251 | wget --tries=1 --timeout=1 http://localhost:8088/ -o /dev/null -O /dev/null >/dev/null || continue | ||
252 | # anastasis_04 | ||
253 | wget --tries=1 --timeout=1 http://localhost:8089/ -o /dev/null -O /dev/null >/dev/null || continue | ||
254 | OK=1 | ||
255 | break | ||
256 | done | ||
257 | |||
258 | if [ 1 != $OK ] | ||
259 | then | ||
260 | exit_skip "Failed to launch anastasis services" | ||
261 | fi | ||
262 | echo "OK" | ||
263 | |||
264 | echo -n "Configuring merchant instance ..." | ||
265 | # Setup merchant | ||
266 | |||
267 | curl -H "Content-Type: application/json" -X POST -d '{"auth":{"method":"external"},"payto_uris":["payto://x-taler-bank/localhost/43"],"id":"default","name":"default","address":{},"jurisdiction":{},"default_max_wire_fee":"TESTKUDOS:1", "default_max_deposit_fee":"TESTKUDOS:1","default_wire_fee_amortization":1,"default_wire_transfer_delay":{"d_ms" : 3600000},"default_pay_delay":{"d_ms": 3600000}}' http://localhost:9966/private/instances | ||
268 | |||
269 | |||
270 | echo " DONE" | ||
271 | |||
272 | echo -en $COLOR$BOLD"Test enter secret in a backup state ..."$NORM$NOCOLOR | ||
273 | |||
274 | $PREFIX anastasis-reducer -a \ | ||
275 | '{"secret": { "value" : "veryhardtoguesssecret", "mime" : "text/plain" } }' \ | ||
276 | enter_secret resources/06-backup.json $TFILE | ||
277 | |||
278 | STATE=`jq -r -e .backup_state < $TFILE` | ||
279 | if test "$STATE" != "SECRET_EDITING" | ||
280 | then | ||
281 | jq -e . $TFILE | ||
282 | exit_fail "Expected new state to be 'SECRET_EDITING', got '$STATE'" | ||
283 | fi | ||
284 | |||
285 | echo " DONE" | ||
286 | echo -en $COLOR$BOLD"Test expiration change ..."$NORM$NOCOLOR | ||
287 | |||
288 | MILLIS=`date '+%s'`000 | ||
289 | # Use 156 days into the future to get 1 year | ||
290 | MILLIS=`expr $MILLIS + 13478400000` | ||
291 | |||
292 | $PREFIX anastasis-reducer -a \ | ||
293 | "$(jq -n ' | ||
294 | {"expiration": { "t_ms" : $MSEC } }' \ | ||
295 | --argjson MSEC $MILLIS | ||
296 | )" \ | ||
297 | update_expiration $TFILE $UFILE | ||
298 | |||
299 | STATE=`jq -r -e .backup_state < $UFILE` | ||
300 | if test "$STATE" != "SECRET_EDITING" | ||
301 | then | ||
302 | jq -e . $UFILE | ||
303 | exit_fail "Expected new state to be 'SECRET_EDITING', got '$STATE'" | ||
304 | fi | ||
305 | |||
306 | FEES=`jq -r -e '.upload_fees[0].fee' < $UFILE` | ||
307 | # 4x 4.99 for annual fees, plus 4x0.01 for truth uploads | ||
308 | if test "$FEES" != "TESTKUDOS:20" | ||
309 | then | ||
310 | jq -e . $TFILE | ||
311 | exit_fail "Expected upload fees to be 'TESTKUDOS:20', got '$FEES'" | ||
312 | fi | ||
313 | |||
314 | |||
315 | echo " DONE" | ||
316 | echo -en $COLOR$BOLD"Test advance to payment ..."$NORM$NOCOLOR | ||
317 | |||
318 | $PREFIX anastasis-reducer next $UFILE $TFILE | ||
319 | |||
320 | STATE=`jq -r -e .backup_state < $TFILE` | ||
321 | if test "$STATE" != "TRUTHS_PAYING" | ||
322 | then | ||
323 | jq -e . $TFILE | ||
324 | exit_fail "Expected new state to be 'TRUTHS_PAYING', got '$STATE'" | ||
325 | fi | ||
326 | |||
327 | TMETHOD=`jq -r -e '.policies[0].methods[0].truth.type' < $TFILE` | ||
328 | if test $TMETHOD != "question" | ||
329 | then | ||
330 | exit_fail "Expected method to be >='question', got $TMETHOD" | ||
331 | fi | ||
332 | |||
333 | echo " OK" | ||
334 | #Pay | ||
335 | |||
336 | echo -en $COLOR$BOLD"Withdrawing amount to wallet ..."$NORM$NOCOLOR | ||
337 | |||
338 | rm $WALLET_DB | ||
339 | taler-wallet-cli --no-throttle --wallet-db=$WALLET_DB api 'withdrawTestBalance' \ | ||
340 | "$(jq -n ' | ||
341 | { | ||
342 | amount: "TESTKUDOS:40", | ||
343 | bankBaseUrl: $BANK_URL, | ||
344 | exchangeBaseUrl: $EXCHANGE_URL | ||
345 | }' \ | ||
346 | --arg BANK_URL "$BANK_URL" \ | ||
347 | --arg EXCHANGE_URL "$EXCHANGE_URL" | ||
348 | )" 2>wallet.err >wallet.log | ||
349 | taler-wallet-cli --wallet-db=$WALLET_DB run-until-done 2>wallet.err >wallet.log | ||
350 | |||
351 | echo " OK" | ||
352 | |||
353 | echo -en $COLOR$BOLD"Making payments for truth uploads ... "$NORM$NOCOLOR | ||
354 | OBJECT_SIZE=`jq -r -e '.payments | length' < $TFILE` | ||
355 | for ((INDEX=0; INDEX < $OBJECT_SIZE; INDEX++)) | ||
356 | do | ||
357 | PAY_URI=`jq --argjson INDEX $INDEX -r -e '.payments[$INDEX]' < $TFILE` | ||
358 | # run wallet CLI | ||
359 | echo -n "$INDEX" | ||
360 | taler-wallet-cli --wallet-db=$WALLET_DB handle-uri $PAY_URI -y 2>wallet.err >wallet.log | ||
361 | echo -n "," | ||
362 | done | ||
363 | echo " OK" | ||
364 | echo -e $COLOR$BOLD"Running wallet run-pending..."$NORM$NOCOLOR | ||
365 | taler-wallet-cli --wallet-db=$WALLET_DB run-pending 2>wallet.err >wallet.log | ||
366 | echo -e $COLOR$BOLD"Payments done"$NORM$NOCOLOR | ||
367 | |||
368 | |||
369 | echo -en $COLOR$BOLD"Try to upload again ..."$NORM$NOCOLOR | ||
370 | $PREFIX anastasis-reducer pay $TFILE $UFILE | ||
371 | mv $UFILE $TFILE | ||
372 | echo " OK" | ||
373 | |||
374 | |||
375 | STATE=`jq -r -e .backup_state < $TFILE` | ||
376 | if test "$STATE" != "POLICIES_PAYING" | ||
377 | then | ||
378 | exit_fail "Expected new state to be 'POLICIES_PAYING', got '$STATE'" | ||
379 | fi | ||
380 | |||
381 | export TFILE | ||
382 | export UFILE | ||
383 | |||
384 | echo -en $COLOR$BOLD"Making payments for policy uploads ... "$NORM$NOCOLOR | ||
385 | OBJECT_SIZE=`jq -r -e '.policy_payment_requests | length' < $TFILE` | ||
386 | for ((INDEX=0; INDEX < $OBJECT_SIZE; INDEX++)) | ||
387 | do | ||
388 | PAY_URI=`jq --argjson INDEX $INDEX -r -e '.policy_payment_requests[$INDEX].payto' < $TFILE` | ||
389 | # run wallet CLI | ||
390 | export PAY_URI | ||
391 | echo -n "$INDEX" | ||
392 | taler-wallet-cli --wallet-db=$WALLET_DB handle-uri $PAY_URI -y 2>wallet.err >wallet.log | ||
393 | echo -n "," | ||
394 | done | ||
395 | echo " OK" | ||
396 | echo -e $COLOR$BOLD"Running wallet run-pending..."$NORM$NOCOLOR | ||
397 | taler-wallet-cli --wallet-db=$WALLET_DB run-pending 2>wallet.err >wallet.log | ||
398 | echo -e $COLOR$BOLD"Payments done"$NORM$NOCOLOR | ||
399 | |||
400 | echo -en $COLOR$BOLD"Try to upload again ..."$NORM$NOCOLOR | ||
401 | $PREFIX anastasis-reducer pay $TFILE $UFILE | ||
402 | |||
403 | echo " OK" | ||
404 | |||
405 | echo -n "Final checks ..." | ||
406 | |||
407 | STATE=`jq -r -e .backup_state < $UFILE` | ||
408 | if test "$STATE" != "BACKUP_FINISHED" | ||
409 | then | ||
410 | exit_fail "Expected new state to be BACKUP_FINISHED, got $STATE" | ||
411 | fi | ||
412 | |||
413 | jq -r -e .core_secret < $UFILE > /dev/null && exit_fail "'core_secret' was not cleared upon success" | ||
414 | |||
415 | echo " OK" | ||
416 | |||
417 | exit 0 | ||