aboutsummaryrefslogtreecommitdiff
path: root/src/cli/test_iban.sh
diff options
context:
space:
mode:
Diffstat (limited to 'src/cli/test_iban.sh')
-rwxr-xr-xsrc/cli/test_iban.sh261
1 files changed, 246 insertions, 15 deletions
diff --git a/src/cli/test_iban.sh b/src/cli/test_iban.sh
index 95adbd8..e364280 100755
--- a/src/cli/test_iban.sh
+++ b/src/cli/test_iban.sh
@@ -21,24 +21,23 @@ function cleanup()
21 do 21 do
22 kill $n 2> /dev/null || true 22 kill $n 2> /dev/null || true
23 done 23 done
24 rm -rf $CONF $R1FILE $R2FILE $B1FILE $B2FILE
24 wait 25 wait
25} 26}
26 27
27# Install cleanup handler (except for kill -9)
28trap cleanup EXIT
29 28
30# $1=ebics username, $2=ebics partner name, $3=person name, $4=sandbox bank account name, $5=iban 29# $1=ebics username, $2=ebics partner name, $3=person name, $4=sandbox bank account name, $5=iban
31function prepare_sandbox_account() { 30function prepare_sandbox_account() {
32 31
33 echo Activating ebics subscriber $1 at the sandbox 32 echo -n "Activating ebics subscriber $1 at the sandbox ..."
34 libeufin-cli \ 33 libeufin-cli \
35 sandbox --sandbox-url=$SANDBOX_URL \ 34 sandbox --sandbox-url=$SANDBOX_URL \
36 ebicssubscriber create \ 35 ebicssubscriber create \
37 --host-id=ebicstesthost \ 36 --host-id=ebicstesthost \
38 --partner-id=$2 \ 37 --partner-id=$2 \
39 --user-id=$1 38 --user-id=$1
40 39 echo " OK"
41 echo "Giving a bank account ($4) to $1" 40 echo -n "Giving a bank account ($4) to $1 ..."
42 libeufin-cli \ 41 libeufin-cli \
43 sandbox --sandbox-url=$SANDBOX_URL \ 42 sandbox --sandbox-url=$SANDBOX_URL \
44 ebicsbankaccount create \ 43 ebicsbankaccount create \
@@ -50,10 +49,28 @@ function prepare_sandbox_account() {
50 --ebics-host-id=ebicstesthost \ 49 --ebics-host-id=ebicstesthost \
51 --ebics-partner-id=$2 \ 50 --ebics-partner-id=$2 \
52 --currency=$CURRENCY 51 --currency=$CURRENCY
52 echo " OK"
53}
53 54
55# Configuration file will be edited, so we create one
56# from the template.
57CONF=`mktemp test_free_reducerXXXXXX.conf`
58cp test_free_reducer.conf $CONF
54 59
60B1FILE=`mktemp test_reducer_stateB1XXXXXX`
61B2FILE=`mktemp test_reducer_stateB2XXXXXX`
62R1FILE=`mktemp test_reducer_stateR1XXXXXX`
63R2FILE=`mktemp test_reducer_stateR2XXXXXX`
55 64
56} 65export CONF
66export B2FILE
67export B1FILE
68export R2FILE
69export R1FILE
70
71
72# Install cleanup handler (except for kill -9)
73trap cleanup EXIT
57 74
58# Script's guidelines: 75# Script's guidelines:
59 76
@@ -63,7 +80,6 @@ function prepare_sandbox_account() {
63# or an sqlite file created via "mktemp /tmp/test-XXXXXX" 80# or an sqlite file created via "mktemp /tmp/test-XXXXXX"
64# or something like that 81# or something like that
65#* exits with 77 if libeufin is not properly installed/available 82#* exits with 77 if libeufin is not properly installed/available
66#* exits with 77 if Postgres with 'anastasischeck' is not properly
67# installed/available 83# installed/available
68#* starts Nexus (in background) 84#* starts Nexus (in background)
69#* starts sandbox (in background) 85#* starts sandbox (in background)
@@ -101,42 +117,257 @@ if ! libeufin-sandbox --version &> /dev/null; then
101 exit_skip "libeufin-sandbox not found" 117 exit_skip "libeufin-sandbox not found"
102fi 118fi
103 119
104if ! psql -d anastasischeck -c "\q" &> /dev/null; then 120
105 exit_skip "Postgresql database 'anastasischeck' not reachable" 121# Check we can actually run
106fi 122echo -n "Testing for jq"
123jq -h > /dev/null || exit_skip "jq required"
124echo " FOUND"
125echo -n "Testing for anastasis-reducer ..."
126anastasis-reducer -h > /dev/null || exit_skip "anastasis-reducer required"
127echo " FOUND"
107 128
108export LIBEUFIN_NEXUS_DB_CONNECTION="jdbc:sqlite:$(mktemp -u /tmp/nexus-db-XXXXXX.sqlite)" 129export LIBEUFIN_NEXUS_DB_CONNECTION="jdbc:sqlite:$(mktemp -u /tmp/nexus-db-XXXXXX.sqlite)"
109export LIBEUFIN_SANDBOX_DB_CONNECTION="jdbc:sqlite:$(mktemp -u /tmp/sandbox-db-XXXXXX.sqlite)" 130export LIBEUFIN_SANDBOX_DB_CONNECTION="jdbc:sqlite:$(mktemp -u /tmp/sandbox-db-XXXXXX.sqlite)"
110NEXUS_URL="http://localhost:5001/" 131NEXUS_URL="http://localhost:5001/"
111SANDBOX_URL="http://localhost:5000/" 132SANDBOX_URL="http://localhost:5000/"
112 133
113echo "Starting Nexus .." 134echo -n "Starting Nexus ..."
114libeufin-nexus serve &> nexus.log & 135libeufin-nexus serve &> nexus.log &
115nexus_pid=$! 136nexus_pid=$!
116if ! curl -s --retry 5 --retry-connrefused $NEXUS_URL > /dev/null; then 137if ! curl -s --retry 5 --retry-connrefused $NEXUS_URL > /dev/null; then
117 exit_skip "Could not launch Nexus" 138 exit_skip "Could not launch Nexus"
118fi 139fi
119echo "Nexus started." 140echo "OK"
120 141
121echo "Starting Sandbox .." 142echo -n "Starting Sandbox ..."
122libeufin-sandbox serve &> sandbox.log & 143libeufin-sandbox serve &> sandbox.log &
123sandbox_pid=$! 144sandbox_pid=$!
124if ! curl -s --retry 5 --retry-connrefused $SANDBOX_URL > /dev/null; then 145if ! curl -s --retry 5 --retry-connrefused $SANDBOX_URL > /dev/null; then
125 exit_skip "Could not launch Sandbox" 146 exit_skip "Could not launch Sandbox"
126fi 147fi
127echo "Sandbox started." 148echo " OK"
128 149
129CURRENCY="TESTKUDOS" 150CURRENCY="TESTKUDOS"
130IBAN1="AA3314655813489414469157" 151IBAN1="AA3314655813489414469157"
131IBAN2="BB3314655813489414469157" 152IBAN2="BB3314655813489414469157"
153export IBAN1
154export IBAN2
132 155
133echo Making a ebics host at the sandbox 156echo -n "Making an ebics host at the sandbox "
134libeufin-cli \ 157libeufin-cli \
135 sandbox --sandbox-url=$SANDBOX_URL \ 158 sandbox --sandbox-url=$SANDBOX_URL \
136 ebicshost create \ 159 ebicshost create \
137 --host-id=ebicstesthost 160 --host-id=ebicstesthost
161echo " OK"
138 162
139prepare_sandbox_account \ 163prepare_sandbox_account \
140 ebicsuser01 ebicspartner01 Person01 sandbox-account-01 $IBAN1 164 ebicsuser01 ebicspartner01 Person01 sandbox-account-01 $IBAN1
141prepare_sandbox_account \ 165prepare_sandbox_account \
142 ebicsuser02 ebicspartner02 Person02 sandbox-account-02 $IBAN2 166 ebicsuser02 ebicspartner02 Person02 sandbox-account-02 $IBAN2
167
168
169echo -n "Initialize Anastasis database ..."
170# Name of the Postgres database we will use for the script.
171# Will be dropped, do NOT use anything that might be used
172# elsewhere
173
174TARGET_DB=`anastasis-config -c $CONF -s stasis-postgres -o CONFIG | sed -e "s/^postgres:\/\/\///"`
175
176dropdb $TARGET_DB >/dev/null 2>/dev/null || true
177createdb $TARGET_DB || exit_skip "Could not create database $TARGET_DB"
178anastasis-dbinit -c $CONF 2> anastasis-dbinit.log
179
180echo " OK"
181
182echo -n "Configuring Anastasis IBAN account ..."
183anastasis-config -c $CONF \
184 -s authorization-iban \
185 -o CREDIT_IBAN \
186 -V ${IBAN1}
187# FIXME-MS: We need the *facade* URL and (likely) the
188# Facade authentication data here, not the NEXUS_URL!
189anastasis-config -c $CONF \
190 -s authorization-iban \
191 -o WIRE_GATEWAY_URL \
192 -V ${NEXUS_URL}
193anastasis-config -c $CONF \
194 -s authorization-iban \
195 -o WIRE_GATEWAY_AUTH_METHOD \
196 -V "external"
197echo " OK"
198
199echo -n "Launching Anastasis service ..."
200PREFIX="" #valgrind
201$PREFIX anastasis-httpd -c $CONF 2> anastasis-httpd_1.log &
202echo " OK"
203
204echo -n "Waiting for Anastasis service ..."
205# Wait for Anastasis service to be available
206for n in `seq 1 50`
207do
208 echo -n "."
209 sleep 0.1
210 OK=0
211 # anastasis_01
212 wget --tries=1 --timeout=1 http://localhost:8086/ -o /dev/null -O /dev/null >/dev/null || continue
213 OK=1
214 break
215done
216if [ 1 != $OK ]
217then
218 exit_skip "Failed to launch Anastasis service"
219fi
220echo "OK"
221
222
223
224echo -n "Running backup logic ...,"
225anastasis-reducer -b > $B1FILE
226echo -n "."
227anastasis-reducer -a \
228 '{"continent": "Testcontinent"}' \
229 select_continent < $B1FILE > $B2FILE
230echo -n "."
231anastasis-reducer -a \
232 '{"country_code": "xx",
233 "currencies":["TESTKUDOS"]}' \
234 select_country < $B2FILE > $B1FILE 2>> test_reducer.err
235echo -n "."
236
237anastasis-reducer -a \
238 '{"identity_attributes": {
239 "full_name": "Max Musterman",
240 "sq_number": "4",
241 "birthdate": "2000-01-01"}}' \
242 enter_user_attributes < $B1FILE > $B2FILE 2>> test_reducer.err
243echo -n ","
244
245BASEIBAN=`echo $IBAN2 | gnunet-base32`
246anastasis-reducer -a \
247 "$(jq -n '{ authentication_method: {
248 type: "iban",
249 instructions: "Send me your money!",
250 challenge: $CHALLENGE
251 } }' \
252 --arg CHALLENGE "$BASEIBAN"
253 )" \
254 add_authentication < $B2FILE > $B1FILE 2>> test_reducer.err
255echo -n "."
256# Finished adding authentication methods
257anastasis-reducer \
258 next < $B1FILE > $B2FILE 2>> test_reducer.err
259
260echo -n ","
261# Finished policy review
262anastasis-reducer \
263 next < $B2FILE > $B1FILE 2>> test_reducer.err
264echo -n "."
265
266# Note: 'secret' must here be a Crockford base32-encoded value
267anastasis-reducer -a \
268 '{"secret": { "value" : "VERYHARDT0GVESSSECRET", "mime" : "text/plain" }}' \
269 enter_secret < $B1FILE > $B2FILE 2>> test_reducer.err
270mv $B2FILE $B1FILE
271anastasis-reducer next < $B1FILE > $B2FILE 2>> test_reducer.err
272echo " OK"
273
274echo -n "Final backup checks ..."
275STATE=`jq -r -e .backup_state < $B2FILE`
276if test "$STATE" != "BACKUP_FINISHED"
277then
278 exit_fail "Expected new state to be 'BACKUP_FINISHED', got '$STATE'"
279fi
280jq -r -e .core_secret < $B2FILE > /dev/null && exit_fail "'core_secret' was not cleared upon success"
281echo " OK"
282
283
284
285echo -n "Running recovery basic logic ..."
286anastasis-reducer -r > $R1FILE
287anastasis-reducer -a \
288 '{"continent": "Testcontinent"}' \
289 select_continent < $R1FILE > $R2FILE
290anastasis-reducer -a \
291 '{"country_code": "xx",
292 "currencies":["TESTKUDOS"]}' \
293 select_country < $R2FILE > $R1FILE 2>> test_reducer.err
294anastasis-reducer -a '{"identity_attributes": { "full_name": "Max Musterman", "sq_number": "4", "birthdate": "2000-01-01" }}' enter_user_attributes < $R1FILE > $R2FILE 2>> test_reducer.err
295
296
297STATE=`jq -r -e .recovery_state < $R2FILE`
298if test "$STATE" != "SECRET_SELECTING"
299then
300 exit_fail "Expected new state to be 'SECRET_SELECTING', got '$STATE'"
301fi
302echo " OK"
303
304echo -n "Selecting default secret"
305mv $R2FILE $R1FILE
306anastasis-reducer next < $R1FILE > $R2FILE 2>> test_reducer.err
307
308STATE=`jq -r -e .recovery_state < $R2FILE`
309if test "$STATE" != "CHALLENGE_SELECTING"
310then
311 exit_fail "Expected new state to be 'CHALLENGE_SELECTING', got '$STATE'"
312fi
313echo " OK"
314
315echo -n "Running challenge logic ..."
316
317NAME_UUID=`jq -r -e .recovery_information.challenges[0].uuid < $R2FILE`
318anastasis-reducer -a \
319 "$(jq -n '
320 {
321 uuid: $UUID
322 }' \
323 --arg UUID "$NAME_UUID"
324 )" \
325 select_challenge < $R2FILE > $R1FILE 2>> test_reducer.err
326
327# FIXME: check $IBAN1 is properly in $R1FILE
328# FIXME: check TESTKUDOS:5 is properly in $R1FILE
329# FIXME: extract wire transfer subject from $R1FILE
330
331# FIXME-MS: must do wire transfer here!
332
333# bash
334
335echo "TEST INCOMPLETE --- BAILING for now"
336
337exit 77
338
339# Check for inbound wire transfer (fails with 'Failed to load bank access configuration data')
340anastasis-helper-authorization-iban -c $CONF -t
341
342# Now we should get the secret...
343anastasis-reducer poll < $R1FILE > $R2FILE
344
345echo " OK"
346
347echo -n "Checking recovered secret ..."
348# finally: check here that we recovered the secret...
349
350STATE=`jq -r -e .recovery_state < $R2FILE`
351if test "$STATE" != "RECOVERY_FINISHED"
352then
353 jq -e . $R2FILE
354 exit_fail "Expected new state to be 'RECOVERY_FINISHED', got '$STATE'"
355fi
356
357SECRET=`jq -r -e .core_secret.value < $R2FILE`
358if test "$SECRET" != "VERYHARDT0GVESSSECRET"
359then
360 jq -e . $R2FILE
361 exit_fail "Expected recovered secret to be 'VERYHARDT0GVESSSECRET', got '$SECRET'"
362fi
363
364MIME=`jq -r -e .core_secret.mime < $R2FILE`
365if test "$MIME" != "text/plain"
366then
367 jq -e . $R2FILE
368 exit_fail "Expected recovered mime to be 'text/plain', got '$MIME'"
369fi
370
371echo " OK"
372
373exit 0