summaryrefslogtreecommitdiff
path: root/src/cli/test_iban.sh
blob: 95adbd8db213bc4011f741286d9b321e15b588c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/bash

set -eu

# Exit, with status code "skip" (no 'real' failure)
function exit_skip() {
    echo " SKIP: $1"
    exit 77
}

# Exit, with error message (hard failure)
function exit_fail() {
    echo " FAIL: $1"
    exit 1
}

# Cleanup to run whenever we exit
function cleanup()
{
    for n in `jobs -p`
    do
        kill $n 2> /dev/null || true
    done
    wait
}

# Install cleanup handler (except for kill -9)
trap cleanup EXIT

# $1=ebics username, $2=ebics partner name, $3=person name, $4=sandbox bank account name, $5=iban
function prepare_sandbox_account() {

  echo Activating ebics subscriber $1 at the sandbox
  libeufin-cli \
    sandbox --sandbox-url=$SANDBOX_URL \
      ebicssubscriber create \
        --host-id=ebicstesthost \
        --partner-id=$2 \
        --user-id=$1
  
  echo "Giving a bank account ($4) to $1"
  libeufin-cli \
    sandbox --sandbox-url=$SANDBOX_URL \
      ebicsbankaccount create \
        --iban=$5 \
        --bic="BCMAESM1XXX"\
        --person-name=$3 \
        --account-name=$4 \
        --ebics-user-id=$1 \
        --ebics-host-id=ebicstesthost \
        --ebics-partner-id=$2 \
        --currency=$CURRENCY



}

# Script's guidelines:

#* uses 'CURRENCY=TESTKUDOS' and uses $CURRENCY for all
#  currencies in what follows ...
#* for databases, use either 'anastasischeck' for Postgres
#  or an sqlite file created via "mktemp /tmp/test-XXXXXX"
#  or something like that
#* exits with 77 if libeufin is not properly installed/available
#* exits with 77 if Postgres with 'anastasischeck' is not properly
#  installed/available
#* starts Nexus (in background)
#* starts sandbox (in background)
#  ~~~~~~~~~
#* creates two IBAN accounts
#* stores IBANs of both accounts in shell variables,
#  call them IBAN_CREDIT and IBAN_DEBIT.
#* configures an Anastasis facade for IBAN_CREDIT.
#* exports authentication credentials (URL, access token)
#  for the facade to shell variables
#  (FACADE_URL, FACADE_AUTH_TOKEN)
#* contains a command to do a wire-transfer (pick your amount)
#  from DEBIT to CREDIT (setup authentication as needed to
#  trigger the transfer)
#
#
#Make sure 'set -eu' and include some progress indicators, like:
#
#echo -n "Starting nexus ..."
## DO WORK
#echo " DONE"
#echo -n "Starting sandbox ..."
## DO WORK
#echo " DONE"

if ! libeufin-cli --version &> /dev/null; then
  exit_skip "libeufin-cli not found"
fi

if ! libeufin-nexus --version &> /dev/null; then
  exit_skip "libeufin-nexus not found"
fi

if ! libeufin-sandbox --version &> /dev/null; then
  exit_skip "libeufin-sandbox not found"
fi

if ! psql -d anastasischeck -c "\q" &> /dev/null; then
  exit_skip "Postgresql database 'anastasischeck' not reachable"
fi

export LIBEUFIN_NEXUS_DB_CONNECTION="jdbc:sqlite:$(mktemp -u /tmp/nexus-db-XXXXXX.sqlite)"
export LIBEUFIN_SANDBOX_DB_CONNECTION="jdbc:sqlite:$(mktemp -u /tmp/sandbox-db-XXXXXX.sqlite)"
NEXUS_URL="http://localhost:5001/"
SANDBOX_URL="http://localhost:5000/"

echo "Starting Nexus .."
libeufin-nexus serve &> nexus.log &
nexus_pid=$!
if ! curl -s --retry 5 --retry-connrefused $NEXUS_URL > /dev/null; then
  exit_skip "Could not launch Nexus"
fi
echo "Nexus started."

echo "Starting Sandbox .."
libeufin-sandbox serve &> sandbox.log &
sandbox_pid=$!
if ! curl -s --retry 5 --retry-connrefused $SANDBOX_URL > /dev/null; then
  exit_skip "Could not launch Sandbox"
fi
echo "Sandbox started."

CURRENCY="TESTKUDOS"
IBAN1="AA3314655813489414469157"
IBAN2="BB3314655813489414469157"

echo Making a ebics host at the sandbox
libeufin-cli \
  sandbox --sandbox-url=$SANDBOX_URL \
    ebicshost create \
      --host-id=ebicstesthost

prepare_sandbox_account \
  ebicsuser01 ebicspartner01 Person01 sandbox-account-01 $IBAN1
prepare_sandbox_account \
  ebicsuser02 ebicspartner02 Person02 sandbox-account-02 $IBAN2