aboutsummaryrefslogtreecommitdiff
path: root/src/cli/test_anastasis_reducer_enter_secret.sh
diff options
context:
space:
mode:
Diffstat (limited to 'src/cli/test_anastasis_reducer_enter_secret.sh')
-rwxr-xr-xsrc/cli/test_anastasis_reducer_enter_secret.sh417
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
3COLOR='\033[0;35m'
4NOCOLOR='\033[0m'
5BOLD="$(tput bold)"
6NORM="$(tput sgr0)"
7
8set -eu
9
10# Exit, with status code "skip" (no 'real' failure)
11function exit_skip() {
12 echo " SKIP: $1"
13 exit 77
14}
15
16# Exit, with error message (hard failure)
17function exit_fail() {
18 echo " FAIL: $1"
19 exit 1
20}
21
22# Cleanup to run whenever we exit
23function 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
33CONF_1="test_anastasis_reducer_1.conf"
34CONF_2="test_anastasis_reducer_2.conf"
35CONF_3="test_anastasis_reducer_3.conf"
36CONF_4="test_anastasis_reducer_4.conf"
37
38# Exchange configuration file will be edited, so we create one
39# from the template.
40CONF=`mktemp test_reducerXXXXXX.conf`
41cp test_reducer.conf $CONF
42
43TMP_DIR=`mktemp -d keys-tmp-XXXXXX`
44WALLET_DB=`mktemp test_reducer_walletXXXXXX.json`
45TFILE=`mktemp test_reducer_statePPXXXXXX`
46UFILE=`mktemp test_reducer_stateBFXXXXXX`
47
48# Install cleanup handler (except for kill -9)
49trap cleanup EXIT
50
51# Check we can actually run
52echo -n "Testing for jq"
53jq -h > /dev/null || exit_skip "jq required"
54echo " FOUND"
55echo -n "Testing for anastasis-reducer ..."
56anastasis-reducer -h > /dev/null || exit_skip "anastasis-reducer required"
57echo " FOUND"
58
59echo -n "Testing for taler"
60taler-exchange-httpd -h > /dev/null || exit_skip " taler-exchange required"
61taler-merchant-httpd -h > /dev/null || exit_skip " taler-merchant required"
62echo " FOUND"
63
64echo -n "Testing for taler-bank-manage"
65taler-bank-manage --help >/dev/null </dev/null || exit_skip " MISSING"
66echo " FOUND"
67echo -n "Testing for taler-wallet-cli"
68taler-wallet-cli -v >/dev/null </dev/null || exit_skip " MISSING"
69echo " FOUND"
70
71echo -n "Testing for anastasis-httpd"
72anastasis-httpd -h >/dev/null </dev/null || exit_skip " MISSING"
73echo " FOUND"
74
75echo -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
79TARGET_DB_1=`anastasis-config -c $CONF_1 -s stasis-postgres -o CONFIG | sed -e "s/^postgres:\/\/\///"`
80TARGET_DB_2=`anastasis-config -c $CONF_2 -s stasis-postgres -o CONFIG | sed -e "s/^postgres:\/\/\///"`
81TARGET_DB_3=`anastasis-config -c $CONF_3 -s stasis-postgres -o CONFIG | sed -e "s/^postgres:\/\/\///"`
82TARGET_DB_4=`anastasis-config -c $CONF_4 -s stasis-postgres -o CONFIG | sed -e "s/^postgres:\/\/\///"`
83
84dropdb $TARGET_DB_1 >/dev/null 2>/dev/null || true
85createdb $TARGET_DB_1 || exit_skip "Could not create database $TARGET_DB_1"
86anastasis-dbinit -c $CONF_1 2> anastasis-dbinit_1.log
87dropdb $TARGET_DB_2 >/dev/null 2>/dev/null || true
88createdb $TARGET_DB_2 || exit_skip "Could not create database $TARGET_DB_2"
89anastasis-dbinit -c $CONF_2 2> anastasis-dbinit_2.log
90dropdb $TARGET_DB_3 >/dev/null 2>/dev/null || true
91createdb $TARGET_DB_3 || exit_skip "Could not create database $TARGET_DB_3"
92anastasis-dbinit -c $CONF_3 2> anastasis-dbinit_3.log
93dropdb $TARGET_DB_4 >/dev/null 2>/dev/null || true
94createdb $TARGET_DB_4 || exit_skip "Could not create database $TARGET_DB_4"
95anastasis-dbinit -c $CONF_4 2> anastasis-dbinit_4.log
96
97echo " OK"
98
99echo -n "Generating Taler auditor, exchange and merchant configurations ..."
100
101DATA_DIR=`taler-config -f -c $CONF -s PATHS -o TALER_HOME`
102rm -rf $DATA_DIR
103
104# obtain key configuration data
105MASTER_PRIV_FILE=`taler-config -f -c $CONF -s EXCHANGE -o MASTER_PRIV_FILE`
106MASTER_PRIV_DIR=`dirname $MASTER_PRIV_FILE`
107mkdir -p $MASTER_PRIV_DIR
108gnunet-ecc -g1 $MASTER_PRIV_FILE > /dev/null 2> /dev/null
109MASTER_PUB=`gnunet-ecc -p $MASTER_PRIV_FILE`
110EXCHANGE_URL=`taler-config -c $CONF -s EXCHANGE -o BASE_URL`
111MERCHANT_PORT=`taler-config -c $CONF -s MERCHANT -o PORT`
112MERCHANT_URL=http://localhost:${MERCHANT_PORT}/
113BANK_PORT=`taler-config -c $CONF -s BANK -o HTTP_PORT`
114BANK_URL=http://localhost:${BANK_PORT}/
115AUDITOR_URL=http://localhost:8083/
116AUDITOR_PRIV_FILE=`taler-config -f -c $CONF -s AUDITOR -o AUDITOR_PRIV_FILE`
117AUDITOR_PRIV_DIR=`dirname $AUDITOR_PRIV_FILE`
118mkdir -p $AUDITOR_PRIV_DIR
119gnunet-ecc -g1 $AUDITOR_PRIV_FILE > /dev/null 2> /dev/null
120AUDITOR_PUB=`gnunet-ecc -p $AUDITOR_PRIV_FILE`
121
122# patch configuration
123TALER_DB=talercheck
124taler-config -c $CONF -s exchange -o MASTER_PUBLIC_KEY -V $MASTER_PUB
125taler-config -c $CONF -s merchant-exchange-default -o MASTER_KEY -V $MASTER_PUB
126taler-config -c $CONF -s exchangedb-postgres -o CONFIG -V postgres:///$TALER_DB
127taler-config -c $CONF -s auditordb-postgres -o CONFIG -V postgres:///$TALER_DB
128taler-config -c $CONF -s merchantdb-postgres -o CONFIG -V postgres:///$TALER_DB
129taler-config -c $CONF -s bank -o database -V postgres:///$TALER_DB
130taler-config -c $CONF -s exchange -o KEYDIR -V "${TMP_DIR}/keydir/"
131taler-config -c $CONF -s exchange -o REVOCATION_DIR -V "${TMP_DIR}/revdir/"
132
133echo " OK"
134
135echo -n "Setting up exchange ..."
136
137# reset database
138dropdb $TALER_DB >/dev/null 2>/dev/null || true
139createdb $TALER_DB || exit_skip "Could not create database $TALER_DB"
140taler-exchange-dbinit -c $CONF
141taler-merchant-dbinit -c $CONF
142taler-auditor-dbinit -c $CONF
143taler-auditor-exchange -c $CONF -m $MASTER_PUB -u $EXCHANGE_URL
144
145echo " OK"
146
147# Launch services
148echo -n "Launching taler services ..."
149taler-bank-manage-testing $CONF postgres:///$TALER_DB serve > taler-bank.log 2> taler-bank.err &
150taler-exchange-secmod-eddsa -c $CONF 2> taler-exchange-secmod-eddsa.log &
151taler-exchange-secmod-rsa -c $CONF 2> taler-exchange-secmod-rsa.log &
152taler-exchange-httpd -c $CONF 2> taler-exchange-httpd.log &
153taler-merchant-httpd -c $CONF -L INFO 2> taler-merchant-httpd.log &
154taler-exchange-wirewatch -c $CONF 2> taler-exchange-wirewatch.log &
155taler-auditor-httpd -L INFO -c $CONF 2> taler-auditor-httpd.log &
156
157echo " OK"
158
159echo -n "Launching anastasis services ..."
160PREFIX="" #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)
167for n in `seq 1 50`
168do
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
176done
177
178if [ 1 != $OK ]
179then
180 exit_skip "Failed to launch services (bank)"
181fi
182
183# Wait for all other taler services to be available
184for n in `seq 1 50`
185do
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
197done
198
199if [ 1 != $OK ]
200then
201 exit_skip "Failed to launch taler services"
202fi
203
204echo "OK"
205
206echo -n "Setting up keys ..."
207taler-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
215echo -n "."
216
217for n in `seq 1 3`
218do
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
224done
225
226if [ 1 != $OK ]
227then
228 exit_skip "Failed to setup keys"
229fi
230
231echo " OK"
232
233echo -n "Setting up auditor signatures ..."
234taler-auditor-offline -c $CONF \
235 download sign upload &> taler-auditor-offline.log
236echo " OK"
237
238echo -n "Waiting for anastasis services ..."
239
240# Wait for anastasis services to be available
241for n in `seq 1 50`
242do
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
256done
257
258if [ 1 != $OK ]
259then
260 exit_skip "Failed to launch anastasis services"
261fi
262echo "OK"
263
264echo -n "Configuring merchant instance ..."
265# Setup merchant
266
267curl -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
270echo " DONE"
271
272echo -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
278STATE=`jq -r -e .backup_state < $TFILE`
279if test "$STATE" != "SECRET_EDITING"
280then
281 jq -e . $TFILE
282 exit_fail "Expected new state to be 'SECRET_EDITING', got '$STATE'"
283fi
284
285echo " DONE"
286echo -en $COLOR$BOLD"Test expiration change ..."$NORM$NOCOLOR
287
288MILLIS=`date '+%s'`000
289# Use 156 days into the future to get 1 year
290MILLIS=`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
299STATE=`jq -r -e .backup_state < $UFILE`
300if test "$STATE" != "SECRET_EDITING"
301then
302 jq -e . $UFILE
303 exit_fail "Expected new state to be 'SECRET_EDITING', got '$STATE'"
304fi
305
306FEES=`jq -r -e '.upload_fees[0].fee' < $UFILE`
307# 4x 4.99 for annual fees, plus 4x0.01 for truth uploads
308if test "$FEES" != "TESTKUDOS:20"
309then
310 jq -e . $TFILE
311 exit_fail "Expected upload fees to be 'TESTKUDOS:20', got '$FEES'"
312fi
313
314
315echo " DONE"
316echo -en $COLOR$BOLD"Test advance to payment ..."$NORM$NOCOLOR
317
318$PREFIX anastasis-reducer next $UFILE $TFILE
319
320STATE=`jq -r -e .backup_state < $TFILE`
321if test "$STATE" != "TRUTHS_PAYING"
322then
323 jq -e . $TFILE
324 exit_fail "Expected new state to be 'TRUTHS_PAYING', got '$STATE'"
325fi
326
327TMETHOD=`jq -r -e '.policies[0].methods[0].truth.type' < $TFILE`
328if test $TMETHOD != "question"
329then
330 exit_fail "Expected method to be >='question', got $TMETHOD"
331fi
332
333echo " OK"
334#Pay
335
336echo -en $COLOR$BOLD"Withdrawing amount to wallet ..."$NORM$NOCOLOR
337
338rm $WALLET_DB
339taler-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
349taler-wallet-cli --wallet-db=$WALLET_DB run-until-done 2>wallet.err >wallet.log
350
351echo " OK"
352
353echo -en $COLOR$BOLD"Making payments for truth uploads ... "$NORM$NOCOLOR
354OBJECT_SIZE=`jq -r -e '.payments | length' < $TFILE`
355for ((INDEX=0; INDEX < $OBJECT_SIZE; INDEX++))
356do
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 ","
362done
363echo " OK"
364echo -e $COLOR$BOLD"Running wallet run-pending..."$NORM$NOCOLOR
365taler-wallet-cli --wallet-db=$WALLET_DB run-pending 2>wallet.err >wallet.log
366echo -e $COLOR$BOLD"Payments done"$NORM$NOCOLOR
367
368
369echo -en $COLOR$BOLD"Try to upload again ..."$NORM$NOCOLOR
370$PREFIX anastasis-reducer pay $TFILE $UFILE
371mv $UFILE $TFILE
372echo " OK"
373
374
375STATE=`jq -r -e .backup_state < $TFILE`
376if test "$STATE" != "POLICIES_PAYING"
377then
378 exit_fail "Expected new state to be 'POLICIES_PAYING', got '$STATE'"
379fi
380
381export TFILE
382export UFILE
383
384echo -en $COLOR$BOLD"Making payments for policy uploads ... "$NORM$NOCOLOR
385OBJECT_SIZE=`jq -r -e '.policy_payment_requests | length' < $TFILE`
386for ((INDEX=0; INDEX < $OBJECT_SIZE; INDEX++))
387do
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 ","
394done
395echo " OK"
396echo -e $COLOR$BOLD"Running wallet run-pending..."$NORM$NOCOLOR
397taler-wallet-cli --wallet-db=$WALLET_DB run-pending 2>wallet.err >wallet.log
398echo -e $COLOR$BOLD"Payments done"$NORM$NOCOLOR
399
400echo -en $COLOR$BOLD"Try to upload again ..."$NORM$NOCOLOR
401$PREFIX anastasis-reducer pay $TFILE $UFILE
402
403echo " OK"
404
405echo -n "Final checks ..."
406
407STATE=`jq -r -e .backup_state < $UFILE`
408if test "$STATE" != "BACKUP_FINISHED"
409then
410 exit_fail "Expected new state to be BACKUP_FINISHED, got $STATE"
411fi
412
413jq -r -e .core_secret < $UFILE > /dev/null && exit_fail "'core_secret' was not cleared upon success"
414
415echo " OK"
416
417exit 0