-work on auditor test

This commit is contained in:
Christian Grothoff 2023-07-18 00:36:48 +02:00
parent e6023a54b9
commit f7fad83a82
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
2 changed files with 44 additions and 58 deletions

View File

@ -76,7 +76,7 @@ mkdir -p "$(dirname "$BASEDB")"
echo "Dumping database ${BASEDB}.sql" echo "Dumping database ${BASEDB}.sql"
pg_dump -O "auditor-basedb" | sed -e '/AS integer/d' > "${BASEDB}.sql" pg_dump -O "auditor-basedb" | sed -e '/AS integer/d' > "${BASEDB}.sql"
cp "${CONF}.edited" "${BASEDB}.conf" cp "${CONF}.edited" "${BASEDB}.conf"
cp "$(taler-config -s exchange-offline -o MASTER_PRIV_FILE -f)" "${BASEDB}.mpriv" cp "$(taler-config -c "${CONF}.edited" -s exchange-offline -o MASTER_PRIV_FILE -f)" "${BASEDB}.mpriv"
# clean up # clean up
echo -n "Final clean up ..." echo -n "Final clean up ..."

View File

@ -58,24 +58,24 @@ LIBEUFIN_SETTLE_TIME=1
# Stop libeufin sandbox and nexus (if running) # Stop libeufin sandbox and nexus (if running)
function stop_libeufin() function stop_libeufin()
{ {
echo "Stopping libeufin..." echo -n "Stopping libeufin... "
if test -f ${MYDIR:-/}/libeufin-sandbox.pid if test -f ${MY_TMP_DIR:-/}/libeufin-sandbox.pid
then then
PID=$(cat ${MYDIR}/libeufin-sandbox.pid 2> /dev/null) PID=$(cat ${MY_TMP_DIR}/libeufin-sandbox.pid 2> /dev/null)
echo "Killing libeufin sandbox $PID" echo "Killing libeufin sandbox $PID"
rm "${MYDIR}/libeufin-sandbox.pid" rm "${MY_TMP_DIR}/libeufin-sandbox.pid"
kill "$PID" 2> /dev/null || true kill "$PID" 2> /dev/null || true
wait "$PID" || true wait "$PID" || true
fi fi
if test -f ${MYDIR:-/}/libeufin-nexus.pid if test -f ${MY_TMP_DIR:-/}/libeufin-nexus.pid
then then
PID=$(cat ${MYDIR}/libeufin-nexus.pid 2> /dev/null) PID=$(cat ${MY_TMP_DIR}/libeufin-nexus.pid 2> /dev/null)
echo "Killing libeufin nexus $PID" echo "Killing libeufin nexus $PID"
rm "${MYDIR}/libeufin-nexus.pid" rm "${MY_TMP_DIR}/libeufin-nexus.pid"
kill "$PID" 2> /dev/null || true kill "$PID" 2> /dev/null || true
wait "$PID" || true wait "$PID" || true
fi fi
echo "Stopping libeufin DONE" echo "DONE"
} }
# Cleanup exchange and libeufin between runs. # Cleanup exchange and libeufin between runs.
@ -119,20 +119,19 @@ function exit_cleanup()
trap exit_cleanup EXIT trap exit_cleanup EXIT
function launch_libeufin () { function launch_libeufin () {
cd "$MYDIR"
# shellcheck disable=SC2016 # shellcheck disable=SC2016
export LIBEUFIN_SANDBOX_DB_CONNECTION='jdbc:postgresql://localhost/auditor-basedb?socketFactory=org.newsclub.net.unix.AFUNIXSocketFactory$FactoryArg&socketFactoryArg=/var/run/postgresql/.s.PGSQL.5432' export LIBEUFIN_SANDBOX_DB_CONNECTION='jdbc:postgresql://localhost/'"${DB}"'?socketFactory=org.newsclub.net.unix.AFUNIXSocketFactory$FactoryArg&socketFactoryArg='"$SOCKETDIR"'/.s.PGSQL.5432'
export MY_TMP_DIR
libeufin-sandbox serve --no-auth --port 18082 \ libeufin-sandbox serve --no-auth --port 18082 \
> "${MYDIR}/libeufin-sandbox-stdout.log" \ > "${MY_TMP_DIR}/libeufin-sandbox-stdout.log" \
2> "${MYDIR}/libeufin-sandbox-stderr.log" & 2> "${MY_TMP_DIR}/libeufin-sandbox-stderr.log" &
echo $! > "${MYDIR}/libeufin-sandbox.pid" echo $! > "${MY_TMP_DIR}/libeufin-sandbox.pid"
# shellcheck disable=SC2016 # shellcheck disable=SC2016
export LIBEUFIN_NEXUS_DB_CONNECTION='jdbc:postgresql://localhost/auditor-basedb?socketFactory=org.newsclub.net.unix.AFUNIXSocketFactory$FactoryArg&socketFactoryArg=/var/run/postgresql/.s.PGSQL.5432' export LIBEUFIN_NEXUS_DB_CONNECTION='jdbc:postgresql://localhost/'"${DB}"'?socketFactory=org.newsclub.net.unix.AFUNIXSocketFactory$FactoryArg&socketFactoryArg='"$SOCKETDIR"'/.s.PGSQL.5432'
libeufin-nexus serve --port 8082 \ libeufin-nexus serve --port 8082 \
2> "${MYDIR}/libeufin-nexus-stderr.log" \ 2> "${MY_TMP_DIR}/libeufin-nexus-stderr.log" \
> "${MYDIR}/libeufin-nexus-stdout.log" & > "${MY_TMP_DIR}/libeufin-nexus-stdout.log" &
echo $! > "${MYDIR}/libeufin-nexus.pid" echo $! > "${MY_TMP_DIR}/libeufin-nexus.pid"
cd "$ORIGIN"
} }
# Downloads new transactions from the bank. # Downloads new transactions from the bank.
@ -140,12 +139,11 @@ function nexus_fetch_transactions () {
export LIBEUFIN_NEXUS_USERNAME="exchange" export LIBEUFIN_NEXUS_USERNAME="exchange"
export LIBEUFIN_NEXUS_PASSWORD="x" export LIBEUFIN_NEXUS_PASSWORD="x"
export LIBEUFIN_NEXUS_URL="http://localhost:8082/" export LIBEUFIN_NEXUS_URL="http://localhost:8082/"
cd "$MY_TMP_DIR" libeufin-cli accounts \
libeufin-cli accounts fetch-transactions \ fetch-transactions \
--range-type since-last \ --range-type since-last \
--level report \ --level report \
exchange-nexus > /dev/null exchange-nexus > /dev/null
cd "$ORIGIN"
unset LIBEUFIN_NEXUS_USERNAME unset LIBEUFIN_NEXUS_USERNAME
unset LIBEUFIN_NEXUS_PASSWORD unset LIBEUFIN_NEXUS_PASSWORD
unset LIBEUFIN_NEXUS_URL unset LIBEUFIN_NEXUS_URL
@ -158,10 +156,9 @@ function nexus_submit_to_sandbox () {
export LIBEUFIN_NEXUS_USERNAME="exchange" export LIBEUFIN_NEXUS_USERNAME="exchange"
export LIBEUFIN_NEXUS_PASSWORD="x" export LIBEUFIN_NEXUS_PASSWORD="x"
export LIBEUFIN_NEXUS_URL="http://localhost:8082/" export LIBEUFIN_NEXUS_URL="http://localhost:8082/"
cd "$MY_TMP_DIR" libeufin-cli accounts \
libeufin-cli accounts submit-payments\ submit-payments\
exchange-nexus exchange-nexus
cd "$ORIGIN"
unset LIBEUFIN_NEXUS_USERNAME unset LIBEUFIN_NEXUS_USERNAME
unset LIBEUFIN_NEXUS_PASSWORD unset LIBEUFIN_NEXUS_PASSWORD
unset LIBEUFIN_NEXUS_URL unset LIBEUFIN_NEXUS_URL
@ -212,7 +209,7 @@ function pre_audit () {
echo -n "Running exchange aggregator ..." echo -n "Running exchange aggregator ..."
taler-exchange-aggregator \ taler-exchange-aggregator \
-y \ -y \
-L INFO \ -L "INFO" \
-t \ -t \
-c "$CONF" \ -c "$CONF" \
2> "${MY_TMP_DIR}/aggregator.log" \ 2> "${MY_TMP_DIR}/aggregator.log" \
@ -220,7 +217,7 @@ function pre_audit () {
echo " DONE" echo " DONE"
echo -n "Running exchange closer ..." echo -n "Running exchange closer ..."
taler-exchange-closer \ taler-exchange-closer \
-L INFO\ -L "INFO" \
-t \ -t \
-c "$CONF" \ -c "$CONF" \
2> "${MY_TMP_DIR}/closer.log" \ 2> "${MY_TMP_DIR}/closer.log" \
@ -228,7 +225,7 @@ function pre_audit () {
echo " DONE" echo " DONE"
echo -n "Running exchange transfer ..." echo -n "Running exchange transfer ..."
taler-exchange-transfer \ taler-exchange-transfer \
-L INFO \ -L "INFO" \
-t \ -t \
-c "$CONF" \ -c "$CONF" \
2> "${MY_TMP_DIR}/transfer.log" \ 2> "${MY_TMP_DIR}/transfer.log" \
@ -390,7 +387,7 @@ function run_audit () {
taler-exchange-httpd \ taler-exchange-httpd \
-c "${CONF}" \ -c "${CONF}" \
-L INFO \ -L INFO \
2> "${MYDIR}/exchange-httpd-drain.err" & 2> "${MY_TMP_DIR}/exchange-httpd-drain.err" &
EPID=$! EPID=$!
# Wait for all services to be available # Wait for all services to be available
@ -444,7 +441,6 @@ function run_audit () {
export LIBEUFIN_NEXUS_USERNAME="exchange" export LIBEUFIN_NEXUS_USERNAME="exchange"
export LIBEUFIN_NEXUS_PASSWORD="x" export LIBEUFIN_NEXUS_PASSWORD="x"
export LIBEUFIN_NEXUS_URL="http://localhost:8082/" 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) PAIN_UUID=$(libeufin-cli accounts list-payments exchange-nexus | jq .initiatedPayments[] | jq 'select(.submitted==false)' | jq -r .paymentInitiationId)
if test -z "${PAIN_UUID}" if test -z "${PAIN_UUID}"
then then
@ -467,7 +463,6 @@ function run_audit () {
--level report \ --level report \
exchange-nexus exchange-nexus
echo " DONE" echo " DONE"
cd "$ORIGIN"
fi fi
audit_only audit_only
post_audit post_audit
@ -477,7 +472,7 @@ function run_audit () {
# Do a full reload of the (original) database # Do a full reload of the (original) database
function full_reload() function full_reload()
{ {
echo "Doing full reload of the database ($BASEDB - $DB)... " echo -n "Doing full reload of the database ($BASEDB - $DB)... "
dropdb "$DB" 2> /dev/null || true dropdb "$DB" 2> /dev/null || true
createdb -T template0 "$DB" \ createdb -T template0 "$DB" \
|| exit_skip "could not create database $DB (at $PGHOST)" || exit_skip "could not create database $DB (at $PGHOST)"
@ -491,7 +486,6 @@ function full_reload()
echo "DONE" echo "DONE"
# Technically, this call shouldn't be needed as libeufin should already be stopped here... # Technically, this call shouldn't be needed as libeufin should already be stopped here...
stop_libeufin stop_libeufin
echo "DONE"
} }
@ -1031,7 +1025,6 @@ function test_8() {
echo "===========8: wire-transfer-subject disagreement===========" echo "===========8: wire-transfer-subject disagreement==========="
# Technically, this call shouldn't be needed, as libeufin should already be stopped here. # Technically, this call shouldn't be needed, as libeufin should already be stopped here.
stop_libeufin stop_libeufin
cd "$MYDIR"
OLD_ID=$(echo "SELECT id FROM NexusBankTransactions WHERE amount='10' AND currency='TESTKUDOS' ORDER BY id LIMIT 1;" | psql "${DB}") \ OLD_ID=$(echo "SELECT id FROM NexusBankTransactions WHERE amount='10' AND currency='TESTKUDOS' ORDER BY id LIMIT 1;" | psql "${DB}") \
|| exit_fail "Failed to SELECT FROM NexusBankTransactions nexus DB!" || exit_fail "Failed to SELECT FROM NexusBankTransactions nexus DB!"
OLD_WTID=$(echo "SELECT reservePublicKey FROM TalerIncomingPayments WHERE payment='$OLD_ID';" \ OLD_WTID=$(echo "SELECT reservePublicKey FROM TalerIncomingPayments WHERE payment='$OLD_ID';" \
@ -1040,7 +1033,6 @@ function test_8() {
echo "UPDATE TalerIncomingPayments SET reservePublicKey='$NEW_WTID' WHERE payment='$OLD_ID';" \ echo "UPDATE TalerIncomingPayments SET reservePublicKey='$NEW_WTID' WHERE payment='$OLD_ID';" \
| psql "${DB}" \ | psql "${DB}" \
|| exit_fail "Failed to update TalerIncomingPayments" || exit_fail "Failed to update TalerIncomingPayments"
cd "$ORIGIN"
run_audit run_audit
@ -1097,10 +1089,8 @@ function test_8() {
echo "PASS" echo "PASS"
# Undo database modification # Undo database modification
cd "$MYDIR"
echo "UPDATE TalerIncomingPayments SET reservePublicKey='$OLD_WTID' WHERE payment='$OLD_ID';" \ echo "UPDATE TalerIncomingPayments SET reservePublicKey='$OLD_WTID' WHERE payment='$OLD_ID';" \
| psql "${DB}" | psql "${DB}"
cd "$ORIGIN"
} }
@ -2256,7 +2246,6 @@ function check_with_database()
BASEDB="$1" BASEDB="$1"
CONF="$1.conf" CONF="$1.conf"
ORIGIN=$(pwd) ORIGIN=$(pwd)
MY_TMP_DIR=$(dirname "$1")
echo "Running test suite with database $BASEDB using configuration $CONF" echo "Running test suite with database $BASEDB using configuration $CONF"
MASTER_PRIV_FILE="${BASEDB}.mpriv" MASTER_PRIV_FILE="${BASEDB}.mpriv"
taler-config \ taler-config \
@ -2292,7 +2281,7 @@ function check_with_database()
# *************** Main logic starts here ************** # *************** Main logic starts here **************
# ####### Setup globals ###### # ####### Setup globals ######
# Postgres database to use # Postgres database to use (must match configuration file)
export DB="auditor-basedb" export DB="auditor-basedb"
# test required commands exist # test required commands exist
@ -2321,19 +2310,21 @@ else
INITDB_BIN=$(echo "$HAVE_INITDB" | grep bin/initdb | grep postgres | sort -n | tail -n1) INITDB_BIN=$(echo "$HAVE_INITDB" | grep bin/initdb | grep postgres | sort -n | tail -n1)
fi fi
POSTGRES_PATH=$(dirname "$INITDB_BIN") POSTGRES_PATH=$(dirname "$INITDB_BIN")
MYDIR=$(mktemp -d /tmp/taler-auditor-basedbXXXXXX)
echo "Using $MYDIR for logging and temporary data" MY_TMP_DIR=$(mktemp -d /tmp/taler-auditor-basedbXXXXXX)
TMPDIR="$MYDIR/postgres/" echo "Using $MY_TMP_DIR for logging and temporary data"
TMPDIR="$MY_TMP_DIR/postgres"
mkdir -p "$TMPDIR" mkdir -p "$TMPDIR"
echo -n "Setting up Postgres DB at $TMPDIR ..." echo -n "Setting up Postgres DB at $TMPDIR ..."
$INITDB_BIN \ $INITDB_BIN \
--no-sync \ --no-sync \
--auth=trust \ --auth=trust \
-D "${TMPDIR}" \ -D "${TMPDIR}" \
> "${MYDIR}/postgres-dbinit.log" \ > "${MY_TMP_DIR}/postgres-dbinit.log" \
2> "${MYDIR}/postgres-dbinit.err" 2> "${MY_TMP_DIR}/postgres-dbinit.err"
echo "DONE" echo "DONE"
mkdir "${TMPDIR}/sockets" SOCKETDIR="${TMPDIR}/sockets"
mkdir "${SOCKETDIR}"
echo -n "Launching Postgres service" echo -n "Launching Postgres service"
cat - >> "$TMPDIR/postgresql.conf" <<EOF cat - >> "$TMPDIR/postgresql.conf" <<EOF
unix_socket_directories='${TMPDIR}/sockets' unix_socket_directories='${TMPDIR}/sockets'
@ -2351,24 +2342,22 @@ mv "$TMPDIR/pg_hba.conf.new" "$TMPDIR/pg_hba.conf"
-D "$TMPDIR" \ -D "$TMPDIR" \
-l /dev/null \ -l /dev/null \
start \ start \
> "${MYDIR}/postgres-start.log" \ > "${MY_TMP_DIR}/postgres-start.log" \
2> "${MYDIR}/postgres-start.err" 2> "${MY_TMP_DIR}/postgres-start.err"
echo " DONE" echo " DONE"
PGHOST="$TMPDIR/sockets" PGHOST="$TMPDIR/sockets"
export PGHOST export PGHOST
# FIXME... # FIXME: here for testing, avoids generation skip.
MYDIR=bar/ # Should probably introduce getopt to make this
DB=foo # possible via CLI.
# foo.sql check_with_database "bar/${DB}"
# foo.conf
# foo.mpriv
check_with_database "$MYDIR/$DB"
exit 0 exit 0
MYDIR="${MY_TMP_DIR}/basedb"
mkdir -p "${MYDIR}"
echo "Generating fresh database at $MYDIR" echo "Generating fresh database at $MYDIR"
if faketime -f '-1 d' ./generate-auditor-basedb.sh "$MYDIR/$DB" if faketime -f '-1 d' ./generate-auditor-basedb.sh "$MYDIR/$DB"
then then
@ -2376,9 +2365,6 @@ then
if [ "$fail" != "0" ] if [ "$fail" != "0" ]
then then
exit "$fail" exit "$fail"
else
echo "Cleaning up $MYDIR..."
rm -rf "$MYDIR" || echo "Removing $MYDIR failed"
fi fi
else else
echo "Generation failed" echo "Generation failed"