From f70596ff4c93a1906533fd488bf5fed1801eeb99 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 8 Feb 2020 18:38:15 +0100 Subject: adding UNIX socket and restart tests (#5309) --- contrib/taler-exchange-revoke | 2 +- src/exchange/Makefile.am | 4 +- src/exchange/test_taler_exchange_httpd_restart.sh | 117 ++++++++++++++++++ src/exchange/test_taler_exchange_unix.conf | 137 ++++++++++++++++++++++ 4 files changed, 258 insertions(+), 2 deletions(-) create mode 100755 src/exchange/test_taler_exchange_httpd_restart.sh create mode 100644 src/exchange/test_taler_exchange_unix.conf diff --git a/contrib/taler-exchange-revoke b/contrib/taler-exchange-revoke index 8ce0e8786..8e4bc6ed4 100755 --- a/contrib/taler-exchange-revoke +++ b/contrib/taler-exchange-revoke @@ -19,6 +19,6 @@ fi taler-exchange-keyup -c $1 -r $2 EXCHANGE_PID=`ps x | grep taler-exchange-httpd | awk '{print $1}'` -kill -HUP $EXCHANGE_PID +kill -SIGUSR1 $EXCHANGE_PID exit 0 diff --git a/src/exchange/Makefile.am b/src/exchange/Makefile.am index 50eb545b0..cf9f984de 100644 --- a/src/exchange/Makefile.am +++ b/src/exchange/Makefile.am @@ -83,7 +83,8 @@ taler_exchange_httpd_LDADD = \ AM_TESTS_ENVIRONMENT=export TALER_PREFIX=$${TALER_PREFIX:-@libdir@};export PATH=$${TALER_PREFIX:-@prefix@}/bin:$$PATH; check_SCRIPTS = \ - test_taler_exchange_httpd.sh + test_taler_exchange_httpd.sh \ + test_taler_exchange_httpd_restart.sh if HAVE_EXPENSIVE_TESTS check_SCRIPTS += \ test_taler_exchange_httpd_afl.sh @@ -97,6 +98,7 @@ TESTS = \ EXTRA_DIST = \ test_taler_exchange_httpd_home/.local/share/taler/exchange/offline-keys/master.priv \ test_taler_exchange_httpd.conf \ + test_taler_exchange_unix.conf \ test_taler_exchange_httpd.get \ test_taler_exchange_httpd.post \ exchange.conf \ diff --git a/src/exchange/test_taler_exchange_httpd_restart.sh b/src/exchange/test_taler_exchange_httpd_restart.sh new file mode 100755 index 000000000..81ac04550 --- /dev/null +++ b/src/exchange/test_taler_exchange_httpd_restart.sh @@ -0,0 +1,117 @@ +#!/bin/bash +# +# This file is part of TALER +# Copyright (C) 2020 Taler Systems SA +# +# TALER is free software; you can redistribute it and/or modify it under the +# terms of the GNU Affero General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# TALER is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License along with +# TALER; see the file COPYING. If not, If not, see +# +# +# This script launches an exchange (binding to a UNIX domain socket) and then +# restarts it in various ways (SIGHUP to re-read configuration, and SIGUSR1 to +# re-spawn a new binary). Basically, the goal is to make sure that the HTTP +# server survives these less common operations. +# +# +set -eu + +# Exit, with status code "skip" (no 'real' failure) +function exit_skip() { + echo $1 + exit 77 +} + +# Exit, with error message (hard failure) +function exit_fail() { + echo $1 + kill `jobs -p` >/dev/null 2>/dev/null || true + wait + exit 1 +} + +echo -n "Testing for curl" +curl --version >/dev/null /dev/null || exit 1 +# Run Exchange HTTPD (in background) +$PREFIX taler-exchange-httpd -c test_taler_exchange_unix.conf -i 2> test-exchange.log & + +# Where should we be bound to? +UNIXPATH=`taler-config -s exchange -f -o UNIXPATH` + +# Give HTTP time to start + +for n in `seq 1 100` +do + echo -n "." + sleep 0.1 + OK=1 + curl --unix-socket "${UNIXPATH}" "http://ignored/" >/dev/null 2> /dev/null && break + OK=0 +done +if [ 1 != $OK ] +then + echo "Failed to launch exchange" + kill -TERM $! + wait $! + echo Process status: $? + exit 77 +fi +echo " DONE" + +# Finally run test... +echo -n "Reloading keys ..." +kill -SIGUSR1 $! +sleep 1 +curl --unix-socket "${UNIXPATH}" "http://ignored/" >/dev/null 2> /dev/null || exit_fail "SIGUSR1 killed HTTP service" +echo " DONE" + +# Finally run test... +echo -n "Restarting program ..." +kill -SIGHUP $! +sleep 1 +curl --unix-socket "${UNIXPATH}" "http://ignored/" >/dev/null 2> /dev/null || exit_fail "SIGHUP killed HTTP service" +echo " DONE" + +echo -n "Waiting for parent to die ..." +wait $! +echo " DONE" + +echo -n "Testing child still alive ..." +curl --unix-socket "${UNIXPATH}" "http://ignored/" >/dev/null 2> /dev/null || exit_fail "SIGHUP killed HTTP service" +echo " DONE" + + +echo -n "Killing grandchild ..." +CPID=`ps x | grep taler-exchange-httpd | grep -v grep | awk '{print $1}'` +kill -TERM $CPID +while true +do + ps x | grep -v grep | grep taler-exchange-httpd > /dev/null || break +done +echo " DONE" + +# Return status code from exchange for this script +exit 0 diff --git a/src/exchange/test_taler_exchange_unix.conf b/src/exchange/test_taler_exchange_unix.conf new file mode 100644 index 000000000..d41df9abe --- /dev/null +++ b/src/exchange/test_taler_exchange_unix.conf @@ -0,0 +1,137 @@ +[PATHS] +# Persistant data storage for the testcase +TALER_TEST_HOME = test_taler_exchange_httpd_home/ + +[taler] +# Currency supported by the exchange (can only be one) +CURRENCY = EUR +CURRENCY_ROUND_UNIT = EUR:0.01 + +[exchange] + +# Directory with our terms of service. +TERMS_DIR = ../../contrib/tos + +# Etag / filename for the terms of service. +TERMS_ETAG = 0 + + +# Directory with our privacy policy. +PRIVACY_DIR = ../../contrib/pp + +# Etag / filename for the privacy policy. +PRIVACY_ETAG = 0 + +# MAX_REQUESTS = 2 +# how long is one signkey valid? +SIGNKEY_DURATION = 4 weeks + +# how long are the signatures with the signkey valid? +LEGAL_DURATION = 2 years + +# how long do we generate denomination and signing keys +# ahead of time? +LOOKAHEAD_SIGN = 32 weeks 1 day + +# how long do we provide to clients denomination and signing keys +# ahead of time? +LOOKAHEAD_PROVIDE = 4 weeks 1 day + +# HTTP port the exchange listens to (we want to use UNIX domain sockets, +# so we use a port that just won't work on GNU/Linux without root rights) +PORT = 999 + +# Here we say we want to use a UNIX domain socket (to test that logic). +SERVE = unix + +# Master public key used to sign the exchange's various keys +MASTER_PUBLIC_KEY = 98NJW3CQHZQGQXTY3K85K531XKPAPAVV4Q5V8PYYRR00NJGZWNVG + +# How to access our database +DB = postgres + + +[exchangedb] +# After how long do we close idle reserves? The exchange +# and the auditor must agree on this value. We currently +# expect it to be globally defined for the whole system, +# as there is no way for wallets to query this value. Thus, +# it is only configurable for testing, and should be treated +# as constant in production. +IDLE_RESERVE_EXPIRATION_TIME = 4 weeks + + +[exchangedb-postgres] +CONFIG = "postgres:///talercheck" + +[exchange-account-1] +PAYTO_URI = "payto://x-taler-bank/localhost:8082/3" +WIRE_RESPONSE = ${TALER_CONFIG_HOME}/account-1.json +ENABLE_DEBIT = YES +ENABLE_CREDIT = YES +TALER_BANK_AUTH_METHOD = NONE + + +# Wire fees are specified by wire method +[fees-x-taler-bank] +# Fees for the forseeable future... +# If you see this after 2018, update to match the next 10 years... +WIRE-FEE-2018 = EUR:0.01 +WIRE-FEE-2019 = EUR:0.01 +WIRE-FEE-2020 = EUR:0.01 +WIRE-FEE-2021 = EUR:0.01 +WIRE-FEE-2022 = EUR:0.01 +WIRE-FEE-2023 = EUR:0.01 +WIRE-FEE-2024 = EUR:0.01 +WIRE-FEE-2025 = EUR:0.01 +WIRE-FEE-2026 = EUR:0.01 +WIRE-FEE-2027 = EUR:0.01 + +CLOSING-FEE-2018 = EUR:0.01 +CLOSING-FEE-2019 = EUR:0.01 +CLOSING-FEE-2020 = EUR:0.01 +CLOSING-FEE-2021 = EUR:0.01 +CLOSING-FEE-2022 = EUR:0.01 +CLOSING-FEE-2023 = EUR:0.01 +CLOSING-FEE-2024 = EUR:0.01 +CLOSING-FEE-2025 = EUR:0.01 +CLOSING-FEE-2026 = EUR:0.01 +CLOSING-FEE-2027 = EUR:0.01 + + +# Coins for the tests. +[coin_eur_ct_1] +value = EUR:0.01 +duration_overlap = 5 minutes +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.00 +fee_deposit = EUR:0.00 +fee_refresh = EUR:0.01 +fee_refund = EUR:0.01 +rsa_keysize = 1024 + +[coin_eur_ct_10] +value = EUR:0.10 +duration_overlap = 5 minutes +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +rsa_keysize = 1024 + +[coin_eur_1] +value = EUR:1 +duration_overlap = 5 minutes +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +rsa_keysize = 1024 -- cgit v1.2.3