summaryrefslogtreecommitdiff
path: root/src/testing/test_prepare.sh
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/test_prepare.sh')
-rwxr-xr-xsrc/testing/test_prepare.sh235
1 files changed, 227 insertions, 8 deletions
diff --git a/src/testing/test_prepare.sh b/src/testing/test_prepare.sh
index 253cb8f..5faee2e 100755
--- a/src/testing/test_prepare.sh
+++ b/src/testing/test_prepare.sh
@@ -28,19 +28,104 @@ function cleanup()
wait
}
+
+# $1=ebics username, $2=ebics partner name, $3=person name, $4=sandbox bank account name, $5=iban
+function prepare_sandbox_account() {
+ echo -n "Activating ebics subscriber $1 at the sandbox ..."
+ libeufin-cli \
+ sandbox --sandbox-url=$SANDBOX_URL \
+ ebicssubscriber create \
+ --host-id=$EBICS_HOST \
+ --partner-id=$2 \
+ --user-id=$1
+ echo " OK"
+ echo -n "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=$EBICS_HOST \
+ --ebics-partner-id=$2 \
+ --currency=EUR
+ echo " OK"
+}
+
+
+# Transfer only from debit to credit/anastasis account.
+# This function moves funds directly at the Sandbox. No need
+# to pass through the Nexus+Ebics layer to issue the payment
+# $1 = amount ($CURRENCY:X.Y), $2 = subject.
+function wire_transfer_to_anastasis() {
+ libeufin-sandbox make-transaction \
+ --debit-account=sandbox-account-debit \
+ --credit-account=sandbox-account-credit "$1" "$2"
+ # Sync nexus with sandbox
+ export LIBEUFIN_NEXUS_USERNAME=$CREDIT_USERNAME
+ export LIBEUFIN_NEXUS_PASSWORD=$CREDIT_PASSWORD
+ libeufin-cli accounts fetch-transactions nexus-bankaccount-credit > /dev/null
+ anastasis-helper-authorization-iban -c $CONF_4 -t
+}
+
+# $1 = facade base URL. Merely a debug utility.
+function see_anastasis_transactions_via_facade() {
+ curl -s --user "$CREDIT_USERNAME:$CREDIT_PASSWORD" "${1}history/incoming?delta=5" | jq
+}
+
+# $1 = ebics user id, $2 = ebics partner, $3 = bank connection name
+# $4 = bank account name local to Nexus, $5 = bank account name as known
+# by Sandbox
+function prepare_nexus_account() {
+ echo -n "Making bank connection $3 ..."
+ libeufin-cli connections new-ebics-connection \
+ --ebics-url="${SANDBOX_URL}ebicsweb" \
+ --host-id=$EBICS_HOST \
+ --partner-id=$2 \
+ --ebics-user-id=$1 \
+ $3 > /dev/null
+ echo " OK"
+ echo -n "Connecting $3 ..."
+ libeufin-cli connections connect $3 > /dev/null
+ echo " OK"
+ echo -n "Importing Sandbox bank account ($5) to Nexus ($4) ..."
+ libeufin-cli connections download-bank-accounts $3 > /dev/null
+ libeufin-cli connections import-bank-account \
+ --offered-account-id=$5 --nexus-bank-account-id=$4 $3 > /dev/null
+ echo " OK"
+}
+
+# $1 = facade name, $2 = bank connection to use, $3 = bank account name
+# local to Nexus
+function prepare_anastasis_facade() {
+ echo -n "Creating facade ..."
+ libeufin-cli facades new-anastasis-facade \
+ --currency=EUR \
+ --facade-name=$1 \
+ $2 $3
+ echo " OK"
+ # No need to setup facade permissions, as the anastasis client
+ # is superuser at Nexus.
+}
+
+
+
if test "${1:-}" != "free" -a "${1:-}" != "fees"
then
echo "Launch script with either 'free' or 'fees' argument to launch providers with/without fees."
exit 1
fi
-CONF_1="test_anastasis_reducer_1.conf"
-CONF_2="test_anastasis_reducer_2.conf"
-CONF_3="test_anastasis_reducer_3.conf"
-CONF_4="test_anastasis_reducer_4.conf"
+export CONF_1="test_anastasis_reducer_1.conf"
+export CONF_2="test_anastasis_reducer_2.conf"
+export CONF_3="test_anastasis_reducer_3.conf"
if test $1 = 'free'
then
- CONF_4="test_anastasis_reducer_4_free.conf"
+ export CONF_4="test_anastasis_reducer_4_free.conf"
+else
+ export CONF_4="test_anastasis_reducer_4.conf"
fi
# Exchange configuration file will be edited, so we create one
@@ -54,6 +139,7 @@ B1FILE=`mktemp test_reducer_stateB1XXXXXX`
B2FILE=`mktemp test_reducer_stateB2XXXXXX`
R1FILE=`mktemp test_reducer_stateR1XXXXXX`
R2FILE=`mktemp test_reducer_stateR2XXXXXX`
+IBAN_ACTIVE='false'
# Install cleanup handler (except for kill -9)
trap cleanup EXIT
@@ -75,6 +161,132 @@ then
echo " FOUND"
fi
+echo -n "Testing for libeufin-cli"
+if libeufin-cli --version > /dev/null
+then
+ echo " FOUND"
+ IBAN_CREDIT=`anastasis-config -c $CONF_4 -s authorization-iban -o CREDIT_IBAN`
+ CREDIT_BUSINESS_NAME=`anastasis-config -c $CONF_4 -s authorization-iban -o BUSINESS_NAME`
+ echo -n "Setting up Nexus ..."
+ 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)"
+ export NEXUS_URL="http://localhost:5001/"
+ export SANDBOX_URL="http://localhost:5000/"
+ 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 -n "."
+ 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
+ export EBICS_HOST="ebicstesthost"
+ export IBAN_DEBIT="FR1420041010050500013M02606"
+ echo "OK"
+
+ echo -n "Preparing Sandbox ..."
+ libeufin-cli \
+ sandbox --sandbox-url=$SANDBOX_URL \
+ ebicshost create \
+ --host-id=$EBICS_HOST
+ echo " OK"
+
+ export PERSON_CREDIT_NAME="Person Credit"
+ echo -n "Preparing accounts ..."
+ # note: Ebisc schema doesn't allow dashed names.
+ prepare_sandbox_account \
+ ebicsuserCredit \
+ ebicspartnerCredit \
+ "${PERSON_CREDIT_NAME}" \
+ sandbox-account-credit \
+ $IBAN_CREDIT
+ prepare_sandbox_account \
+ ebicsuserDebit \
+ ebicspartnerDebit \
+ "Person Debit" \
+ sandbox-account-debit \
+ $IBAN_DEBIT
+ echo "Sandbox preparation done"
+
+ echo -n "Preparing Nexus ..."
+ export LIBEUFIN_NEXUS_URL=$NEXUS_URL
+ # Make debit user, will buy Anastasis services.
+ export DEBIT_USERNAME=anastasis-debit-user
+ export DEBIT_PASSWORD=anastasis-debit-password
+ libeufin-nexus superuser $DEBIT_USERNAME --password=$DEBIT_PASSWORD
+ echo " OK"
+ export LIBEUFIN_NEXUS_USERNAME=$DEBIT_USERNAME
+ export LIBEUFIN_NEXUS_PASSWORD=$DEBIT_PASSWORD
+
+ prepare_nexus_account \
+ ebicsuserDebit \
+ ebicspartnerDebit \
+ bankconnection-debit \
+ nexus-bankaccount-debit \
+ sandbox-account-debit
+
+ # Make credit user, will be Anastasis client.
+ export CREDIT_USERNAME=anastasis-credit-user
+ export CREDIT_PASSWORD=anastasis-credit-password
+ echo -n "Create credit user (for anastasis) at Nexus ..."
+ libeufin-nexus superuser $CREDIT_USERNAME --password=$CREDIT_PASSWORD
+ echo " OK"
+ export LIBEUFIN_NEXUS_USERNAME=$CREDIT_USERNAME
+ export LIBEUFIN_NEXUS_PASSWORD=$CREDIT_PASSWORD
+
+ prepare_nexus_account \
+ ebicsuserCredit \
+ ebicspartnerCredit \
+ bankconnection-credit \
+ nexus-bankaccount-credit \
+ sandbox-account-credit
+
+ echo -n "Create facade ..."
+ libeufin-cli facades new-anastasis-facade \
+ --currency="EUR" \
+ --facade-name=facade-credit \
+ bankconnection-credit nexus-bankaccount-credit
+ echo " OK"
+ export FACADE_URL=$(libeufin-cli facades list | jq .facades[0].baseUrl | tr -d \")
+
+ ## Reach facade with: $FACADE_URL + $CREDIT_USERNAME + $CREDIT_PASSWORD
+
+ echo -n "Configuring Anastasis IBAN account ..."
+ anastasis-config -c $CONF_4 \
+ -s authorization-iban \
+ -o CREDIT_IBAN \
+ -V "${IBAN_CREDIT}"
+ anastasis-config -c $CONF_4 \
+ -s authorization-iban \
+ -o BUSINESS_NAME \
+ -V "${PERSON_CREDIT_NAME}"
+ anastasis-config -c $CONF_4 \
+ -s authorization-iban \
+ -o WIRE_GATEWAY_URL \
+ -V "${FACADE_URL}"
+ anastasis-config -c $CONF_4 \
+ -s authorization-iban \
+ -o WIRE_GATEWAY_AUTH_METHOD \
+ -V "basic"
+ anastasis-config -c $CONF_4 \
+ -s authorization-iban \
+ -o USERNAME \
+ -V "${LIBEUFIN_NEXUS_USERNAME}"
+ anastasis-config -c $CONF_4 \
+ -s authorization-iban \
+ -o PASSWORD \
+ -V "${LIBEUFIN_NEXUS_PASSWORD}"
+ echo " OK"
+ IBAN_ACTIVE='true'
+else
+ echo " NOT FOUND (IBAN authentication not supported)"
+ anastasis-config -c $CONF_4 -s authorization-iban -o ENABLED -V no
+fi
+
+
echo -n "Testing for anastasis-httpd"
anastasis-httpd -h >/dev/null </dev/null || exit_skip " MISSING"
echo " FOUND"
@@ -308,12 +520,19 @@ then
fi
-echo "You can now run anastasis-gtk in the shell we are starting now."
-echo "Exit the shell when done to terminate the test environment!"
+export -f wire_transfer_to_anastasis
+echo "You can now run anastasis-gtk in TESTLAND."
+echo " "
+echo "We will now start a sub-shell. Please note:"
+echo '- to terminate the test environment by leaving the sub-shell use: exit'
+if test $IBAN_ACTIVE = 'true'
+then
+ echo '- for IBAN authentication use: wire_transfer_to_anastasis "$AMOUNT" "$SUBJECT"'
+fi
if test $1 = 'fees'
then
- echo "Use 'taler-wallet-cli --wallet-db=\$WALLET_DB handle-uri \$PAY_URI -y' to pay"
+ echo '- to pay, use: taler-wallet-cli --wallet-db=$WALLET_DB handle-uri $PAY_URI -y'
export WALLET_DB
fi