mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 13:13:44 +01:00
test/parseconf: Stop ignoring --dump-config failures
When we added the $FILTER for Windows newlines, we made the pipeline always exit successfully, even if tor failed. Fixes bug 32468; bugfix on 0.4.2.1-alpha.
This commit is contained in:
parent
7ef44100c4
commit
4514bfe9c2
3
changes/bug32468
Normal file
3
changes/bug32468
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
o Minor bugfixes (testing):
|
||||||
|
- Stop ignoring "tor --dump-config" errors in test_parseconf.sh.
|
||||||
|
Fixes bug 32468; bugfix on 0.4.2.1-alpha.
|
1
src/test/conf_examples/pt_02/error
Normal file
1
src/test/conf_examples/pt_02/error
Normal file
@ -0,0 +1 @@
|
|||||||
|
Invalid ExtORPort configuration
|
1
src/test/conf_examples/pt_09/error
Normal file
1
src/test/conf_examples/pt_09/error
Normal file
@ -0,0 +1 @@
|
|||||||
|
Error parsing ServerTransportListenAddr address
|
1
src/test/conf_examples/relay_02/error
Normal file
1
src/test/conf_examples/relay_02/error
Normal file
@ -0,0 +1 @@
|
|||||||
|
Unrecognized value bad
|
@ -102,6 +102,8 @@
|
|||||||
umask 077
|
umask 077
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
MYNAME="$0"
|
||||||
|
|
||||||
# emulate realpath(), in case coreutils or equivalent is not installed.
|
# emulate realpath(), in case coreutils or equivalent is not installed.
|
||||||
abspath() {
|
abspath() {
|
||||||
f="$*"
|
f="$*"
|
||||||
@ -156,7 +158,20 @@ fi
|
|||||||
|
|
||||||
FINAL_EXIT=0
|
FINAL_EXIT=0
|
||||||
|
|
||||||
die() { echo "$1" >&2 ; FINAL_EXIT=$EXITCODE; }
|
NEXT_TEST=
|
||||||
|
fail() { printf "FAIL: " >&2;
|
||||||
|
# The first argument is a printf string, so this warning is spurious
|
||||||
|
# shellcheck disable=SC2059
|
||||||
|
printf "$@" >&2;
|
||||||
|
printf '\n' >&2;
|
||||||
|
NEXT_TEST="yes"
|
||||||
|
FINAL_EXIT=$EXITCODE; }
|
||||||
|
die() { printf "FAIL: CRITICAL error in '%s':" "$MYNAME" >&2;
|
||||||
|
# The first argument is a printf string, so this warning is spurious
|
||||||
|
# shellcheck disable=SC2059
|
||||||
|
printf "$@" >&2;
|
||||||
|
printf '\n' >&2;
|
||||||
|
exit $EXITCODE; }
|
||||||
|
|
||||||
if test "$WINDOWS" = 1; then
|
if test "$WINDOWS" = 1; then
|
||||||
FILTER="dos2unix"
|
FILTER="dos2unix"
|
||||||
@ -166,7 +181,8 @@ fi
|
|||||||
|
|
||||||
EMPTY="${DATA_DIR}/EMPTY"
|
EMPTY="${DATA_DIR}/EMPTY"
|
||||||
|
|
||||||
touch "$EMPTY" || die "Couldn't create empty file."
|
touch "$EMPTY" || die "Couldn't create empty file '%s'." \
|
||||||
|
"$EMPTY"
|
||||||
|
|
||||||
STANDARD_LIBS="libevent\\|openssl\\|zlib"
|
STANDARD_LIBS="libevent\\|openssl\\|zlib"
|
||||||
# Lib names are restricted to [a-z0-9]* at the moment
|
# Lib names are restricted to [a-z0-9]* at the moment
|
||||||
@ -185,9 +201,8 @@ TOR_LIBS_ENABLED=${TOR_LIBS_ENABLED%_}
|
|||||||
# If we ever have more than 3 optional libraries, we'll need more code here
|
# If we ever have more than 3 optional libraries, we'll need more code here
|
||||||
TOR_LIBS_ENABLED_COUNT="$(echo "$TOR_LIBS_ENABLED_SEARCH" \
|
TOR_LIBS_ENABLED_COUNT="$(echo "$TOR_LIBS_ENABLED_SEARCH" \
|
||||||
| tr ' ' '\n' | wc -l)"
|
| tr ' ' '\n' | wc -l)"
|
||||||
if [ "$TOR_LIBS_ENABLED_COUNT" -gt 3 ]; then
|
if test "$TOR_LIBS_ENABLED_COUNT" -gt 3; then
|
||||||
echo "$0 can not handle more than 3 optional libraries"
|
die "Can not handle more than 3 optional libraries"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
# Brute-force the combinations of libraries
|
# Brute-force the combinations of libraries
|
||||||
TOR_LIBS_ENABLED_SEARCH_3="$(echo "$TOR_LIBS_ENABLED" \
|
TOR_LIBS_ENABLED_SEARCH_3="$(echo "$TOR_LIBS_ENABLED" \
|
||||||
@ -214,7 +229,9 @@ fi
|
|||||||
echo "Disabled Modules: ${TOR_MODULES_DISABLED:-(None)}"
|
echo "Disabled Modules: ${TOR_MODULES_DISABLED:-(None)}"
|
||||||
|
|
||||||
for dir in "${EXAMPLEDIR}"/*; do
|
for dir in "${EXAMPLEDIR}"/*; do
|
||||||
if ! test -d "${dir}"; then
|
NEXT_TEST=
|
||||||
|
|
||||||
|
if ! test -d "$dir"; then
|
||||||
# Only count directories.
|
# Only count directories.
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
@ -254,10 +271,11 @@ for dir in "${EXAMPLEDIR}"/*; do
|
|||||||
|
|
||||||
# Check for broken configs
|
# Check for broken configs
|
||||||
if test -f "./error${suffix}"; then
|
if test -f "./error${suffix}"; then
|
||||||
echo "FAIL: Found both ${dir}/expected${suffix}" >&2
|
fail "Found both '%s' and '%s'.%s" \
|
||||||
echo "and ${dir}/error${suffix}." >&2
|
"${dir}/expected${suffix}" \
|
||||||
echo "(Only one of these files should exist.)" >&2
|
"${dir}/error${suffix}" \
|
||||||
FINAL_EXIT=$EXITCODE
|
"(Only one of these files should exist.)"
|
||||||
|
break
|
||||||
fi
|
fi
|
||||||
|
|
||||||
EXPECTED="./expected${suffix}"
|
EXPECTED="./expected${suffix}"
|
||||||
@ -272,92 +290,114 @@ for dir in "${EXAMPLEDIR}"/*; do
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Exit as soon as the inner loop finds a file
|
# Exit as soon as the inner loop finds a file, or fails
|
||||||
if test -f "$EXPECTED" || test -f "$ERROR"; then
|
if test -f "$EXPECTED" || test -f "$ERROR" || test "$NEXT_TEST"; then
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if test -f "$EXPECTED"; then
|
if test "$NEXT_TEST"; then
|
||||||
|
# The test failed inside the file search loop: go to the next test
|
||||||
|
continue
|
||||||
|
elif test -f "$EXPECTED"; then
|
||||||
# This case should succeed: run dump-config and see if it does.
|
# This case should succeed: run dump-config and see if it does.
|
||||||
FAILED_LOG=
|
|
||||||
FAILED_CONFIG=
|
|
||||||
|
|
||||||
if test -f "$EXPECTED_LOG"; then
|
if test -f "$EXPECTED_LOG"; then
|
||||||
if ! test -s "$EXPECTED_LOG"; then
|
if ! test -s "$EXPECTED_LOG"; then
|
||||||
echo "FAIL: expected log file '$EXPECTED_LOG' is empty." >&2
|
fail "Expected log file '%s' is empty.%s" \
|
||||||
echo "Empty expected log files match any output." >&2
|
"$EXPECTED_LOG" \
|
||||||
FINAL_EXIT=$EXITCODE
|
"(Empty expected log files match any output.)"
|
||||||
|
continue
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
"${TOR_BINARY}" -f "./torrc" \
|
"$TOR_BINARY" -f "./torrc" \
|
||||||
--defaults-torrc "${DEFAULTS}" \
|
--defaults-torrc "$DEFAULTS" \
|
||||||
--dump-config short \
|
--dump-config short \
|
||||||
${CMDLINE} \
|
$CMDLINE > "${DATA_DIR}/output_raw.${testname}" \
|
||||||
| "${FILTER}" > "${DATA_DIR}/output.${testname}" \
|
|| fail "'%s': Tor --dump-config reported an error." \
|
||||||
|| die "FAIL: $EXPECTED: Tor reported an error."
|
"$EXPECTED"
|
||||||
|
|
||||||
|
"$FILTER" "${DATA_DIR}/output_raw.${testname}" \
|
||||||
|
> "${DATA_DIR}/output.${testname}" \
|
||||||
|
|| fail "'%s': Filter '%s' reported an error." \
|
||||||
|
"$EXPECTED" \
|
||||||
|
"$FILTER"
|
||||||
|
|
||||||
if cmp "$EXPECTED" "${DATA_DIR}/output.${testname}">/dev/null ; then
|
if cmp "$EXPECTED" "${DATA_DIR}/output.${testname}" > /dev/null; then
|
||||||
# Check round-trip.
|
# Check round-trip.
|
||||||
"${TOR_BINARY}" -f "${DATA_DIR}/output.${testname}" \
|
"$TOR_BINARY" -f "${DATA_DIR}/output.${testname}" \
|
||||||
--defaults-torrc "${DATA_DIR}/empty" \
|
--defaults-torrc "$EMPTY" \
|
||||||
--dump-config short \
|
--dump-config short \
|
||||||
| "${FILTER}" \
|
> "${DATA_DIR}/output_2_raw.${testname}" \
|
||||||
> "${DATA_DIR}/output_2.${testname}" \
|
|| fail "'%s': Tor --dump-config reported an error%s." \
|
||||||
|| die \
|
"$EXPECTED" \
|
||||||
"FAIL: $EXPECTED: Tor reported an error on round-trip."
|
" on round-trip"
|
||||||
|
|
||||||
|
"$FILTER" "${DATA_DIR}/output_2_raw.${testname}" \
|
||||||
|
> "${DATA_DIR}/output_2.${testname}" \
|
||||||
|
|| fail "'%s': Filter '%s' reported an error." \
|
||||||
|
"$EXPECTED" \
|
||||||
|
"$FILTER"
|
||||||
|
|
||||||
if ! cmp "${DATA_DIR}/output.${testname}" \
|
if ! cmp "${DATA_DIR}/output.${testname}" \
|
||||||
"${DATA_DIR}/output_2.${testname}"; then
|
"${DATA_DIR}/output_2.${testname}"; then
|
||||||
echo "FAIL: $EXPECTED did not match on round-trip:" >&2
|
fail "'%s': did not match on round-trip:" \
|
||||||
|
"$EXPECTED"
|
||||||
diff -u "${DATA_DIR}/output.${testname}" \
|
diff -u "${DATA_DIR}/output.${testname}" \
|
||||||
"${DATA_DIR}/output_2.${testname}" >&2 \
|
"${DATA_DIR}/output_2.${testname}" >&2 \
|
||||||
|| true
|
|| true
|
||||||
FINAL_EXIT=$EXITCODE
|
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
FAILED_CONFIG="yes"
|
|
||||||
if test "$(wc -c < "${DATA_DIR}/output.${testname}")" = 0; then
|
if test "$(wc -c < "${DATA_DIR}/output.${testname}")" = 0; then
|
||||||
echo "FAIL: $EXPECTED: Tor said:" >&2
|
|
||||||
# There was no output -- probably we failed.
|
# There was no output -- probably we failed.
|
||||||
"${TOR_BINARY}" -f "./torrc" \
|
fail "'%s': Tor said:" \
|
||||||
--defaults-torrc "${DEFAULTS}" \
|
"$EXPECTED"
|
||||||
--verify-config \
|
"$TOR_BINARY" -f "./torrc" \
|
||||||
${CMDLINE} || true
|
--defaults-torrc "$DEFAULTS" \
|
||||||
|
--verify-config \
|
||||||
|
$CMDLINE >&2 \
|
||||||
|
|| true
|
||||||
fi
|
fi
|
||||||
echo "FAIL: $EXPECTED did not match:" >&2
|
fail "'%s' did not match:" \
|
||||||
|
"$EXPECTED"
|
||||||
diff -u "$EXPECTED" "${DATA_DIR}/output.${testname}" >&2 \
|
diff -u "$EXPECTED" "${DATA_DIR}/output.${testname}" >&2 \
|
||||||
|| true
|
|| true
|
||||||
FINAL_EXIT=$EXITCODE
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test -f "$EXPECTED_LOG"; then
|
if test -f "$EXPECTED_LOG" || test "$NEXT_TEST"; then
|
||||||
# This case should succeed: run verify-config and see if it does.
|
# This case should succeed: run verify-config and see if it does.
|
||||||
|
#
|
||||||
|
# As a temporary hack, we also use this code when --dump-config
|
||||||
|
# has failed, to display the error logs.
|
||||||
|
if ! test -f "$EXPECTED_LOG"; then
|
||||||
|
NON_EMPTY="${DATA_DIR}/NON_EMPTY"
|
||||||
|
echo "This pattern should not match any log messages" \
|
||||||
|
> "$NON_EMPTY"
|
||||||
|
EXPECTED_LOG=$NON_EMPTY
|
||||||
|
fi
|
||||||
|
|
||||||
"${TOR_BINARY}" --verify-config \
|
"$TOR_BINARY" --verify-config \
|
||||||
-f ./torrc \
|
-f ./torrc \
|
||||||
--defaults-torrc "${DEFAULTS}" \
|
--defaults-torrc "$DEFAULTS" \
|
||||||
${CMDLINE} \
|
$CMDLINE \
|
||||||
> "${DATA_DIR}/output_log.${testname}" \
|
> "${DATA_DIR}/output_log.${testname}" \
|
||||||
|| die "FAIL: $EXPECTED_LOG: Tor reported an error."
|
|| fail "'%s': Tor --verify-config reported an error." \
|
||||||
|
"$EXPECTED_LOG"
|
||||||
|
|
||||||
expect_log="$(cat "$EXPECTED_LOG")"
|
expect_log="$(cat "${EXPECTED_LOG}")"
|
||||||
if grep "${expect_log}" "${DATA_DIR}/output_log.${testname}" \
|
if grep "$expect_log" "${DATA_DIR}/output_log.${testname}" \
|
||||||
>/dev/null; then
|
> /dev/null; then
|
||||||
:
|
:
|
||||||
else
|
else
|
||||||
FAILED_LOG="yes"
|
fail "Expected '%s':\\n%s\\nTor said:" \
|
||||||
echo "FAIL: Expected $EXPECTED_LOG:" >&2
|
"$EXPECTED_LOG" \
|
||||||
echo "${expect_log}" >&2
|
"$expect_log"
|
||||||
echo "Tor said:" >&2
|
|
||||||
cat "${DATA_DIR}/output_log.${testname}" >&2
|
cat "${DATA_DIR}/output_log.${testname}" >&2
|
||||||
FINAL_EXIT=$EXITCODE
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test -z "${FAILED_LOG}${FAILED_CONFIG}"; then
|
if test -z "$NEXT_TEST"; then
|
||||||
echo "OK"
|
echo "OK"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -365,35 +405,34 @@ for dir in "${EXAMPLEDIR}"/*; do
|
|||||||
# This case should fail: run verify-config and see if it does.
|
# This case should fail: run verify-config and see if it does.
|
||||||
|
|
||||||
if ! test -s "$ERROR"; then
|
if ! test -s "$ERROR"; then
|
||||||
echo "FAIL: error file '$ERROR' is empty." >&2
|
fail "Error file '%s' is empty.%s" \
|
||||||
echo "Empty error files match any output." >&2
|
"$ERROR" \
|
||||||
FINAL_EXIT=$EXITCODE
|
"(Empty error files match any output.)"
|
||||||
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
"${TOR_BINARY}" --verify-config \
|
"$TOR_BINARY" --verify-config \
|
||||||
-f ./torrc \
|
-f ./torrc \
|
||||||
--defaults-torrc "${DEFAULTS}" \
|
--defaults-torrc "$DEFAULTS" \
|
||||||
${CMDLINE} \
|
$CMDLINE \
|
||||||
> "${DATA_DIR}/output.${testname}" \
|
> "${DATA_DIR}/output.${testname}" \
|
||||||
&& die "FAIL: $ERROR: Tor did not report an error."
|
&& fail "'%s': Tor did not report an error." \
|
||||||
|
"$ERROR"
|
||||||
|
|
||||||
expect_err="$(cat "$ERROR")"
|
expect_err="$(cat "$ERROR")"
|
||||||
if grep "${expect_err}" "${DATA_DIR}/output.${testname}" >/dev/null; then
|
if grep "${expect_err}" "${DATA_DIR}/output.${testname}" >/dev/null; then
|
||||||
echo "OK"
|
echo "OK"
|
||||||
else
|
else
|
||||||
echo "FAIL: Expected $ERROR: " >&2
|
fail "Expected '%s':\\n%s\\nTor said:" \
|
||||||
echo "${expect_err}" >&2
|
"$ERROR" \
|
||||||
echo "Tor said:" >&2
|
"$expect_err"
|
||||||
cat "${DATA_DIR}/output.${testname}" >&2
|
cat "${DATA_DIR}/output.${testname}" >&2
|
||||||
FINAL_EXIT=$EXITCODE
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
# This case is not actually configured with a success or a failure.
|
# This case is not actually configured with a success or a failure.
|
||||||
# call that an error.
|
# call that an error.
|
||||||
|
fail "Did not find ${dir}/*expected or ${dir}/*error."
|
||||||
echo "FAIL: Did not find ${dir}/*expected or ${dir}/*error." >&2
|
|
||||||
FINAL_EXIT=$EXITCODE
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd "${PREV_DIR}"
|
cd "${PREV_DIR}"
|
||||||
|
Loading…
Reference in New Issue
Block a user