diff options
author | Christian Grothoff <christian@grothoff.org> | 2022-08-06 13:25:54 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2022-08-06 13:25:54 +0200 |
commit | c602e11a3642fe9cd59a3526fb4f99912e275092 (patch) | |
tree | ea533c922f53addc25a985541cd82c786ad336d7 /contrib | |
parent | 6834b1290fa4bd9d6331329282f72f1f67b4d1bf (diff) | |
download | exchange-c602e11a3642fe9cd59a3526fb4f99912e275092.tar.xz |
-merge eufin branch (manually)
Diffstat (limited to 'contrib')
-rwxr-xr-x | contrib/taler-bank-manage-testing | 174 | ||||
-rwxr-xr-x | contrib/taler-nexus-prepare | 233 |
2 files changed, 273 insertions, 134 deletions
diff --git a/contrib/taler-bank-manage-testing b/contrib/taler-bank-manage-testing index 4fa80b177..9be8ac9ad 100755 --- a/contrib/taler-bank-manage-testing +++ b/contrib/taler-bank-manage-testing @@ -4,24 +4,176 @@ # testing accounts before launching the bank properly. # # Takes 3 arguments: -# $1: the configuration file name +# $1: the Nexus port (Sandbox port prepends 1 to it) # $2: the database name -# $3: serve-http or serve-uwsgi +# $3: exchange base URL (used to specify the default exchange) +# $4: config file (needs patch to specify exchange's PAYTO_URI) set -eu -if [ "$#" -ne 3 ]; +if [ "$#" -ne 4 ]; then - echo "illegal number of parameters" + echo "illegal number of parameters. \ +Give: Nexus port number, SQLIte file path, exchange base URL, config file path." exit 1 fi -# Ensure starting accounts exist -taler-bank-manage -c $1 --with-db $2 django provide_accounts -taler-bank-manage -c $1 --with-db $2 django add_bank_account 42 -taler-bank-manage -c $1 --with-db $2 django add_bank_account 43 +# Must not terminate jobs here, as they are needed +# by the script _importing_ this one. Those script +# will then manage the termination. +# trap cleanup EXIT -taler-bank-manage -c $1 --with-db $2 django changepassword_unsafe Exchange x +export LIBEUFIN_SANDBOX_DB_CONNECTION="jdbc:sqlite:$2" +# Create the default demobank. +libeufin-sandbox config --currency TESTKUDOS default +export LIBEUFIN_SANDBOX_ADMIN_PASSWORD=secret +libeufin-sandbox serve --port "1$1" \ + > libeufin-sandbox-stdout.log \ + 2> libeufin-sandbox-stderr.log & +echo $! > libeufin-sandbox.pid +export LIBEUFIN_SANDBOX_URL="http://localhost:1$1/demobanks/default" +set +e +echo -n "Waiting for Sandbox.." +for n in `seq 1 50`; do + echo -n "." + sleep 1 + wget --timeout=1 \ + --tries=3 --waitretry=0 \ + -o /dev/null -O /dev/null \ + $LIBEUFIN_SANDBOX_URL + break +done +echo OK -# Now run Django for good -exec taler-bank-manage -c $1 --with-db $2 $3 +register_sandbox_account() { + export LIBEUFIN_SANDBOX_USERNAME=$1 + export LIBEUFIN_SANDBOX_PASSWORD=$2 + libeufin-cli sandbox \ + demobank \ + register --name "$3" + unset LIBEUFIN_SANDBOX_USERNAME + unset LIBEUFIN_SANDBOX_PASSWORD +} +set -e +echo -n "Register the 'fortytwo' Sandbox user.." +register_sandbox_account fortytwo x "Forty Two" +echo OK +echo -n "Register the 'fortythree' Sandbox user.." +register_sandbox_account fortythree x "Forty Three" +echo OK +echo -n "Register 'exchange' Sandbox user.." +register_sandbox_account exchange x "Exchange Company" +echo OK +echo -n "Register 'tor' Sandbox user.." +register_sandbox_account tor x "Tor Project" +echo OK +echo -n "Register 'gnunet' Sandbox user.." +register_sandbox_account gnunet x "GNUnet" +echo OK +echo -n "Register 'tutorial' Sandbox user.." +register_sandbox_account tutorial x "Tutorial" +echo OK +echo -n "Register 'survey' Sandbox user.." +register_sandbox_account survey x "Survey" +echo OK +echo -n "Specify exchange's PAYTO_URI in the config ..." +export LIBEUFIN_SANDBOX_USERNAME=exchange +export LIBEUFIN_SANDBOX_PASSWORD=x +PAYTO=`libeufin-cli sandbox demobank info --bank-account exchange | jq --raw-output '.paytoUri'` +taler-config -c $4 -s exchange-account-1 -o PAYTO_URI -V $PAYTO +echo " OK" +echo -n "Setting this exchange as the bank's default ..." +EXCHANGE_PAYTO=`libeufin-cli sandbox demobank info --bank-account exchange | jq --raw-output '.paytoUri'` +libeufin-sandbox default-exchange "$3" "$EXCHANGE_PAYTO" +echo " OK" +# Prepare EBICS: create Ebics host and Exchange subscriber. +# Shortly becoming admin to setup Ebics. +export LIBEUFIN_SANDBOX_USERNAME=admin +export LIBEUFIN_SANDBOX_PASSWORD=secret +echo -n "Create EBICS host at Sandbox.." +libeufin-cli sandbox \ + --sandbox-url http://localhost:1$1 \ + ebicshost create --host-id talerebics +echo OK +echo -n "Create exchange EBICS subscriber at Sandbox.." +libeufin-cli sandbox \ + demobank new-ebicssubscriber --host-id talerebics \ + --user-id exchangeebics --partner-id talerpartner \ + --bank-account exchange # that's a username _and_ a bank account name +echo OK +unset LIBEUFIN_SANDBOX_USERNAME +unset LIBEUFIN_SANDBOX_PASSWORD +# Prepare Nexus, which is the side actually talking +# to the exchange. +export LIBEUFIN_NEXUS_DB_CONNECTION="jdbc:sqlite:$2" +# For convenience, username and password are +# identical to those used at the Sandbox. +echo -n Create exchange Nexus user.. +libeufin-nexus superuser exchange --password x +echo OK +libeufin-nexus serve --port $1 \ + 2> libeufin-nexus-stderr.log \ + > libeufin-nexus-stdout.log & +echo $! > libeufin-nexus.pid +export LIBEUFIN_NEXUS_URL=http://localhost:$1 +echo -n Waiting for Nexus.. +set +e +for n in `seq 1 50`; do + echo -n "." + sleep 1 + wget --timeout=1 \ + --tries=3 --waitretry=0 \ + -o /dev/null -O /dev/null \ + $LIBEUFIN_NEXUS_URL + break +done +set -e +echo OK +export LIBEUFIN_NEXUS_USERNAME=exchange +export LIBEUFIN_NEXUS_PASSWORD=x +echo -n Creating a EBICS connection at Nexus.. +libeufin-cli connections new-ebics-connection \ + --ebics-url "http://localhost:1$1/ebicsweb" \ + --host-id talerebics \ + --partner-id talerpartner \ + --ebics-user-id exchangeebics \ + talerconn +echo OK +echo -n Setup EBICS keying.. +libeufin-cli connections connect talerconn > /dev/null +echo OK +echo -n Download bank account name from Sandbox.. +libeufin-cli connections download-bank-accounts talerconn +echo OK +echo -n Importing bank account info into Nexus.. +libeufin-cli connections import-bank-account \ + --offered-account-id exchange \ + --nexus-bank-account-id exchange-nexus \ + talerconn +echo OK +echo -n Setup payments submission task.. +# Tries every second. +libeufin-cli accounts task-schedule \ + --task-type submit \ + --task-name exchange-payments \ + --task-cronspec "* * *" \ + exchange-nexus +echo OK +# Tries every second. Ask C52 +echo -n Setup history fetch task.. +libeufin-cli accounts task-schedule \ + --task-type fetch \ + --task-name exchange-history \ + --task-cronspec "* * *" \ + --task-param-level report \ + --task-param-range-type latest \ + exchange-nexus +echo OK +# TBD: create Taler facade. +echo -n Create the Taler facade at Nexus.. +libeufin-cli facades \ + new-taler-wire-gateway-facade \ + --currency TESTKUDOS --facade-name test-facade \ + talerconn exchange-nexus +echo OK +# Facade schema: http://localhost:$1/facades/test-facade/taler-wire-gateway/ diff --git a/contrib/taler-nexus-prepare b/contrib/taler-nexus-prepare index 66a0b1c1e..6a36387d9 100755 --- a/contrib/taler-nexus-prepare +++ b/contrib/taler-nexus-prepare @@ -1,128 +1,115 @@ -#!/usr/bin/env python3 -# This file is in the public domain. +#!/bin/bash -from requests import get, post -from subprocess import call -import base64 +set -eu # EBICS details -EBICS_URL = "http://localhost:5000/ebicsweb" -HOST_ID = "HOST01" -PARTNER_ID = "PARTNER1" -USER_ID = "USER1" -EBICS_VERSION = "H004" - -SUBSCRIBER_IBAN = "ES9121000418450200051332" -SUBSCRIBER_BIC = "BIC" -SUBSCRIBER_NAME = "Exchange" - -BANK_ACCOUNT_LABEL = "my-bank-account" -BANK_CONNECTION_LABEL = "my-bank-connection" +EBICS_URL="http://localhost:5000/ebicsweb" +HOST_ID="HOST01" +PARTNER_ID="PARTNER1" +USER_ID="USER1" + +# This is used _both_ at Sandbox and at Nexus. +# Basically, Nexus imports the offered bank account +# using the same name used by the Sandbox. +BANK_ACCOUNT_LABEL="my-bank-account" +BANK_CONNECTION_LABEL="my-bank-connection" FACADE_LABEL="my-facade" -USERNAME="Exchange" -USER_AUTHORIZATION_HEADER = "basic {}".format( - base64.b64encode(b"Exchange:x").decode("utf-8") -) - -def assertResponse(response): - if response.status_code != 200: - print("Test failed on URL: {}".format(response.url)) - # stdout/stderr from both services is A LOT of text. - # Confusing to dump all that to console. - print("Check nexus.log and sandbox.log, probably under /tmp") - exit(1) - # Allows for finer grained checks. - return response - -# Create a nexus (super-) user -check_call(["libeufin-nexus", - "superuser", - "--db-name", "/tmp/nexus-exchange-test.sqlite3", - "Exchange", - "--password", "x"] -) - -# Create a EBICS bank connection. -assertResponse( - post( - "http://localhost:5001/bank-connections", - json=dict( - name=BANK_CONNECTION_LABEL, - source="new", - type="ebics", - data=dict( - ebicsURL=EBICS_URL, hostID=HOST_ID, partnerID=PARTNER_ID, userID=USER_ID - ), - ), - headers=dict(Authorization=USER_AUTHORIZATION_HEADER), - ) -) - -# Create a facade -assertResponse( - post( - "http://localhost:5001/facades", - json=dict( - name=FACADE_LABEL, - type="taler-wire-gateway", - creator=USERNAME, - config=dict( - bankAccount=BANK_ACCOUNT_LABEL, - bankConnection=BANK_CONNECTION_LABEL, - reserveTransferLevel="UNUSED", - intervalIncremental="UNUSED" - ) - ), - headers=dict(Authorization=USER_AUTHORIZATION_HEADER), - ) -) - -# Create the EBICS host at the Sandbox. -assertResponse( - post( - "http://localhost:5000/admin/ebics/host", - json=dict(hostID=HOST_ID, ebicsVersion=EBICS_VERSION), - ) -) - -# Create Exchange EBICS subscriber at the Sandbox. -assertResponse( - post( - "http://localhost:5000/admin/ebics/subscribers", - json=dict(hostID=HOST_ID, partnerID=PARTNER_ID, userID=USER_ID), - ) -) - -# Create a bank account associated to the Exchange's EBICS subscriber, -# again at the Sandbox. -assertResponse( - post( - "http://localhost:5000/admin/ebics/bank-accounts", - json=dict( - subscriber=dict(hostID=HOST_ID, partnerID=PARTNER_ID, userID=USER_ID), - iban=SUBSCRIBER_IBAN, - bic=SUBSCRIBER_BIC, - name=SUBSCRIBER_NAME, - label=BANK_ACCOUNT_LABEL, - ), - ) -) - -# 'connect' to the bank: upload+download keys. -assertResponse( - post( - "http://localhost:5001/bank-connections/{}/connect".format(BANK_CONNECTION_LABEL), - json=dict(), - headers=dict(Authorization=USER_AUTHORIZATION_HEADER), - ) -) - -# Download bank accounts. -assertResponse( - post( - "http://localhost:5001/bank-connections/{}/ebics/import-accounts".format(BANK_CONNECTION_LABEL), - json=dict(), - headers=dict(Authorization=USER_AUTHORIZATION_HEADER), - ) -) +export LIBEUFIN_SANDBOX_USERNAME=exchange +export LIBEUFIN_SANDBOX_PASSWORD=x +export LIBEUFIN_SANDBOX_URL=http://localhost:5000/demobanks/default +libeufin-cli sandbox demobank register --name "Exchange Company" + +export LIBEUFIN_SANDBOX_USERNAME=fortytwo +export LIBEUFIN_SANDBOX_PASSWORD=x +export LIBEUFIN_SANDBOX_URL=http://localhost:5000/demobanks/default +libeufin-cli sandbox demobank register \ + --name User42 --iban FR7630006000011234567890189 + +export LIBEUFIN_SANDBOX_USERNAME=fortythree +export LIBEUFIN_SANDBOX_PASSWORD=x +export LIBEUFIN_SANDBOX_URL=http://localhost:5000/demobanks/default +libeufin-cli sandbox demobank register \ + --name User43 --iban GB33BUKB20201555555555 + +export LIBEUFIN_SANDBOX_USERNAME=admin +export LIBEUFIN_SANDBOX_PASSWORD=secret +export LIBEUFIN_SANDBOX_URL=http://localhost:5000/demobanks/default +echo -n "Create EBICS host at Sandbox..." +libeufin-cli sandbox \ + --sandbox-url "http://localhost:5000" \ + ebicshost create --host-id $HOST_ID +echo " OK" + +echo -n "Create exchange EBICS subscriber at Sandbox..." +libeufin-cli sandbox \ + demobank new-ebicssubscriber --host-id $HOST_ID \ + --user-id $USER_ID --partner-id $PARTNER_ID \ + --bank-account exchange # that's a username _and_ a bank account name +echo " OK" +unset LIBEUFIN_SANDBOX_USERNAME +unset LIBEUFIN_SANDBOX_PASSWORD +unset LIBEUFIN_SANDBOX_URL + +export LIBEUFIN_NEXUS_USERNAME=exchange +export LIBEUFIN_NEXUS_PASSWORD=x +export LIBEUFIN_NEXUS_URL=http://localhost:5001/ + +echo -n "Create the exchange (super)user at Nexus..." +libeufin-nexus superuser exchange --password x +echo " DONE" + +echo -n "Creating a EBICS connection at Nexus..." +libeufin-cli connections new-ebics-connection \ + --ebics-url $EBICS_URL \ + --host-id $HOST_ID \ + --partner-id $PARTNER_ID \ + --ebics-user-id $USER_ID \ + $BANK_CONNECTION_LABEL +echo " OK" + +echo -n "Setup EBICS keying..." +libeufin-cli connections connect $BANK_CONNECTION_LABEL > /dev/null +echo " OK" + +echo -n "Download bank account name from Sandbox..." +libeufin-cli connections download-bank-accounts $BANK_CONNECTION_LABEL +echo " OK" + +echo -n "Importing bank account info into Nexus..." +libeufin-cli connections import-bank-account \ + --offered-account-id exchange \ + --nexus-bank-account-id $BANK_ACCOUNT_LABEL \ + $BANK_CONNECTION_LABEL +echo " OK" + +echo -n "Create the Taler facade at Nexus..." +libeufin-cli facades \ + new-taler-wire-gateway-facade \ + --currency KUDOS --facade-name $FACADE_LABEL \ + $BANK_CONNECTION_LABEL $BANK_ACCOUNT_LABEL +echo " DONE" + +echo -n Setup payments submission task.. +# Tries every second. +libeufin-cli accounts task-schedule \ + --task-type submit \ + --task-name exchange-payments \ + --task-cronspec "* * *" \ + $BANK_ACCOUNT_LABEL +echo OK +# Tries every second. Ask C52 +echo -n Setup history fetch task.. +libeufin-cli accounts task-schedule \ + --task-type fetch \ + --task-name exchange-history \ + --task-cronspec "* * *" \ + --task-param-level report \ + --task-param-range-type latest \ + $BANK_ACCOUNT_LABEL +echo OK + +# unset, in case the script gets 'source'd. +unset LIBEUFIN_NEXUS_USERNAME +unset LIBEUFIN_NEXUS_PASSWORD +unset LIBEUFIN_NEXUS_URL |