From 9fda23115ab0607034a084a369570f8aab4fc9fa Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 22 Sep 2022 21:37:26 +0200 Subject: -work on test-auditor.sh --- src/auditor/generate-auditor-basedb.sh | 70 ++++++++++------- src/auditor/generate-revoke-basedb.sh | 80 ++++++++++--------- src/auditor/test-auditor.sh | 140 ++++++++++++++++++--------------- src/auditor/test-revocation.sh | 52 ++++++------ 4 files changed, 189 insertions(+), 153 deletions(-) (limited to 'src/auditor') diff --git a/src/auditor/generate-auditor-basedb.sh b/src/auditor/generate-auditor-basedb.sh index a12057b93..6fbb4ad2d 100755 --- a/src/auditor/generate-auditor-basedb.sh +++ b/src/auditor/generate-auditor-basedb.sh @@ -19,33 +19,37 @@ function get_iban() { export LIBEUFIN_SANDBOX_USERNAME=$1 export LIBEUFIN_SANDBOX_PASSWORD=$2 export LIBEUFIN_SANDBOX_URL=$BANK_URL + cd $MY_TMP_DIR libeufin-cli sandbox demobank info --bank-account $1 | jq --raw-output '.iban' + cd $ORIGIN } function get_payto_uri() { export LIBEUFIN_SANDBOX_USERNAME=$1 export LIBEUFIN_SANDBOX_PASSWORD=$2 export LIBEUFIN_SANDBOX_URL=$BANK_URL + cd $MY_TMP_DIR libeufin-cli sandbox demobank info --bank-account $1 | jq --raw-output '.paytoUri' + cd $ORIGIN } # Cleanup to run whenever we exit function exit_cleanup() { echo "Running generate-auditor-basedb exit cleanup logic..." - if test -f libeufin-sandbox.pid + if test -f ${MY_TMP_DIR:-/}/libeufin-sandbox.pid then - PID=`cat libeufin-sandbox.pid 2> /dev/null` + PID=`cat ${MY_TMP_DIR}/libeufin-sandbox.pid 2> /dev/null` kill $PID 2> /dev/null || true - rm libeufin-sandbox.pid + rm ${MY_TMP_DIR}/libeufin-sandbox.pid echo "Killed libeufin sandbox $PID" wait $PID || true fi - if test -f libeufin-nexus.pid + if test -f ${MY_TMP_DIR:-/}/libeufin-nexus.pid then - PID=`cat libeufin-nexus.pid 2> /dev/null` + PID=`cat ${MY_TMP_DIR}/libeufin-nexus.pid 2> /dev/null` kill $PID 2> /dev/null || true - rm libeufin-nexus.pid + rm ${MY_TMP_DIR}/libeufin-nexus.pid echo "Killed libeufin nexus $PID" wait $PID || true fi @@ -83,6 +87,9 @@ rm -f $WALLET_DB export CONF=$1.conf cp generate-auditor-basedb.conf $CONF echo "Created configuration at ${CONF}" +DATA_DIR=$1/exchange-data-dir/ +mkdir -p $DATA_DIR +taler-config -c $CONF -s PATHS -o TALER_HOME -V $DATA_DIR echo -n "Testing for libeufin" libeufin-cli --help >/dev/null /dev/null /dev/null 2>/dev/null || true createdb $TARGET_DB || exit_skip "Could not create database $TARGET_DB" +ORIGIN=`pwd` +MY_TMP_DIR=`dirname $1` # obtain key configuration data MASTER_PRIV_FILE=$1.mpriv @@ -151,15 +156,16 @@ taler-auditor-exchange -c $CONF -m $MASTER_PUB -u $EXCHANGE_URL || exit_skip "Fa # Launch services echo "Launching services (pre audit DB: $TARGET_DB)" -rm -f ${TARGET_DB}-sandbox.sqlite3 ${TARGET_DB}-nexus.sqlite3 2> /dev/null # libeufin DB export LIBEUFIN_SANDBOX_DB_CONNECTION="jdbc:sqlite:${TARGET_DB}-sandbox.sqlite3" # Create the default demobank. +cd $MY_TMP_DIR libeufin-sandbox config --currency "TESTKUDOS" default export LIBEUFIN_SANDBOX_ADMIN_PASSWORD=secret libeufin-sandbox serve --port "1${BANK_PORT}" \ - > libeufin-sandbox-stdout.log \ - 2> libeufin-sandbox-stderr.log & -echo $! > libeufin-sandbox.pid + > ${MY_TMP_DIR}/libeufin-sandbox-stdout.log \ + 2> ${MY_TMP_DIR}/libeufin-sandbox-stderr.log & +echo $! > ${MY_TMP_DIR}/libeufin-sandbox.pid +cd $ORIGIN export LIBEUFIN_SANDBOX_URL="http://localhost:1${BANK_PORT}/demobanks/default" set +e echo -n "Waiting for Sandbox..." @@ -185,9 +191,11 @@ echo "OK" register_sandbox_account() { export LIBEUFIN_SANDBOX_USERNAME=$1 export LIBEUFIN_SANDBOX_PASSWORD=$2 + cd $MY_TMP_DIR libeufin-cli sandbox \ demobank \ register --name "$3" + cd $ORIGIN unset LIBEUFIN_SANDBOX_USERNAME unset LIBEUFIN_SANDBOX_PASSWORD } @@ -204,6 +212,7 @@ echo OK echo -n "Specify exchange's PAYTO_URI in the config ..." export LIBEUFIN_SANDBOX_USERNAME=exchange export LIBEUFIN_SANDBOX_PASSWORD=x +cd $MY_TMP_DIR PAYTO=`libeufin-cli sandbox demobank info --bank-account exchange | jq --raw-output '.paytoUri'` taler-config -c $CONF -s exchange-account-1 -o PAYTO_URI -V $PAYTO echo " OK" @@ -237,9 +246,9 @@ echo -n "Create exchange Nexus user..." libeufin-nexus superuser exchange --password x echo " OK" libeufin-nexus serve --port ${BANK_PORT} \ - 2> libeufin-nexus-stderr.log \ - > libeufin-nexus-stdout.log & -echo $! > libeufin-nexus.pid + 2> ${MY_TMP_DIR}/libeufin-nexus-stderr.log \ + > ${MY_TMP_DIR}/libeufin-nexus-stdout.log & +echo $! > ${MY_TMP_DIR}/libeufin-nexus.pid export LIBEUFIN_NEXUS_URL="http://localhost:${BANK_PORT}" echo -n "Waiting for Nexus..." set +e @@ -309,19 +318,20 @@ libeufin-cli facades \ --currency "TESTKUDOS" --facade-name "test-facade" \ "talerconn" "exchange-nexus" echo "OK" +cd $ORIGIN # Facade schema: http://localhost:$BANK_PORT/facades/test-facade/taler-wire-gateway/ TFN=`which taler-exchange-httpd` TBINPFX=`dirname $TFN` TLIBEXEC=${TBINPFX}/../lib/taler/libexec/ -taler-exchange-secmod-eddsa -c $CONF 2> taler-exchange-secmod-eddsa.log & -taler-exchange-secmod-rsa -c $CONF 2> taler-exchange-secmod-rsa.log & -taler-exchange-secmod-cs -c $CONF 2> taler-exchange-secmod-cs.log & -taler-exchange-httpd -c $CONF 2> taler-exchange-httpd.log & -taler-merchant-httpd -c $CONF -L INFO 2> taler-merchant-httpd.log & -taler-exchange-wirewatch -c $CONF 2> taler-exchange-wirewatch.log & -taler-auditor-httpd -L INFO -c $CONF 2> taler-auditor-httpd.log & +taler-exchange-secmod-eddsa -c $CONF 2> ${MY_TMP_DIR}/taler-exchange-secmod-eddsa.log & +taler-exchange-secmod-rsa -c $CONF 2> ${MY_TMP_DIR}/taler-exchange-secmod-rsa.log & +taler-exchange-secmod-cs -c $CONF 2> ${MY_TMP_DIR}/taler-exchange-secmod-cs.log & +taler-exchange-httpd -c $CONF 2> ${MY_TMP_DIR}/taler-exchange-httpd.log & +taler-merchant-httpd -c $CONF -L INFO 2> ${MY_TMP_DIR}/taler-merchant-httpd.log & +taler-exchange-wirewatch -c $CONF 2> ${MY_TMP_DIR}/taler-exchange-wirewatch.log & +taler-auditor-httpd -L INFO -c $CONF 2> ${MY_TMP_DIR}/taler-auditor-httpd.log & # Wait for all bank to be available (usually the slowest) for n in `seq 1 50` @@ -367,7 +377,7 @@ taler-exchange-offline -c $CONF \ enable-auditor $AUDITOR_PUB $AUDITOR_URL "TESTKUDOS Auditor" \ wire-fee now iban TESTKUDOS:0.07 TESTKUDOS:0.01 TESTKUDOS:0.01 \ global-fee now TESTKUDOS:0.01 TESTKUDOS:0.01 TESTKUDOS:0.01 TESTKUDOS:0.01 1h 1h 1year 5 \ - upload &> taler-exchange-offline.log + upload &> ${MY_TMP_DIR}/taler-exchange-offline.log echo -n "." @@ -389,7 +399,7 @@ echo " DONE" echo -n "Adding auditor signatures ..." taler-auditor-offline -c $CONF \ - download sign upload &> taler-auditor-offline.log + download sign upload &> ${MY_TMP_DIR}/taler-auditor-offline.log echo " DONE" # Setup merchant @@ -416,9 +426,7 @@ taler-wallet-cli --no-throttle --wallet-db=$WALLET_DB api --expect-success 'runI --arg MERCHANT_URL "$MERCHANT_URL" \ --arg EXCHANGE_URL "$EXCHANGE_URL" \ --arg BANK_URL "$BANK_URL/access-api/" - )" &> taler-wallet-cli.log - -bash + )" &> ${MY_TMP_DIR}/taler-wallet-cli.log echo "Shutting down services" exit_cleanup @@ -426,15 +434,17 @@ exit_cleanup # Dump database echo "Dumping database ${BASEDB}(-libeufin).sql" pg_dump -O $TARGET_DB | sed -e '/AS integer/d' > ${BASEDB}.sql +cd $MY_TMP_DIR sqlite3 ${TARGET_DB}-nexus.sqlite3 ".dump" > ${BASEDB}-libeufin-nexus.sql sqlite3 ${TARGET_DB}-sandbox.sqlite3 ".dump" > ${BASEDB}-libeufin-sandbox.sql +rm ${TARGET_DB}-sandbox.sqlite3 ${TARGET_DB}-nexus.sqlite3 # libeufin DB +cd $ORIGIN echo $MASTER_PUB > ${BASEDB}.mpub # clean up echo "Final clean up" dropdb $TARGET_DB -rm ${TARGET_DB}-sandbox.sqlite3 ${TARGET_DB}-nexus.sqlite3 # libeufin DB echo "=====================================" echo " Finished generation of $BASEDB" diff --git a/src/auditor/generate-revoke-basedb.sh b/src/auditor/generate-revoke-basedb.sh index 6ad0a6e99..997a9b723 100755 --- a/src/auditor/generate-revoke-basedb.sh +++ b/src/auditor/generate-revoke-basedb.sh @@ -11,19 +11,19 @@ set -eux function exit_cleanup() { echo "Running generate-revoke-basedb exit cleanup logic..." - if test -f libeufin-sandbox.pid + if test -f ${MY_TMP_DIR:-/}/libeufin-sandbox.pid then - PID=`cat libeufin-sandbox.pid 2> /dev/null` + PID=`cat ${MY_TMP_DIR}/libeufin-sandbox.pid 2> /dev/null` kill $PID 2> /dev/null || true - rm libeufin-sandbox.pid + rm ${MY_TMP_DIR}/libeufin-sandbox.pid echo "Killed libeufin sandbox $PID" wait $PID || true fi - if test -f libeufin-nexus.pid + if test -f ${MY_TMP_DIR}/libeufin-nexus.pid then - PID=`cat libeufin-nexus.pid 2> /dev/null` + PID=`cat ${MY_TMP_DIR}/libeufin-nexus.pid 2> /dev/null` kill $PID 2> /dev/null || true - rm libeufin-nexus.pid + rm ${MY_TMP_DIR}/libeufin-nexus.pid echo "Killed libeufin nexus $PID" wait $PID || true fi @@ -39,7 +39,9 @@ function get_payto_uri() { export LIBEUFIN_SANDBOX_USERNAME=$1 export LIBEUFIN_SANDBOX_PASSWORD=$2 export LIBEUFIN_SANDBOX_URL=$BANK_URL + cd $MY_TMP_DIR libeufin-cli sandbox demobank info --bank-account $1 | jq --raw-output '.paytoUri' + cd $ORIGIN } # Install cleanup handler (except for kill -9) @@ -67,6 +69,9 @@ rm -f $WALLET_DB export CONF=${BASEDB}.conf cp generate-auditor-basedb.conf $CONF echo "Created configuration at ${CONF}" +DATA_DIR=$1/exchange-data-dir/ +mkdir -p $DATA_DIR +taler-config -c $CONF -s PATHS -o TALER_HOME -V $DATA_DIR echo -n "Testing for libeufin(-cli)" libeufin-cli --help >/dev/null /dev/null /dev/null 2>/dev/null || true createdb $TARGET_DB || exit_skip "Could not create database $TARGET_DB" -rm $TARGET_DB >/dev/null 2>/dev/null || true # libeufin +ORIGIN=`pwd` +MY_TMP_DIR=`dirname $1` + # obtain key configuration data MASTER_PRIV_FILE=$1.mpriv @@ -138,15 +141,16 @@ taler-auditor-exchange -c $CONF -m $MASTER_PUB -u $EXCHANGE_URL # Launch services echo "Launching services" -rm -f ${TARGET_DB}-sandbox.sqlite3 ${TARGET_DB}-nexus.sqlite3 2> /dev/null # libeufin DB export LIBEUFIN_SANDBOX_DB_CONNECTION="jdbc:sqlite:${TARGET_DB}-sandbox.sqlite3" # Create the default demobank. +cd $MY_TMP_DIR libeufin-sandbox config --currency "TESTKUDOS" default export LIBEUFIN_SANDBOX_ADMIN_PASSWORD=secret libeufin-sandbox serve --port "1${BANK_PORT}" \ - > libeufin-sandbox-stdout.log \ - 2> libeufin-sandbox-stderr.log & -echo $! > libeufin-sandbox.pid + > ${MY_TMP_DIR}/libeufin-sandbox-stdout.log \ + 2> ${MY_TMP_DIR}/libeufin-sandbox-stderr.log & +echo $! > ${MY_TMP_DIR}/libeufin-sandbox.pid +cd $ORIGIN export LIBEUFIN_SANDBOX_URL="http://localhost:1${BANK_PORT}/demobanks/default" set +e echo -n "Waiting for Sandbox..." @@ -172,9 +176,11 @@ echo "OK" register_sandbox_account() { export LIBEUFIN_SANDBOX_USERNAME=$1 export LIBEUFIN_SANDBOX_PASSWORD=$2 + cd $MY_TMP_DIR libeufin-cli sandbox \ demobank \ register --name "$3" + cd $ORIGIN unset LIBEUFIN_SANDBOX_USERNAME unset LIBEUFIN_SANDBOX_PASSWORD } @@ -191,6 +197,7 @@ echo OK echo -n "Specify exchange's PAYTO_URI in the config ..." export LIBEUFIN_SANDBOX_USERNAME=exchange export LIBEUFIN_SANDBOX_PASSWORD=x +cd $MY_TMP_DIR PAYTO=`libeufin-cli sandbox demobank info --bank-account exchange | jq --raw-output '.paytoUri'` taler-config -c $CONF -s exchange-account-1 -o PAYTO_URI -V $PAYTO echo " OK" @@ -224,9 +231,9 @@ echo -n "Create exchange Nexus user..." libeufin-nexus superuser exchange --password x echo " OK" libeufin-nexus serve --port ${BANK_PORT} \ - 2> libeufin-nexus-stderr.log \ - > libeufin-nexus-stdout.log & -echo $! > libeufin-nexus.pid + 2> ${MY_TMP_DIR}/libeufin-nexus-stderr.log \ + > ${MY_TMP_DIR}/libeufin-nexus-stdout.log & +echo $! > ${MY_TMP_DIR}/libeufin-nexus.pid export LIBEUFIN_NEXUS_URL="http://localhost:${BANK_PORT}" echo -n "Waiting for Nexus..." set +e @@ -296,23 +303,24 @@ libeufin-cli facades \ --currency "TESTKUDOS" --facade-name "test-facade" \ "talerconn" "exchange-nexus" echo "OK" +cd $ORIGIN # Facade schema: http://localhost:$BANK_PORT/facades/test-facade/taler-wire-gateway/ TFN=`which taler-exchange-httpd` TBINPFX=`dirname $TFN` TLIBEXEC=${TBINPFX}/../lib/taler/libexec/ -taler-exchange-secmod-eddsa -c $CONF 2> taler-exchange-secmod-eddsa.log & +taler-exchange-secmod-eddsa -c $CONF 2> ${MY_TMP_DIR}/taler-exchange-secmod-eddsa.log & SIGNKEY_HELPER_PID=$! -taler-exchange-secmod-rsa -c $CONF 2> taler-exchange-secmod-rsa.log & +taler-exchange-secmod-rsa -c $CONF 2> ${MY_TMP_DIR}/taler-exchange-secmod-rsa.log & RSA_DENOM_HELPER_PID=$! -taler-exchange-secmod-cs -c $CONF 2> taler-exchange-secmod-cs.log & +taler-exchange-secmod-cs -c $CONF 2> ${MY_TMP_DIR}/taler-exchange-secmod-cs.log & CS_DENOM_HELPER_PID=$! -taler-exchange-httpd -c $CONF 2> taler-exchange-httpd.log & +taler-exchange-httpd -c $CONF 2> ${MY_TMP_DIR}/taler-exchange-httpd.log & EXCHANGE_PID=$! -taler-merchant-httpd -c $CONF -L INFO 2> taler-merchant-httpd.log & +taler-merchant-httpd -c $CONF -L INFO 2> ${MY_TMP_DIR}/taler-merchant-httpd.log & MERCHANT_PID=$! -taler-exchange-wirewatch -c $CONF 2> taler-exchange-wirewatch.log & -taler-auditor-httpd -c $CONF 2> taler-auditor-httpd.log & +taler-exchange-wirewatch -c $CONF 2> ${MY_TMP_DIR}/taler-exchange-wirewatch.log & +taler-auditor-httpd -c $CONF 2> ${MY_TMP_DIR}/taler-auditor-httpd.log & # Wait for all bank to be available (usually the slowest) for n in `seq 1 50` @@ -362,7 +370,7 @@ taler-exchange-offline -c $CONF \ enable-auditor $AUDITOR_PUB $AUDITOR_URL "TESTKUDOS Auditor" \ wire-fee now iban TESTKUDOS:0.01 TESTKUDOS:0.01 TESTKUDOS:0.01 \ global-fee now TESTKUDOS:0.01 TESTKUDOS:0.01 TESTKUDOS:0.01 TESTKUDOS:0.01 1h 1h 1year 5 \ - upload &> taler-exchange-offline.log + upload &> ${MY_TMP_DIR}/taler-exchange-offline.log echo -n "." @@ -383,7 +391,7 @@ fi taler-auditor-offline -c $CONF \ - download sign upload &> taler-auditor-offline.log + download sign upload &> ${MY_TMP_DIR}/taler-auditor-offline.log echo " DONE" @@ -424,13 +432,13 @@ export susp=$(echo "$coins" | jq --arg rc "$rc" '[.coins[] | select(.coin_pub != # Do the revocation taler-exchange-offline -c $CONF \ - revoke-denomination "${rd}" upload &> taler-exchange-offline-revoke.log + revoke-denomination "${rd}" upload &> ${MY_TMP_DIR}/taler-exchange-offline-revoke.log sleep 1 # Give exchange time to create replacmenent key # Re-sign replacement keys taler-auditor-offline -c $CONF \ - download sign upload &> taler-auditor-offline.log + download sign upload &> ${MY_TMP_DIR}/taler-auditor-offline.log # Now we suspend the other coins, so later we will pay with the recouped coin taler-wallet-cli --wallet-db=$WALLET_DB advanced suspend-coins "$susp" @@ -478,13 +486,13 @@ kill -TERM $EXCHANGE_PID kill -TERM $RSA_DENOM_HELPER_PID kill -TERM $CS_DENOM_HELPER_PID kill -TERM $SIGNKEY_HELPER_PID -taler-exchange-secmod-eddsa $TIMETRAVEL -c $CONF 2> taler-exchange-secmod-eddsa.log & +taler-exchange-secmod-eddsa $TIMETRAVEL -c $CONF 2> ${MY_TMP_DIR}/taler-exchange-secmod-eddsa.log & SIGNKEY_HELPER_PID=$! -taler-exchange-secmod-rsa $TIMETRAVEL -c $CONF 2> taler-exchange-secmod-rsa.log & +taler-exchange-secmod-rsa $TIMETRAVEL -c $CONF 2> ${MY_TMP_DIR}/taler-exchange-secmod-rsa.log & RSA_DENOM_HELPER_PID=$! -taler-exchange-secmod-cs $TIMETRAVEL -c $CONF 2> taler-exchange-secmod-cs.log & +taler-exchange-secmod-cs $TIMETRAVEL -c $CONF 2> ${MY_TMP_DIR}/taler-exchange-secmod-cs.log & CS_DENOM_HELPER_PID=$! -taler-exchange-httpd $TIMETRAVEL -c $CONF 2> taler-exchange-httpd.log & +taler-exchange-httpd $TIMETRAVEL -c $CONF 2> ${MY_TMP_DIR}/taler-exchange-httpd.log & export EXCHANGE_PID=$! # Wait for exchange to be available @@ -525,13 +533,13 @@ export susp=$(echo "$coins" | jq --arg freshc "$freshc" '[.coins[] | select(.coi # Do the revocation of freshc echo "Revoking ${fresh_denom} (to affect coin ${freshc})" taler-exchange-offline -c $CONF \ - revoke-denomination "${fresh_denom}" upload &> taler-exchange-offline-revoke-2.log + revoke-denomination "${fresh_denom}" upload &> ${MY_TMP_DIR}/taler-exchange-offline-revoke-2.log sleep 1 # Give exchange time to create replacmenent key # Re-sign replacement keys taler-auditor-offline -c $CONF \ - download sign upload &> taler-auditor-offline.log + download sign upload &> ${MY_TMP_DIR}/taler-auditor-offline.log # Now we suspend the other coins, so later we will pay with the recouped coin taler-wallet-cli $TIMETRAVEL --wallet-db=$WALLET_DB advanced suspend-coins "$susp" @@ -545,7 +553,7 @@ taler-wallet-cli $TIMETRAVEL --wallet-db=$WALLET_DB run-until-done echo "Restarting merchant (so new keys are known)" kill -TERM $MERCHANT_PID -taler-merchant-httpd -c $CONF -L INFO 2> taler-merchant-httpd.log & +taler-merchant-httpd -c $CONF -L INFO 2> ${MY_TMP_DIR}/taler-merchant-httpd.log & MERCHANT_PID=$! # Wait for merchant to be again available for n in `seq 1 50` diff --git a/src/auditor/test-auditor.sh b/src/auditor/test-auditor.sh index 5992ac10d..9601c2f58 100755 --- a/src/auditor/test-auditor.sh +++ b/src/auditor/test-auditor.sh @@ -122,17 +122,19 @@ function exit_cleanup() trap exit_cleanup EXIT function launch_libeufin () { - export LIBEUFIN_NEXUS_DB_CONNECTION="jdbc:sqlite:${DB}-nexus.sqlite3" - libeufin-nexus serve --port 8082 \ - 2> libeufin-nexus-stderr.log \ - > libeufin-nexus-stdout.log & - echo $! > libeufin-nexus.pid + cd $MYDIR export LIBEUFIN_SANDBOX_DB_CONNECTION="jdbc:sqlite:${DB}-sandbox.sqlite3" export LIBEUFIN_SANDBOX_ADMIN_PASSWORD=secret libeufin-sandbox serve --port 18082 \ - > libeufin-sandbox-stdout.log \ - 2> libeufin-sandbox-stderr.log & - echo $! > libeufin-sandbox.pid + > ${MYDIR}/libeufin-sandbox-stdout.log \ + 2> ${MYDIR}/libeufin-sandbox-stderr.log & + echo $! > ${MYDIR}/libeufin-sandbox.pid + export LIBEUFIN_NEXUS_DB_CONNECTION="jdbc:sqlite:${DB}-nexus.sqlite3" + libeufin-nexus serve --port 8082 \ + 2> ${MYDIR}/libeufin-nexus-stderr.log \ + > ${MYDIR}/libeufin-nexus-stdout.log & + echo $! > ${MYDIR}/libeufin-nexus.pid + cd $ORIGIN } # Downloads new transactions from the bank. @@ -140,8 +142,10 @@ function nexus_fetch_transactions () { export LIBEUFIN_NEXUS_USERNAME=exchange export LIBEUFIN_NEXUS_PASSWORD=x export LIBEUFIN_NEXUS_URL=http://localhost:8082/ + cd $MY_TMP_DIR libeufin-cli accounts fetch-transactions \ --range-type since-last --level report exchange-nexus > /dev/null + cd $ORIGIN unset LIBEUFIN_NEXUS_USERNAME unset LIBEUFIN_NEXUS_PASSWORD unset LIBEUFIN_NEXUS_URL @@ -154,7 +158,9 @@ function nexus_submit_to_sandbox () { export LIBEUFIN_NEXUS_USERNAME=exchange export LIBEUFIN_NEXUS_PASSWORD=x export LIBEUFIN_NEXUS_URL=http://localhost:8082/ + cd $MY_TMP_DIR libeufin-cli accounts submit-payments exchange-nexus + cd $ORIGIN unset LIBEUFIN_NEXUS_USERNAME unset LIBEUFIN_NEXUS_PASSWORD unset LIBEUFIN_NEXUS_URL @@ -196,13 +202,13 @@ function pre_audit () { if test ${1:-no} = "aggregator" then echo -n "Running exchange aggregator ..." - taler-exchange-aggregator -y -L INFO -t -c $CONF 2> aggregator.log || exit_fail "FAIL" + taler-exchange-aggregator -y -L INFO -t -c $CONF 2> ${MY_TMP_DIR}/aggregator.log || exit_fail "FAIL" echo " DONE" echo -n "Running exchange closer ..." - taler-exchange-closer -L INFO -t -c $CONF 2> closer.log || exit_fail "FAIL" + taler-exchange-closer -L INFO -t -c $CONF 2> ${MY_TMP_DIR}/closer.log || exit_fail "FAIL" echo " DONE" echo -n "Running exchange transfer ..." - taler-exchange-transfer -L INFO -t -c $CONF 2> transfer.log || exit_fail "FAIL" + taler-exchange-transfer -L INFO -t -c $CONF 2> ${MY_TMP_DIR}/transfer.log || exit_fail "FAIL" echo " DONE" echo -n "Running Nexus payment submitter ..." nexus_submit_to_sandbox @@ -221,25 +227,25 @@ function audit_only () { # Restart so that first run is always fresh, and second one is incremental taler-auditor-dbinit -r -c $CONF - $VALGRIND taler-helper-auditor-aggregation -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-aggregation.json 2> test-audit-aggregation.log || exit_fail "aggregation audit failed" + $VALGRIND taler-helper-auditor-aggregation -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-aggregation.json 2> ${MY_TMP_DIR}/test-audit-aggregation.log || exit_fail "aggregation audit failed" echo -n "." - $VALGRIND taler-helper-auditor-aggregation -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-aggregation-inc.json 2> test-audit-aggregation-inc.log || exit_fail "incremental aggregation audit failed" + $VALGRIND taler-helper-auditor-aggregation -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-aggregation-inc.json 2> ${MY_TMP_DIR}/test-audit-aggregation-inc.log || exit_fail "incremental aggregation audit failed" echo -n "." - $VALGRIND taler-helper-auditor-coins -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-coins.json 2> test-audit-coins.log || exit_fail "coin audit failed" + $VALGRIND taler-helper-auditor-coins -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-coins.json 2> ${MY_TMP_DIR}/test-audit-coins.log || exit_fail "coin audit failed" echo -n "." - $VALGRIND taler-helper-auditor-coins -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-coins-inc.json 2> test-audit-coins-inc.log || exit_fail "incremental coin audit failed" + $VALGRIND taler-helper-auditor-coins -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-coins-inc.json 2> ${MY_TMP_DIR}/test-audit-coins-inc.log || exit_fail "incremental coin audit failed" echo -n "." - $VALGRIND taler-helper-auditor-deposits -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-deposits.json 2> test-audit-deposits.log || exit_fail "deposits audit failed" + $VALGRIND taler-helper-auditor-deposits -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-deposits.json 2> ${MY_TMP_DIR}/test-audit-deposits.log || exit_fail "deposits audit failed" echo -n "." - $VALGRIND taler-helper-auditor-deposits -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-deposits-inc.json 2> test-audit-deposits-inc.log || exit_fail "incremental deposits audit failed" + $VALGRIND taler-helper-auditor-deposits -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-deposits-inc.json 2> ${MY_TMP_DIR}/test-audit-deposits-inc.log || exit_fail "incremental deposits audit failed" echo -n "." - $VALGRIND taler-helper-auditor-reserves -i -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-reserves.json 2> test-audit-reserves.log || exit_fail "reserves audit failed" + $VALGRIND taler-helper-auditor-reserves -i -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-reserves.json 2> ${MY_TMP_DIR}/test-audit-reserves.log || exit_fail "reserves audit failed" echo -n "." - $VALGRIND taler-helper-auditor-reserves -i -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-reserves-inc.json 2> test-audit-reserves-inc.log || exit_fail "incremental reserves audit failed" + $VALGRIND taler-helper-auditor-reserves -i -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-reserves-inc.json 2> ${MY_TMP_DIR}/test-audit-reserves-inc.log || exit_fail "incremental reserves audit failed" echo -n "." - $VALGRIND taler-helper-auditor-wire -i -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-wire.json 2> test-wire-audit.log || exit_fail "wire audit failed" + $VALGRIND taler-helper-auditor-wire -i -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-wire.json 2> ${MY_TMP_DIR}/test-wire-audit.log || exit_fail "wire audit failed" echo -n "." - $VALGRIND taler-helper-auditor-wire -i -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-wire-inc.json 2> test-wire-audit-inc.log || exit_fail "wire audit inc failed" + $VALGRIND taler-helper-auditor-wire -i -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-wire-inc.json 2> ${MY_TMP_DIR}/test-wire-audit-inc.log || exit_fail "wire audit inc failed" echo -n "." echo " DONE" @@ -272,7 +278,7 @@ function run_audit () { if test ${2:-no} = "drain" then echo -n "Starting exchange..." - taler-exchange-httpd -c "${CONF}" -L INFO 2> exchange-httpd-drain.err & + taler-exchange-httpd -c "${CONF}" -L INFO 2> ${MYDIR}/exchange-httpd-drain.err & EPID=$! # Wait for all services to be available @@ -294,21 +300,22 @@ function run_audit () { taler-exchange-offline -L DEBUG -c "${CONF}" \ drain TESTKUDOS:0.1 exchange-account-1 payto://iban/SANDBOXX/DE360679?receiver-name=Exchange+Drain \ upload \ - 2> taler-exchange-offline-drain.log || exit_fail "offline draining failed" + 2> ${MY_TMP_DIR}/taler-exchange-offline-drain.log || exit_fail "offline draining failed" kill -TERM $EPID wait $EPID || true unset EPID echo -n "Running taler-exchange-drain ..." - echo "\n" | taler-exchange-drain -L DEBUG -c $CONF 2> taler-exchange-drain.log || exit_fail "FAIL" + echo "\n" | taler-exchange-drain -L DEBUG -c $CONF 2> ${MY_TMP_DIR}/taler-exchange-drain.log || exit_fail "FAIL" echo " DONE" echo -n "Running taler-exchange-transfer ..." - taler-exchange-transfer -L INFO -t -c $CONF 2> drain-transfer.log || exit_fail "FAIL" + taler-exchange-transfer -L INFO -t -c $CONF 2> ${MY_TMP_DIR}/drain-transfer.log || exit_fail "FAIL" echo " DONE" export LIBEUFIN_NEXUS_USERNAME=exchange export LIBEUFIN_NEXUS_PASSWORD=x export LIBEUFIN_NEXUS_URL=http://localhost:8082/ + cd $MY_TMP_DIR PAIN_UUID=`libeufin-cli accounts list-payments exchange-nexus | jq .initiatedPayments[] | jq 'select(.submitted==false)' | jq -r .paymentInitiationId` if test -z "${PAIN_UUID}" then @@ -318,6 +325,7 @@ function run_audit () { echo -n "Running submitting payment ${PAIN_UUID} ..." libeufin-cli accounts submit-payments --payment-uuid ${PAIN_UUID} exchange-nexus fi + cd $ORIGIN echo " DONE" fi audit_only @@ -330,16 +338,18 @@ function full_reload() { echo "Doing full reload of the database ($BASEDB - $DB)... " dropdb $DB 2> /dev/null || true - rm -f ${DB}-nexus.sqlite3 ${DB}-sandbox.sqlite3 2> /dev/null || true # libeufin createdb -T template0 $DB || exit_skip "could not create database $DB (at $PGHOST)" # Import pre-generated database, -q(ietly) using single (-1) transaction psql -Aqt $DB -q -1 -f ${BASEDB}.sql > /dev/null || exit_skip "Failed to load database $DB from ${BASEDB}.sql" echo "DONE" + cd $MYDIR + rm -f ${DB}-nexus.sqlite3 ${DB}-sandbox.sqlite3 2> /dev/null || true # libeufin echo -n "Loading libeufin Nexus basedb: ${BASEDB}-libeufin-nexus.sql " sqlite3 ${DB}-nexus.sqlite3 < ${BASEDB}-libeufin-nexus.sql || exit_skip "Failed to load Nexus database" echo "DONE" echo -n "Loading libeufin Sandbox basedb: ${BASEDB}-libeufin-sandbox.sql " sqlite3 ${DB}-sandbox.sqlite3 < ${BASEDB}-libeufin-sandbox.sql || exit_skip "Failed to load Sandbox database" + cd $ORIGIN echo "DONE" } @@ -834,10 +844,12 @@ function test_7() { function test_8() { echo "===========8: wire-transfer-subject disagreement===========" + cd $MYDIR OLD_ID=`echo "SELECT id FROM NexusBankTransactions WHERE amount='10' AND currency='TESTKUDOS' ORDER BY id LIMIT 1;" | sqlite3 ${DB}-nexus.sqlite3` OLD_WTID=`echo "SELECT reservePublicKey FROM TalerIncomingPayments WHERE payment='$OLD_ID';" | sqlite3 ${DB}-nexus.sqlite3` NEW_WTID="CK9QBFY972KR32FVA1MW958JWACEB6XCMHHKVFMCH1A780Q12SVG" echo "UPDATE TalerIncomingPayments SET reservePublicKey='$NEW_WTID' WHERE payment='$OLD_ID';" | sqlite3 ${DB}-nexus.sqlite3 + cd $ORIGIN run_audit @@ -894,7 +906,9 @@ function test_8() { echo PASS # Undo database modification + cd $MYDIR echo "UPDATE TalerIncomingPayments SET reservePublicKey='$OLD_WTID' WHERE payment='$OLD_ID';" | sqlite3 ${DB}-nexus.sqlite3 + cd $ORIGIN } @@ -903,9 +917,9 @@ function test_8() { function test_9() { echo "===========9: wire-origin disagreement===========" - OLD_ID=`echo "SELECT id FROM NexusBankTransactions WHERE amount='10' AND currency='TESTKUDOS' ORDER BY id LIMIT 1;" | sqlite3 ${DB}-nexus.sqlite3` - OLD_ACC=`echo "SELECT incomingPaytoUri FROM TalerIncomingPayments WHERE payment='$OLD_ID';" | sqlite3 ${DB}-nexus.sqlite3` - echo "UPDATE TalerIncomingPayments SET incomingPaytoUri='payto://iban/SANDBOXX/DE144373?receiver-name=New+Exchange+Company' WHERE payment='$OLD_ID';" | sqlite3 ${DB}-nexus.sqlite3 + OLD_ID=`echo "SELECT id FROM NexusBankTransactions WHERE amount='10' AND currency='TESTKUDOS' ORDER BY id LIMIT 1;" | sqlite3 ${MYDIR}/${DB}-nexus.sqlite3` + OLD_ACC=`echo "SELECT incomingPaytoUri FROM TalerIncomingPayments WHERE payment='$OLD_ID';" | sqlite3 ${MYDIR}/${DB}-nexus.sqlite3` + echo "UPDATE TalerIncomingPayments SET incomingPaytoUri='payto://iban/SANDBOXX/DE144373?receiver-name=New+Exchange+Company' WHERE payment='$OLD_ID';" | sqlite3 ${MYDIR}/${DB}-nexus.sqlite3 run_audit @@ -923,7 +937,7 @@ function test_9() { echo PASS # Undo database modification - echo "UPDATE TalerIncomingPayments SET incomingPaytoUri='$OLD_ACC' WHERE payment='$OLD_ID';" | sqlite3 ${DB}-nexus.sqlite3 + echo "UPDATE TalerIncomingPayments SET incomingPaytoUri='$OLD_ACC' WHERE payment='$OLD_ID';" | sqlite3 ${MYDIR}/${DB}-nexus.sqlite3 } @@ -932,9 +946,9 @@ function test_9() { function test_10() { NOW_MS=`date +%s`000 echo "===========10: wire-timestamp disagreement===========" - OLD_ID=`echo "SELECT id FROM NexusBankTransactions WHERE amount='10' AND currency='TESTKUDOS' ORDER BY id LIMIT 1;" | sqlite3 ${DB}-nexus.sqlite3` - OLD_DATE=`echo "SELECT timestampMs FROM TalerIncomingPayments WHERE payment='$OLD_ID';" | sqlite3 ${DB}-nexus.sqlite3` - echo "UPDATE TalerIncomingPayments SET timestampMs=$NOW_MS WHERE payment=$OLD_ID;" | sqlite3 ${DB}-nexus.sqlite3 + OLD_ID=`echo "SELECT id FROM NexusBankTransactions WHERE amount='10' AND currency='TESTKUDOS' ORDER BY id LIMIT 1;" | sqlite3 ${MYDIR}/${DB}-nexus.sqlite3` + OLD_DATE=`echo "SELECT timestampMs FROM TalerIncomingPayments WHERE payment='$OLD_ID';" | sqlite3 ${MYDIR}/${DB}-nexus.sqlite3` + echo "UPDATE TalerIncomingPayments SET timestampMs=$NOW_MS WHERE payment=$OLD_ID;" | sqlite3 ${MYDIR}/${DB}-nexus.sqlite3 run_audit @@ -952,7 +966,7 @@ function test_10() { echo PASS # Undo database modification - echo "UPDATE TalerIncomingPayments SET timestampMs='$OLD_DATE' WHERE payment=$OLD_ID;" | sqlite3 ${DB}-nexus.sqlite3 + echo "UPDATE TalerIncomingPayments SET timestampMs='$OLD_DATE' WHERE payment=$OLD_ID;" | sqlite3 ${MYDIR}/${DB}-nexus.sqlite3 } @@ -962,25 +976,25 @@ function test_10() { # ingested table: '.batches[0].batchTransactions[0].details.unstructuredRemittanceInformation' function test_11() { echo "===========11: spurious outgoing transfer ===========" - OLD_ID=`echo "SELECT id FROM NexusBankTransactions WHERE amount='10' AND currency='TESTKUDOS' ORDER BY id LIMIT 1;" | sqlite3 ${DB}-nexus.sqlite3` - OLD_TX=`echo "SELECT transactionJson FROM NexusBankTransactions WHERE id='$OLD_ID';" | sqlite3 ${DB}-nexus.sqlite3` + OLD_ID=`echo "SELECT id FROM NexusBankTransactions WHERE amount='10' AND currency='TESTKUDOS' ORDER BY id LIMIT 1;" | sqlite3 ${MYDIR}/${DB}-nexus.sqlite3` + OLD_TX=`echo "SELECT transactionJson FROM NexusBankTransactions WHERE id='$OLD_ID';" | sqlite3 ${MYDIR}/${DB}-nexus.sqlite3` # Change wire transfer to be FROM the exchange (#2) to elsewhere! # (Note: this change also causes a missing incoming wire transfer, but # this test is only concerned about the outgoing wire transfer # being detected as such, and we simply ignore the other # errors being reported.) - OTHER_IBAN=`echo -e "SELECT iban FROM BankAccounts WHERE label='fortytwo'" | sqlite3 ${DB}-sandbox.sqlite3` + OTHER_IBAN=`echo -e "SELECT iban FROM BankAccounts WHERE label='fortytwo'" | sqlite3 ${MYDIR}/${DB}-sandbox.sqlite3` NEW_TX=$(echo "$OLD_TX" | jq .batches[0].batchTransactions[0].details.creditDebitIndicator='"DBIT"' | jq 'del(.batches[0].batchTransactions[0].details.debtor)' | jq 'del(.batches[0].batchTransactions[0].details.debtorAccount)' | jq 'del(.batches[0].batchTransactions[0].details.debtorAgent)' | jq '.batches[0].batchTransactions[0].details.creditor'='{"name": "Forty Two"}' | jq .batches[0].batchTransactions[0].details.creditorAccount='{"iban": "'$OTHER_IBAN'"}' | jq .batches[0].batchTransactions[0].details.creditorAgent='{"bic": "SANDBOXX"}' | jq .batches[0].batchTransactions[0].details.unstructuredRemittanceInformation='"CK9QBFY972KR32FVA1MW958JWACEB6XCMHHKVFMCH1A780Q12SVG http://exchange.example.com/"') - echo -e "UPDATE NexusBankTransactions SET transactionJson='"$NEW_TX"' WHERE id=$OLD_ID" | sqlite3 ${DB}-nexus.sqlite3 + echo -e "UPDATE NexusBankTransactions SET transactionJson='"$NEW_TX"' WHERE id=$OLD_ID" | sqlite3 ${MYDIR}/${DB}-nexus.sqlite3 # Now fake that the exchange prepared this payment (= it POSTed to /transfer) # This step is necessary, because the TWG table that accounts for outgoing # payments needs it. Worth noting here is the column 'rawConfirmation' that # points to the transaction from the main Nexus ledger; without that column set, # a prepared payment won't appear as actually outgoing. - echo -e "INSERT INTO PaymentInitiations (bankAccount,preparationDate,submissionDate,sum,currency,endToEndId,paymentInformationId,instructionId,subject,creditorIban,creditorBic,creditorName,submitted,messageId,rawConfirmation) VALUES (1,1,1,10,'TESTKUDOS','NOTGIVEN','unused','unused','CK9QBFY972KR32FVA1MW958JWACEB6XCMHHKVFMCH1A780Q12SVG http://exchange.example.com/','"$OTHER_IBAN"','SANDBOXX','Forty Two','unused',1,$OLD_ID)" | sqlite3 ${DB}-nexus.sqlite3 + echo -e "INSERT INTO PaymentInitiations (bankAccount,preparationDate,submissionDate,sum,currency,endToEndId,paymentInformationId,instructionId,subject,creditorIban,creditorBic,creditorName,submitted,messageId,rawConfirmation) VALUES (1,1,1,10,'TESTKUDOS','NOTGIVEN','unused','unused','CK9QBFY972KR32FVA1MW958JWACEB6XCMHHKVFMCH1A780Q12SVG http://exchange.example.com/','"$OTHER_IBAN"','SANDBOXX','Forty Two','unused',1,$OLD_ID)" | sqlite3 ${MYDIR}/${DB}-nexus.sqlite3 # Now populate the TWG table that accounts for outgoing payments, in # order to let /history/outgoing return one result. - echo -e "INSERT INTO TalerRequestedPayments (facade,payment,requestUid,amount,exchangeBaseUrl,wtid,creditAccount) VALUES (1,1,'unused','TESTKUDOS:10','http://exchange.example.com/','CK9QBFY972KR32FVA1MW958JWACEB6XCMHHKVFMCH1A780Q12SVG','payto://iban/SANDBOXX/"$OTHER_IBAN"?receiver-name=Forty+Two')" | sqlite3 ${DB}-nexus.sqlite3 + echo -e "INSERT INTO TalerRequestedPayments (facade,payment,requestUid,amount,exchangeBaseUrl,wtid,creditAccount) VALUES (1,1,'unused','TESTKUDOS:10','http://exchange.example.com/','CK9QBFY972KR32FVA1MW958JWACEB6XCMHHKVFMCH1A780Q12SVG','payto://iban/SANDBOXX/"$OTHER_IBAN"?receiver-name=Forty+Two')" | sqlite3 ${MYDIR}/${DB}-nexus.sqlite3 run_audit @@ -1013,11 +1027,11 @@ function test_11() { echo PASS # Undo database modification - echo -e "UPDATE NexusBankTransactions SET transactionJson='"$OLD_TX"' WHERE id=$OLD_ID;" | sqlite3 ${DB}-nexus.sqlite3 + echo -e "UPDATE NexusBankTransactions SET transactionJson='"$OLD_TX"' WHERE id=$OLD_ID;" | sqlite3 ${MYDIR}/${DB}-nexus.sqlite3 # No other prepared payment should exist at this point, # so OK to remove the number 1. - echo -e "DELETE FROM PaymentInitiations WHERE id=1" | sqlite3 ${DB}-nexus.sqlite3 - echo -e "DELETE FROM TalerRequestedPayments WHERE id=1" | sqlite3 ${DB}-nexus.sqlite3 + echo -e "DELETE FROM PaymentInitiations WHERE id=1" | sqlite3 ${MYDIR}/${DB}-nexus.sqlite3 + echo -e "DELETE FROM TalerRequestedPayments WHERE id=1" | sqlite3 ${MYDIR}/${DB}-nexus.sqlite3 } # Test for hanging/pending refresh. @@ -1159,9 +1173,9 @@ function test_16() { # (Only one payment out exist, so the logic below should select the outgoing # wire transfer): function test_16_db () { - OLD_AMOUNT=`echo "SELECT amount FROM TalerRequestedPayments WHERE id='1';" | sqlite3 ${DB}-nexus.sqlite3` + OLD_AMOUNT=`echo "SELECT amount FROM TalerRequestedPayments WHERE id='1';" | sqlite3 ${MYDIR}/${DB}-nexus.sqlite3` NEW_AMOUNT="TESTKUDOS:50" - echo "UPDATE TalerRequestedPayments SET amount='${NEW_AMOUNT}' WHERE id='1';" | sqlite3 ${DB}-nexus.sqlite3 + echo "UPDATE TalerRequestedPayments SET amount='${NEW_AMOUNT}' WHERE id='1';" | sqlite3 ${MYDIR}/${DB}-nexus.sqlite3 } echo -n Trying to patch the SQLite database.. for try in `seq 1 10`; do @@ -1204,7 +1218,7 @@ function test_16() { echo "Second modification: wire nothing" NEW_AMOUNT="TESTKUDOS:0" - echo "UPDATE TalerRequestedPayments SET amount='${NEW_AMOUNT}' WHERE id='1';" | sqlite3 ${DB}-nexus.sqlite3 + echo "UPDATE TalerRequestedPayments SET amount='${NEW_AMOUNT}' WHERE id='1';" | sqlite3 ${MYDIR}/${DB}-nexus.sqlite3 audit_only echo -n "Testing inconsistency detection... " @@ -1254,12 +1268,12 @@ function test_17() { # wire transfer). function test_17_db () { OLD_ID=1 - OLD_PREP=`echo "SELECT payment FROM TalerRequestedPayments WHERE id='${OLD_ID}';" | sqlite3 ${DB}-nexus.sqlite3` - OLD_DATE=`echo "SELECT preparationDate FROM PaymentInitiations WHERE id='${OLD_ID}';" | sqlite3 ${DB}-nexus.sqlite3` + OLD_PREP=`echo "SELECT payment FROM TalerRequestedPayments WHERE id='${OLD_ID}';" | sqlite3 ${MYDIR}/${DB}-nexus.sqlite3` + OLD_DATE=`echo "SELECT preparationDate FROM PaymentInitiations WHERE id='${OLD_ID}';" | sqlite3 ${MYDIR}/${DB}-nexus.sqlite3` # Note: need - interval '1h' as "NOW()" may otherwise be exactly what is already in the DB # (due to rounding, if this machine is fast...) NOW_1HR=$(expr $(date +%s) - 3600) - echo "UPDATE PaymentInitiations SET preparationDate='$NOW_1HR' WHERE id='${OLD_PREP}';" | sqlite3 ${DB}-nexus.sqlite3 + echo "UPDATE PaymentInitiations SET preparationDate='$NOW_1HR' WHERE id='${OLD_PREP}';" | sqlite3 ${MYDIR}/${DB}-nexus.sqlite3 } echo -n Trying to patch the SQLite database.. for try in `seq 1 10`; do @@ -1422,7 +1436,7 @@ function test_21() { # remove transaction from bank DB # Currently emulating this (to be deleted): - echo "DELETE FROM TalerRequestedPayments WHERE amount='TESTKUDOS:${VAL_DELTA}'" | sqlite3 ${DB}-nexus.sqlite3 + echo "DELETE FROM TalerRequestedPayments WHERE amount='TESTKUDOS:${VAL_DELTA}'" | sqlite3 ${MYDIR}/${DB}-nexus.sqlite3 audit_only post_audit @@ -1673,14 +1687,14 @@ function test_27() { pre_audit aggregator # Obtain data to duplicate. - WTID=`echo SELECT wtid FROM TalerRequestedPayments WHERE id=1 | sqlite3 ${DB}-nexus.sqlite3` + WTID=`echo SELECT wtid FROM TalerRequestedPayments WHERE id=1 | sqlite3 ${MYDIR}/${DB}-nexus.sqlite3` echo WTID=$WTID - OTHER_IBAN=`echo -e "SELECT iban FROM BankAccounts WHERE label='fortytwo'" | sqlite3 ${DB}-sandbox.sqlite3` + OTHER_IBAN=`echo -e "SELECT iban FROM BankAccounts WHERE label='fortytwo'" | sqlite3 ${MYDIR}/${DB}-sandbox.sqlite3` stop_libeufin # 'rawConfirmation' is set to 2 here, that doesn't # point to any record. That's only needed to set a non null value. - echo -e "INSERT INTO PaymentInitiations (bankAccount,preparationDate,submissionDate,sum,currency,endToEndId,paymentInformationId,instructionId,subject,creditorIban,creditorBic,creditorName,submitted,messageId,rawConfirmation) VALUES (1,$(date +%s),$(expr $(date +%s) + 2),10,'TESTKUDOS','NOTGIVEN','unused','unused','$WTID http://exchange.example.com/','$OTHER_IBAN','SANDBOXX','Forty Two','unused',1,2)" | sqlite3 ${DB}-nexus.sqlite3 - echo -e "INSERT INTO TalerRequestedPayments (facade,payment,requestUid,amount,exchangeBaseUrl,wtid,creditAccount) VALUES (1,2,'unused','TESTKUDOS:1','http://exchange.example.com/','$WTID','payto://iban/SANDBOXX/$OTHER_IBAN?receiver-name=Forty+Two')" | sqlite3 ${DB}-nexus.sqlite3 + echo -e "INSERT INTO PaymentInitiations (bankAccount,preparationDate,submissionDate,sum,currency,endToEndId,paymentInformationId,instructionId,subject,creditorIban,creditorBic,creditorName,submitted,messageId,rawConfirmation) VALUES (1,$(date +%s),$(expr $(date +%s) + 2),10,'TESTKUDOS','NOTGIVEN','unused','unused','$WTID http://exchange.example.com/','$OTHER_IBAN','SANDBOXX','Forty Two','unused',1,2)" | sqlite3 ${MYDIR}/${DB}-nexus.sqlite3 + echo -e "INSERT INTO TalerRequestedPayments (facade,payment,requestUid,amount,exchangeBaseUrl,wtid,creditAccount) VALUES (1,2,'unused','TESTKUDOS:1','http://exchange.example.com/','$WTID','payto://iban/SANDBOXX/$OTHER_IBAN?receiver-name=Forty+Two')" | sqlite3 ${MYDIR}/${DB}-nexus.sqlite3 launch_libeufin audit_only post_audit @@ -2004,6 +2018,8 @@ function check_with_database() { BASEDB=$1 CONF=$1.conf + ORIGIN=`pwd` + MY_TMP_DIR=`dirname $1` echo "Running test suite with database $BASEDB using configuration $CONF" MASTER_PRIV_FILE=${BASEDB}.mpriv taler-config -f -c ${CONF} -s exchange-offline -o MASTER_PRIV_FILE -V ${MASTER_PRIV_FILE} @@ -2063,11 +2079,14 @@ else echo " FOUND at" `dirname $HAVE_INITDB` INITDB_BIN=`echo $HAVE_INITDB | grep bin/initdb | grep postgres | sort -n | tail -n1` fi -echo -n "Setting up Postgres DB" POSTGRES_PATH=`dirname $INITDB_BIN` -TMPDIR=`mktemp -d /tmp/taler-test-postgresXXXXXX` -$INITDB_BIN --no-sync --auth=trust -D ${TMPDIR} > postgres-dbinit.log 2> postgres-dbinit.err -echo " DONE" +MYDIR=`mktemp -d /tmp/taler-auditor-basedbXXXXXX` +echo "Using $MYDIR for logging and temporary data" +TMPDIR="$MYDIR/postgres/" +mkdir -p $TMPDIR +echo -n "Setting up Postgres DB at $TMPDIR ..." +$INITDB_BIN --no-sync --auth=trust -D ${TMPDIR} > ${MYDIR}/postgres-dbinit.log 2> ${MYDIR}/postgres-dbinit.err +echo "DONE" mkdir ${TMPDIR}/sockets echo -n "Launching Postgres service" cat - >> $TMPDIR/postgresql.conf < $TMPDIR/pg_hba.conf.new mv $TMPDIR/pg_hba.conf.new $TMPDIR/pg_hba.conf -${POSTGRES_PATH}/pg_ctl -D $TMPDIR -l /dev/null start > postgres-start.log 2> postgres-start.err +${POSTGRES_PATH}/pg_ctl -D $TMPDIR -l /dev/null start > ${MYDIR}/postgres-start.log 2> ${MYDIR}/postgres-start.err echo " DONE" PGHOST="$TMPDIR/sockets" export PGHOST -MYDIR=`mktemp -d /tmp/taler-auditor-basedbXXXXXX` echo "Generating fresh database at $MYDIR" -rm -f ${DB}-nexus.sqlite3 ${DB}-sandbox.sqlite3 2> /dev/null || true # libeufin if faketime -f '-1 d' ./generate-auditor-basedb.sh $MYDIR/$DB then check_with_database $MYDIR/$DB @@ -2097,7 +2114,6 @@ then else echo "Cleaning up $MYDIR..." rm -rf $MYDIR || echo "Removing $MYDIR failed" - rm -rf $TMPDIR || echo "Removing $TMPDIR failed" fi else echo "Generation failed" diff --git a/src/auditor/test-revocation.sh b/src/auditor/test-revocation.sh index db36bf034..44971c595 100755 --- a/src/auditor/test-revocation.sh +++ b/src/auditor/test-revocation.sh @@ -54,27 +54,24 @@ function exit_fail() { exit 1 } -# Clean up leftovers on start -rm -f libeufin-sandbox.pid libeufin-nexus.pid - function stop_libeufin() { echo "killing libeufin..." - if test -f libeufin-sandbox.pid + if test -f ${MYDIR:-/}/libeufin-sandbox.pid then echo "Killing libeufin sandbox" - PID=`cat libeufin-sandbox.pid 2> /dev/null` + PID=`cat ${MYDIR}/libeufin-sandbox.pid 2> /dev/null` + rm ${MYDIR}/libeufin-sandbox.pid kill $PID 2> /dev/null || true wait $PID || true - rm libeufin-sandbox.pid fi - if test -f libeufin-nexus.pid + if test -f ${MYDIR:-/}/libeufin-nexus.pid then echo "Killing libeufin nexus" - PID=`cat libeufin-nexus.pid 2> /dev/null` + PID=`cat ${MYDIR}/libeufin-nexus.pid 2> /dev/null` + rm ${MYDIR}/libeufin-nexus.pid kill $PID 2> /dev/null || true wait $PID || true - rm libeufin-nexus.pid fi echo "killing libeufin DONE" } @@ -148,16 +145,18 @@ function get_payto_uri() { function launch_libeufin () { export LIBEUFIN_NEXUS_DB_CONNECTION="jdbc:sqlite:${DB}-nexus.sqlite3" + cd $MYDIR libeufin-nexus serve --port 8082 \ - 2> libeufin-nexus-stderr.log \ - > libeufin-nexus-stdout.log & - echo $! > libeufin-nexus.pid + 2> ${MYDIR}/libeufin-nexus-stderr.log \ + > ${MYDIR}/libeufin-nexus-stdout.log & + echo $! > ${MYDIR}/libeufin-nexus.pid export LIBEUFIN_SANDBOX_DB_CONNECTION="jdbc:sqlite:${DB}-sandbox.sqlite3" export LIBEUFIN_SANDBOX_ADMIN_PASSWORD=secret libeufin-sandbox serve --port 18082 \ - > libeufin-sandbox-stdout.log \ - 2> libeufin-sandbox-stderr.log & - echo $! > libeufin-sandbox.pid + > ${MYDIR}/libeufin-sandbox-stdout.log \ + 2> ${MYDIR}/libeufin-sandbox-stderr.log & + echo $! > ${MYDIR}/libeufin-sandbox.pid + cd $ORIGIN } # Operations to run before the actual audit @@ -195,13 +194,13 @@ function pre_audit () { then export CONF echo -n "Running exchange aggregator ... (config: $CONF)" - taler-exchange-aggregator -L INFO -t -c $CONF -y 2> aggregator.log || exit_fail "FAIL" + taler-exchange-aggregator -L INFO -t -c $CONF -y 2> ${MYDIR}/aggregator.log || exit_fail "FAIL" echo " DONE" echo -n "Running exchange closer ..." - taler-exchange-closer -L INFO -t -c $CONF 2> closer.log || exit_fail "FAIL" + taler-exchange-closer -L INFO -t -c $CONF 2> ${MYDIR}/closer.log || exit_fail "FAIL" echo " DONE" echo -n "Running exchange transfer ..." - taler-exchange-transfer -L INFO -t -c $CONF 2> transfer.log || exit_fail "FAIL" + taler-exchange-transfer -L INFO -t -c $CONF 2> ${MYDIR}/transfer.log || exit_fail "FAIL" echo " DONE" echo -n "Running Nexus payment submitter ..." nexus_submit_to_sandbox @@ -276,11 +275,12 @@ function full_reload() { echo -n "Doing full reload of the database... " dropdb $DB 2> /dev/null || true - rm -f ${DB}-nexus.sqlite3 ${DB}-sandbox.sqlite3 || true # libeufin createdb -T template0 $DB || exit_skip "could not create database $DB (at $PGHOST)" # Import pre-generated database, -q(ietly) using single (-1) transaction psql -Aqt $DB -q -1 -f ${BASEDB}.sql > /dev/null || exit_skip "Failed to load database $DB from ${BASEDB}.sql" echo "DONE" + cd $MYDIR + rm -f ${DB}-nexus.sqlite3 ${DB}-sandbox.sqlite3 || true # libeufin echo "Loading libeufin Nexus basedb: ${BASEDB}-libeufin-nexus.sql" sqlite3 ${DB}-nexus.sqlite3 < ${BASEDB}-libeufin-nexus.sql || exit_skip "Failed to load Nexus database" echo "DONE" @@ -297,6 +297,7 @@ function full_reload() -V "payto://iban/SANDBOXX/$EXCHANGE_IBAN?receiver-name=Exchange+Company" echo " DONE" ) + cd $ORIGIN } @@ -612,7 +613,6 @@ function check_with_database() done # echo "Cleanup (disabled, leaving database $DB behind)" dropdb $DB - rm -f test-audit.log test-wire-audit.log } @@ -648,8 +648,12 @@ else fi echo -n "Setting up Postgres DB" POSTGRES_PATH=`dirname $INITDB_BIN` -TMPDIR=`mktemp -d /tmp/taler-test-postgresXXXXXX` -$INITDB_BIN --no-sync --auth=trust -D ${TMPDIR} > postgres-dbinit.log 2> postgres-dbinit.err +ORIGIN=`pwd` +MYDIR=`mktemp -d /tmp/taler-auditor-basedbXXXXXX` +TMPDIR="${MYDIR}/postgres/" +mkdir -p $TMPDIR +echo -n "Setting up Postgres DB at $TMPDIR ..." +$INITDB_BIN --no-sync --auth=trust -D ${TMPDIR} > ${MYDIR}/postgres-dbinit.log 2> ${MYDIR}/postgres-dbinit.err echo " DONE" mkdir ${TMPDIR}/sockets echo -n "Launching Postgres service at $POSTGRES_PATH" @@ -663,12 +667,11 @@ listen_addresses='' EOF cat $TMPDIR/pg_hba.conf | grep -v host > $TMPDIR/pg_hba.conf.new mv $TMPDIR/pg_hba.conf.new $TMPDIR/pg_hba.conf -${POSTGRES_PATH}/pg_ctl -D $TMPDIR -l /dev/null start > postgres-start.log 2> postgres-start.err +${POSTGRES_PATH}/pg_ctl -D $TMPDIR -l /dev/null start > ${MYDIR}/postgres-start.log 2> ${MYDIR}/postgres-start.err echo " DONE" PGHOST="$TMPDIR/sockets" export PGHOST -MYDIR=`mktemp -d /tmp/taler-auditor-basedbXXXXXX` echo "Generating fresh database at $MYDIR" if faketime -f '-1 d' ./generate-revoke-basedb.sh $MYDIR/$DB then @@ -679,7 +682,6 @@ then else echo "Cleaning up $MYDIR..." rm -rf $MYDIR || echo "Removing $MYDIR failed" - rm -rf $TMPDIR || echo "Removing $TMPDIR failed" fi else echo "Generation failed" -- cgit v1.2.3