From 735d5f5b7eaed14b2242d1685e0ffa92f746c70c Mon Sep 17 00:00:00 2001 From: teor Date: Tue, 12 Nov 2019 15:03:47 +1000 Subject: [PATCH 01/15] test/parseconf: Split the file list into sections There are lots of different files now, so having Config and Result sections is helpful. Part of 32451. --- src/test/test_parseconf.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/test/test_parseconf.sh b/src/test/test_parseconf.sh index 8d41438b2e..83631cb4c4 100755 --- a/src/test/test_parseconf.sh +++ b/src/test/test_parseconf.sh @@ -17,6 +17,8 @@ # This script looks for its test cases as individual directories in # src/test/conf_examples/. Each test may have these files: # +# Configuration Files +# # torrc -- Usually needed. This file is passed to Tor on the command line # with the "-f" flag. (If you omit it, you'll test Tor's behavior when # it receives a nonexistent configuration file.) @@ -33,6 +35,8 @@ # included. Include paths should be specified relative to the test case # directory. # +# Result Files +# # expected -- If this file is present, then it should be the expected result # of "--dump-config short" for this test case. Exactly one of # "expected" or "error" must be present, or the test will fail. From 4cf5d4cb3c6d725c7615b664b2f3ba116f36b150 Mon Sep 17 00:00:00 2001 From: teor Date: Tue, 12 Nov 2019 15:06:15 +1000 Subject: [PATCH 02/15] test/parseconf: Rewrite the included files section Part of 32451. --- src/test/test_parseconf.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/test_parseconf.sh b/src/test/test_parseconf.sh index 83631cb4c4..2f1f1ed35a 100755 --- a/src/test/test_parseconf.sh +++ b/src/test/test_parseconf.sh @@ -30,10 +30,10 @@ # cmdline -- Optional. If present, it contains command-line arguments that # will be passed to Tor. # -# (included torrc files or directories) -- Optional. If present, and -# configured in the torrc* or cmdline, these files or directories are -# included. Include paths should be specified relative to the test case -# directory. +# (included torrc files or directories) -- Optional. Additional files can be +# included in configuration, using the "%include" directive. Files or +# directories can be included in any of the config files listed above. +# Include paths should be specified relative to the test case directory. # # Result Files # From 3df64320067625e1ce888b9bd11943524ee8f47d Mon Sep 17 00:00:00 2001 From: teor Date: Tue, 12 Nov 2019 15:07:27 +1000 Subject: [PATCH 03/15] test/parseconf: Add an expected_log file The "expected_log" file is a set of patterns that matches the output of "tor --verify-config". Unlike "error", it expects a successful exit status. Part of 32451. --- src/test/test_parseconf.sh | 79 ++++++++++++++++++++++++++++++++------ 1 file changed, 67 insertions(+), 12 deletions(-) diff --git a/src/test/test_parseconf.sh b/src/test/test_parseconf.sh index 2f1f1ed35a..f298072c3e 100755 --- a/src/test/test_parseconf.sh +++ b/src/test/test_parseconf.sh @@ -8,11 +8,16 @@ # Valid configurations are tested with --dump-config, which parses and # validates the configuration before writing it out. We then make sure that # the result is what we expect, before parsing and dumping it again to make -# sure that there is no change. +# sure that there is no change. Optionally, we can also test the log messages +# with --verify-config. # # Invalid configurations are tested with --verify-config, which parses # and validates the configuration. We capture its output and make sure that # it contains the error message we expect. +# +# When tor is compiled with different libraries or modules, some +# configurations may have different results. We can specify these result +# variants using additional result files. # This script looks for its test cases as individual directories in # src/test/conf_examples/. Each test may have these files: @@ -41,33 +46,42 @@ # of "--dump-config short" for this test case. Exactly one of # "expected" or "error" must be present, or the test will fail. # +# expected_log -- Optional. If this file is present, then it contains a regex +# that must be matched by some line in the output of "--verify-config", +# which must succeed. Only used if "expected" is also present. +# # error -- If this file is present, then it contains a regex that must be # matched by some line in the output of "--verify-config", which must # fail. Exactly one of "expected" or "error" must be present, or the # test will fail. # -# {expected,error}_${TOR_LIBS_ENABLED}* -- If this file is present, -# then the outcome is different when some optional libraries are +# {expected,expected_log,error}_${TOR_LIBS_ENABLED}* -- If this file is +# present, then the outcome is different when some optional libraries are # enabled. If there is no result file matching the exact list of enabled # libraries, the script searches for result files with one or more of # those libraries disabled. The search terminates at the standard result -# file. +# file. If expected* is present, the script also searches for +# expected_log*. # # For example: # A test that succeeds, regardless of any enabled libraries: # - expected # A test that has a different result if the nss library is enabled -# (but the same result if any other library is enabled): +# (but the same result if any other library is enabled). We also check +# the log output in this test: # - expected +# - expected_log # - expected_nss +# - expected_log_nss # A test that fails if the lzma and zstd modules are *not* enabled: # - error # - expected_lzma_zstd # -# {expected,error}*_no_${TOR_MODULES_DISABLED} -- If this file is present, -# then the outcome is different when some modules are disabled. If there -# is no result file matching the exact list of disabled modules, the -# standard result file is used. +# {expected,expected_log,error}*_no_${TOR_MODULES_DISABLED} -- If this file is +# present, then the outcome is different when some modules are disabled. +# If there is no result file matching the exact list of disabled modules, +# the standard result file is used. If expected* is present, the script +# also searches for expected_log*. # # For example: # A test that succeeds, regardless of any disabled modules: @@ -225,6 +239,7 @@ for dir in "${EXAMPLEDIR}"/*; do fi EXPECTED= + EXPECTED_LOG= ERROR= # Search for a custom result file for any combination of enabled optional # libraries @@ -246,6 +261,9 @@ for dir in "${EXAMPLEDIR}"/*; do fi EXPECTED="./expected${suffix}" + if test -f "./expected_log${suffix}"; then + EXPECTED_LOG="./expected_log${suffix}" + fi break elif test -f "./error${suffix}"; then @@ -261,8 +279,17 @@ for dir in "${EXAMPLEDIR}"/*; do done if test -f "$EXPECTED"; then - # This case should succeed: run dump-config and see if it does. + FAILED_LOG= + FAILED_CONFIG= + + if test -f "$EXPECTED_LOG"; then + if ! test -s "$EXPECTED_LOG"; then + echo "FAIL: expected log file '$EXPECTED_LOG' is empty." >&2 + echo "Empty expected log files match any output." >&2 + FINAL_EXIT=$EXITCODE + fi + fi "${TOR_BINARY}" -f "./torrc" \ --defaults-torrc "${DEFAULTS}" \ @@ -271,6 +298,7 @@ for dir in "${EXAMPLEDIR}"/*; do | "${FILTER}" > "${DATA_DIR}/output.${testname}" \ || die "FAIL: $EXPECTED: Tor reported an error." + if cmp "$EXPECTED" "${DATA_DIR}/output.${testname}">/dev/null ; then # Check round-trip. "${TOR_BINARY}" -f "${DATA_DIR}/output.${testname}" \ @@ -286,9 +314,8 @@ for dir in "${EXAMPLEDIR}"/*; do echo "FAIL: $EXPECTED did not match on round-trip." >&2 FINAL_EXIT=$EXITCODE fi - - echo "OK" else + FAILED_CONFIG="yes" echo "FAIL" >&2 if test "$(wc -c < "${DATA_DIR}/output.${testname}")" = 0; then # There was no output -- probably we failed. @@ -303,6 +330,34 @@ for dir in "${EXAMPLEDIR}"/*; do FINAL_EXIT=$EXITCODE fi + if test -f "$EXPECTED_LOG"; then + # This case should succeed: run verify-config and see if it does. + + "${TOR_BINARY}" --verify-config \ + -f ./torrc \ + --defaults-torrc "${DEFAULTS}" \ + ${CMDLINE} \ + > "${DATA_DIR}/output_log.${testname}" \ + || die "FAIL: $EXPECTED_LOG: Tor reported an error." + + expect_log="$(cat "$EXPECTED_LOG")" + if grep "${expect_log}" "${DATA_DIR}/output_log.${testname}" \ + >/dev/null; then + : + else + FAILED_LOG="yes" + echo "FAIL" >&2 + echo "Expected $EXPECTED_LOG: ${expect_log}" >&2 + echo "Tor said:" >&2 + cat "${DATA_DIR}/output_log.${testname}" >&2 + FINAL_EXIT=$EXITCODE + fi + fi + + if test -z "${FAILED_LOG}${FAILED_CONFIG}"; then + echo "OK" + fi + elif test -f "$ERROR"; then # This case should fail: run verify-config and see if it does. From 7ef44100c4d85fbd091c3965013b5465872a05f6 Mon Sep 17 00:00:00 2001 From: teor Date: Tue, 12 Nov 2019 15:21:10 +1000 Subject: [PATCH 04/15] test/parseconf: Standardise output messages Part of 32451. --- src/test/test_parseconf.sh | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/test/test_parseconf.sh b/src/test/test_parseconf.sh index f298072c3e..962d43dd77 100755 --- a/src/test/test_parseconf.sh +++ b/src/test/test_parseconf.sh @@ -311,20 +311,23 @@ for dir in "${EXAMPLEDIR}"/*; do if ! cmp "${DATA_DIR}/output.${testname}" \ "${DATA_DIR}/output_2.${testname}"; then - echo "FAIL: $EXPECTED did not match on round-trip." >&2 + echo "FAIL: $EXPECTED did not match on round-trip:" >&2 + diff -u "${DATA_DIR}/output.${testname}" \ + "${DATA_DIR}/output_2.${testname}" >&2 \ + || true FINAL_EXIT=$EXITCODE fi else FAILED_CONFIG="yes" - echo "FAIL" >&2 if test "$(wc -c < "${DATA_DIR}/output.${testname}")" = 0; then + echo "FAIL: $EXPECTED: Tor said:" >&2 # There was no output -- probably we failed. "${TOR_BINARY}" -f "./torrc" \ --defaults-torrc "${DEFAULTS}" \ --verify-config \ ${CMDLINE} || true fi - echo "FAIL: $EXPECTED did not match." >&2 + echo "FAIL: $EXPECTED did not match:" >&2 diff -u "$EXPECTED" "${DATA_DIR}/output.${testname}" >&2 \ || true FINAL_EXIT=$EXITCODE @@ -346,8 +349,8 @@ for dir in "${EXAMPLEDIR}"/*; do : else FAILED_LOG="yes" - echo "FAIL" >&2 - echo "Expected $EXPECTED_LOG: ${expect_log}" >&2 + echo "FAIL: Expected $EXPECTED_LOG:" >&2 + echo "${expect_log}" >&2 echo "Tor said:" >&2 cat "${DATA_DIR}/output_log.${testname}" >&2 FINAL_EXIT=$EXITCODE @@ -378,8 +381,8 @@ for dir in "${EXAMPLEDIR}"/*; do if grep "${expect_err}" "${DATA_DIR}/output.${testname}" >/dev/null; then echo "OK" else - echo "FAIL" >&2 - echo "Expected $ERROR: ${expect_err}" >&2 + echo "FAIL: Expected $ERROR: " >&2 + echo "${expect_err}" >&2 echo "Tor said:" >&2 cat "${DATA_DIR}/output.${testname}" >&2 FINAL_EXIT=$EXITCODE From 4514bfe9c25f3222e0feba29c5129229287f3963 Mon Sep 17 00:00:00 2001 From: teor Date: Tue, 12 Nov 2019 16:45:07 +1000 Subject: [PATCH 05/15] 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. --- changes/bug32468 | 3 + src/test/conf_examples/pt_02/error | 1 + src/test/conf_examples/pt_02/expected | 0 src/test/conf_examples/pt_09/error | 1 + src/test/conf_examples/pt_09/expected | 0 src/test/conf_examples/relay_02/error | 1 + src/test/conf_examples/relay_02/expected | 0 src/test/test_parseconf.sh | 187 ++++++++++++++--------- 8 files changed, 119 insertions(+), 74 deletions(-) create mode 100644 changes/bug32468 create mode 100644 src/test/conf_examples/pt_02/error delete mode 100644 src/test/conf_examples/pt_02/expected create mode 100644 src/test/conf_examples/pt_09/error delete mode 100644 src/test/conf_examples/pt_09/expected create mode 100644 src/test/conf_examples/relay_02/error delete mode 100644 src/test/conf_examples/relay_02/expected diff --git a/changes/bug32468 b/changes/bug32468 new file mode 100644 index 0000000000..fa0d877096 --- /dev/null +++ b/changes/bug32468 @@ -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. diff --git a/src/test/conf_examples/pt_02/error b/src/test/conf_examples/pt_02/error new file mode 100644 index 0000000000..ce28eab729 --- /dev/null +++ b/src/test/conf_examples/pt_02/error @@ -0,0 +1 @@ +Invalid ExtORPort configuration diff --git a/src/test/conf_examples/pt_02/expected b/src/test/conf_examples/pt_02/expected deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/test/conf_examples/pt_09/error b/src/test/conf_examples/pt_09/error new file mode 100644 index 0000000000..882b50a7bc --- /dev/null +++ b/src/test/conf_examples/pt_09/error @@ -0,0 +1 @@ +Error parsing ServerTransportListenAddr address \ No newline at end of file diff --git a/src/test/conf_examples/pt_09/expected b/src/test/conf_examples/pt_09/expected deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/test/conf_examples/relay_02/error b/src/test/conf_examples/relay_02/error new file mode 100644 index 0000000000..dd87d9f7e2 --- /dev/null +++ b/src/test/conf_examples/relay_02/error @@ -0,0 +1 @@ +Unrecognized value bad diff --git a/src/test/conf_examples/relay_02/expected b/src/test/conf_examples/relay_02/expected deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/test/test_parseconf.sh b/src/test/test_parseconf.sh index 962d43dd77..b843509854 100755 --- a/src/test/test_parseconf.sh +++ b/src/test/test_parseconf.sh @@ -102,6 +102,8 @@ umask 077 set -e +MYNAME="$0" + # emulate realpath(), in case coreutils or equivalent is not installed. abspath() { f="$*" @@ -156,7 +158,20 @@ fi 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 FILTER="dos2unix" @@ -166,7 +181,8 @@ fi 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" # 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 TOR_LIBS_ENABLED_COUNT="$(echo "$TOR_LIBS_ENABLED_SEARCH" \ | tr ' ' '\n' | wc -l)" -if [ "$TOR_LIBS_ENABLED_COUNT" -gt 3 ]; then - echo "$0 can not handle more than 3 optional libraries" - exit 1 +if test "$TOR_LIBS_ENABLED_COUNT" -gt 3; then + die "Can not handle more than 3 optional libraries" fi # Brute-force the combinations of libraries TOR_LIBS_ENABLED_SEARCH_3="$(echo "$TOR_LIBS_ENABLED" \ @@ -214,7 +229,9 @@ fi echo "Disabled Modules: ${TOR_MODULES_DISABLED:-(None)}" for dir in "${EXAMPLEDIR}"/*; do - if ! test -d "${dir}"; then + NEXT_TEST= + + if ! test -d "$dir"; then # Only count directories. continue fi @@ -254,10 +271,11 @@ for dir in "${EXAMPLEDIR}"/*; do # Check for broken configs if test -f "./error${suffix}"; then - echo "FAIL: Found both ${dir}/expected${suffix}" >&2 - echo "and ${dir}/error${suffix}." >&2 - echo "(Only one of these files should exist.)" >&2 - FINAL_EXIT=$EXITCODE + fail "Found both '%s' and '%s'.%s" \ + "${dir}/expected${suffix}" \ + "${dir}/error${suffix}" \ + "(Only one of these files should exist.)" + break fi EXPECTED="./expected${suffix}" @@ -272,92 +290,114 @@ for dir in "${EXAMPLEDIR}"/*; do fi done - # Exit as soon as the inner loop finds a file - if test -f "$EXPECTED" || test -f "$ERROR"; then + # Exit as soon as the inner loop finds a file, or fails + if test -f "$EXPECTED" || test -f "$ERROR" || test "$NEXT_TEST"; then break fi 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. - FAILED_LOG= - FAILED_CONFIG= if test -f "$EXPECTED_LOG"; then if ! test -s "$EXPECTED_LOG"; then - echo "FAIL: expected log file '$EXPECTED_LOG' is empty." >&2 - echo "Empty expected log files match any output." >&2 - FINAL_EXIT=$EXITCODE + fail "Expected log file '%s' is empty.%s" \ + "$EXPECTED_LOG" \ + "(Empty expected log files match any output.)" + continue fi fi - "${TOR_BINARY}" -f "./torrc" \ - --defaults-torrc "${DEFAULTS}" \ - --dump-config short \ - ${CMDLINE} \ - | "${FILTER}" > "${DATA_DIR}/output.${testname}" \ - || die "FAIL: $EXPECTED: Tor reported an error." + "$TOR_BINARY" -f "./torrc" \ + --defaults-torrc "$DEFAULTS" \ + --dump-config short \ + $CMDLINE > "${DATA_DIR}/output_raw.${testname}" \ + || fail "'%s': Tor --dump-config 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. - "${TOR_BINARY}" -f "${DATA_DIR}/output.${testname}" \ - --defaults-torrc "${DATA_DIR}/empty" \ - --dump-config short \ - | "${FILTER}" \ - > "${DATA_DIR}/output_2.${testname}" \ - || die \ - "FAIL: $EXPECTED: Tor reported an error on round-trip." + "$TOR_BINARY" -f "${DATA_DIR}/output.${testname}" \ + --defaults-torrc "$EMPTY" \ + --dump-config short \ + > "${DATA_DIR}/output_2_raw.${testname}" \ + || fail "'%s': Tor --dump-config reported an error%s." \ + "$EXPECTED" \ + " 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}" \ "${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}" \ "${DATA_DIR}/output_2.${testname}" >&2 \ || true - FINAL_EXIT=$EXITCODE fi else - FAILED_CONFIG="yes" if test "$(wc -c < "${DATA_DIR}/output.${testname}")" = 0; then - echo "FAIL: $EXPECTED: Tor said:" >&2 # There was no output -- probably we failed. - "${TOR_BINARY}" -f "./torrc" \ - --defaults-torrc "${DEFAULTS}" \ - --verify-config \ - ${CMDLINE} || true + fail "'%s': Tor said:" \ + "$EXPECTED" + "$TOR_BINARY" -f "./torrc" \ + --defaults-torrc "$DEFAULTS" \ + --verify-config \ + $CMDLINE >&2 \ + || true fi - echo "FAIL: $EXPECTED did not match:" >&2 + fail "'%s' did not match:" \ + "$EXPECTED" diff -u "$EXPECTED" "${DATA_DIR}/output.${testname}" >&2 \ || true - FINAL_EXIT=$EXITCODE 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. + # + # 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 \ - -f ./torrc \ - --defaults-torrc "${DEFAULTS}" \ - ${CMDLINE} \ - > "${DATA_DIR}/output_log.${testname}" \ - || die "FAIL: $EXPECTED_LOG: Tor reported an error." + "$TOR_BINARY" --verify-config \ + -f ./torrc \ + --defaults-torrc "$DEFAULTS" \ + $CMDLINE \ + > "${DATA_DIR}/output_log.${testname}" \ + || fail "'%s': Tor --verify-config reported an error." \ + "$EXPECTED_LOG" - expect_log="$(cat "$EXPECTED_LOG")" - if grep "${expect_log}" "${DATA_DIR}/output_log.${testname}" \ - >/dev/null; then + expect_log="$(cat "${EXPECTED_LOG}")" + if grep "$expect_log" "${DATA_DIR}/output_log.${testname}" \ + > /dev/null; then : else - FAILED_LOG="yes" - echo "FAIL: Expected $EXPECTED_LOG:" >&2 - echo "${expect_log}" >&2 - echo "Tor said:" >&2 + fail "Expected '%s':\\n%s\\nTor said:" \ + "$EXPECTED_LOG" \ + "$expect_log" cat "${DATA_DIR}/output_log.${testname}" >&2 - FINAL_EXIT=$EXITCODE fi fi - if test -z "${FAILED_LOG}${FAILED_CONFIG}"; then + if test -z "$NEXT_TEST"; then echo "OK" fi @@ -365,35 +405,34 @@ for dir in "${EXAMPLEDIR}"/*; do # This case should fail: run verify-config and see if it does. if ! test -s "$ERROR"; then - echo "FAIL: error file '$ERROR' is empty." >&2 - echo "Empty error files match any output." >&2 - FINAL_EXIT=$EXITCODE + fail "Error file '%s' is empty.%s" \ + "$ERROR" \ + "(Empty error files match any output.)" + continue fi - "${TOR_BINARY}" --verify-config \ - -f ./torrc \ - --defaults-torrc "${DEFAULTS}" \ - ${CMDLINE} \ - > "${DATA_DIR}/output.${testname}" \ - && die "FAIL: $ERROR: Tor did not report an error." + "$TOR_BINARY" --verify-config \ + -f ./torrc \ + --defaults-torrc "$DEFAULTS" \ + $CMDLINE \ + > "${DATA_DIR}/output.${testname}" \ + && fail "'%s': Tor did not report an error." \ + "$ERROR" expect_err="$(cat "$ERROR")" if grep "${expect_err}" "${DATA_DIR}/output.${testname}" >/dev/null; then echo "OK" else - echo "FAIL: Expected $ERROR: " >&2 - echo "${expect_err}" >&2 - echo "Tor said:" >&2 + fail "Expected '%s':\\n%s\\nTor said:" \ + "$ERROR" \ + "$expect_err" cat "${DATA_DIR}/output.${testname}" >&2 - FINAL_EXIT=$EXITCODE fi else # This case is not actually configured with a success or a failure. # call that an error. - - echo "FAIL: Did not find ${dir}/*expected or ${dir}/*error." >&2 - FINAL_EXIT=$EXITCODE + fail "Did not find ${dir}/*expected or ${dir}/*error." fi cd "${PREV_DIR}" From e6ca32fae3031e33898d541bf4da28c58b978713 Mon Sep 17 00:00:00 2001 From: teor Date: Tue, 12 Nov 2019 16:51:18 +1000 Subject: [PATCH 06/15] test/parseconf: Use consistent formatting Make spacing, quotes, and env vars consistent. Cleanup after 32451 and 32468. --- src/test/test_parseconf.sh | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/test/test_parseconf.sh b/src/test/test_parseconf.sh index b843509854..78b88c48e3 100755 --- a/src/test/test_parseconf.sh +++ b/src/test/test_parseconf.sh @@ -107,7 +107,7 @@ MYNAME="$0" # emulate realpath(), in case coreutils or equivalent is not installed. abspath() { f="$*" - if [ -d "$f" ]; then + if test -d "$f"; then dir="$f" base="" else @@ -119,8 +119,8 @@ abspath() { } # find the tor binary -if [ $# -ge 1 ]; then - TOR_BINARY="${1}" +if test $# -ge 1; then + TOR_BINARY="$1" shift else TOR_BINARY="${TESTING_TOR_BINARY:-./src/app/tor}" @@ -128,7 +128,7 @@ fi TOR_BINARY="$(abspath "$TOR_BINARY")" -echo "TOR BINARY IS ${TOR_BINARY}" +echo "TOR BINARY IS $TOR_BINARY" # make a safe space for temporary files DATA_DIR=$(mktemp -d -t tor_parseconf_tests.XXXXXX) @@ -163,14 +163,14 @@ fail() { printf "FAIL: " >&2; # The first argument is a printf string, so this warning is spurious # shellcheck disable=SC2059 printf "$@" >&2; - printf '\n' >&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; + printf "\\n" >&2; exit $EXITCODE; } if test "$WINDOWS" = 1; then @@ -223,7 +223,7 @@ TOR_MODULES_DISABLED=${TOR_MODULES_DISABLED%_} echo "Tor is configured with:" echo "Optional Libraries: ${TOR_LIBS_ENABLED:-(None)}" -if [ -n "${TOR_LIBS_ENABLED}" ]; then +if test "$TOR_LIBS_ENABLED"; then echo "Optional Library Search List: $TOR_LIBS_ENABLED_SEARCH" fi echo "Disabled Modules: ${TOR_MODULES_DISABLED:-(None)}" @@ -238,10 +238,11 @@ for dir in "${EXAMPLEDIR}"/*; do testname="$(basename "${dir}")" # We use printf since "echo -n" is not standard - printf "%s: " "$testname" + printf "%s: " \ + "$testname" PREV_DIR="$(pwd)" - cd "${dir}" + cd "$dir" if test -f "./torrc.defaults"; then DEFAULTS="./torrc.defaults" @@ -419,8 +420,8 @@ for dir in "${EXAMPLEDIR}"/*; do && fail "'%s': Tor did not report an error." \ "$ERROR" - expect_err="$(cat "$ERROR")" - if grep "${expect_err}" "${DATA_DIR}/output.${testname}" >/dev/null; then + expect_err="$(cat "${ERROR}")" + if grep "$expect_err" "${DATA_DIR}/output.${testname}" > /dev/null; then echo "OK" else fail "Expected '%s':\\n%s\\nTor said:" \ @@ -435,7 +436,7 @@ for dir in "${EXAMPLEDIR}"/*; do fail "Did not find ${dir}/*expected or ${dir}/*error." fi - cd "${PREV_DIR}" + cd "$PREV_DIR" done From b4b3060f692ed934fe89d791be683a7506e5860e Mon Sep 17 00:00:00 2001 From: teor Date: Wed, 13 Nov 2019 14:00:09 +1000 Subject: [PATCH 07/15] test/parseconf: Rename some functions, and reformat Part of 32451. --- src/test/test_parseconf.sh | 110 +++++++++++++++++++------------------ 1 file changed, 56 insertions(+), 54 deletions(-) diff --git a/src/test/test_parseconf.sh b/src/test/test_parseconf.sh index 78b88c48e3..237bf33ce3 100755 --- a/src/test/test_parseconf.sh +++ b/src/test/test_parseconf.sh @@ -159,19 +159,21 @@ fi FINAL_EXIT=0 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; } +fail_printf() { 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() { 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 FILTER="dos2unix" @@ -181,8 +183,8 @@ fi EMPTY="${DATA_DIR}/EMPTY" -touch "$EMPTY" || die "Couldn't create empty file '%s'." \ - "$EMPTY" +touch "$EMPTY" || die_printf "Couldn't create empty file '%s'." \ + "$EMPTY" STANDARD_LIBS="libevent\\|openssl\\|zlib" # Lib names are restricted to [a-z0-9]* at the moment @@ -202,7 +204,7 @@ TOR_LIBS_ENABLED=${TOR_LIBS_ENABLED%_} TOR_LIBS_ENABLED_COUNT="$(echo "$TOR_LIBS_ENABLED_SEARCH" \ | tr ' ' '\n' | wc -l)" if test "$TOR_LIBS_ENABLED_COUNT" -gt 3; then - die "Can not handle more than 3 optional libraries" + die_printf "Can not handle more than 3 optional libraries" fi # Brute-force the combinations of libraries TOR_LIBS_ENABLED_SEARCH_3="$(echo "$TOR_LIBS_ENABLED" \ @@ -272,10 +274,10 @@ for dir in "${EXAMPLEDIR}"/*; do # Check for broken configs if test -f "./error${suffix}"; then - fail "Found both '%s' and '%s'.%s" \ - "${dir}/expected${suffix}" \ - "${dir}/error${suffix}" \ - "(Only one of these files should exist.)" + fail_printf "Found both '%s' and '%s'.%s" \ + "${dir}/expected${suffix}" \ + "${dir}/error${suffix}" \ + "(Only one of these files should exist.)" break fi @@ -305,9 +307,9 @@ for dir in "${EXAMPLEDIR}"/*; do if test -f "$EXPECTED_LOG"; then if ! test -s "$EXPECTED_LOG"; then - fail "Expected log file '%s' is empty.%s" \ - "$EXPECTED_LOG" \ - "(Empty expected log files match any output.)" + fail_printf "Expected log file '%s' is empty.%s" \ + "$EXPECTED_LOG" \ + "(Empty expected log files match any output.)" continue fi fi @@ -316,14 +318,14 @@ for dir in "${EXAMPLEDIR}"/*; do --defaults-torrc "$DEFAULTS" \ --dump-config short \ $CMDLINE > "${DATA_DIR}/output_raw.${testname}" \ - || fail "'%s': Tor --dump-config reported an error." \ - "$EXPECTED" + || fail_printf "'%s': Tor --dump-config reported an error." \ + "$EXPECTED" "$FILTER" "${DATA_DIR}/output_raw.${testname}" \ > "${DATA_DIR}/output.${testname}" \ - || fail "'%s': Filter '%s' reported an error." \ - "$EXPECTED" \ - "$FILTER" + || fail_printf "'%s': Filter '%s' reported an error." \ + "$EXPECTED" \ + "$FILTER" if cmp "$EXPECTED" "${DATA_DIR}/output.${testname}" > /dev/null; then # Check round-trip. @@ -331,20 +333,20 @@ for dir in "${EXAMPLEDIR}"/*; do --defaults-torrc "$EMPTY" \ --dump-config short \ > "${DATA_DIR}/output_2_raw.${testname}" \ - || fail "'%s': Tor --dump-config reported an error%s." \ - "$EXPECTED" \ - " on round-trip" + || fail_printf "'%s': Tor --dump-config reported an %s." \ + "$EXPECTED" \ + "error on round-trip" "$FILTER" "${DATA_DIR}/output_2_raw.${testname}" \ > "${DATA_DIR}/output_2.${testname}" \ - || fail "'%s': Filter '%s' reported an error." \ - "$EXPECTED" \ - "$FILTER" + || fail_printf "'%s': Filter '%s' reported an error." \ + "$EXPECTED" \ + "$FILTER" if ! cmp "${DATA_DIR}/output.${testname}" \ "${DATA_DIR}/output_2.${testname}"; then - fail "'%s': did not match on round-trip:" \ - "$EXPECTED" + fail_printf "'%s': did not match on round-trip:" \ + "$EXPECTED" diff -u "${DATA_DIR}/output.${testname}" \ "${DATA_DIR}/output_2.${testname}" >&2 \ || true @@ -352,16 +354,16 @@ for dir in "${EXAMPLEDIR}"/*; do else if test "$(wc -c < "${DATA_DIR}/output.${testname}")" = 0; then # There was no output -- probably we failed. - fail "'%s': Tor said:" \ - "$EXPECTED" + fail_printf "'%s': Tor said:" \ + "$EXPECTED" "$TOR_BINARY" -f "./torrc" \ --defaults-torrc "$DEFAULTS" \ --verify-config \ $CMDLINE >&2 \ || true fi - fail "'%s' did not match:" \ - "$EXPECTED" + fail_printf "'%s' did not match:" \ + "$EXPECTED" diff -u "$EXPECTED" "${DATA_DIR}/output.${testname}" >&2 \ || true fi @@ -383,17 +385,17 @@ for dir in "${EXAMPLEDIR}"/*; do --defaults-torrc "$DEFAULTS" \ $CMDLINE \ > "${DATA_DIR}/output_log.${testname}" \ - || fail "'%s': Tor --verify-config reported an error." \ - "$EXPECTED_LOG" + || fail_printf "'%s': Tor --verify-config reported an error." \ + "$EXPECTED_LOG" expect_log="$(cat "${EXPECTED_LOG}")" if grep "$expect_log" "${DATA_DIR}/output_log.${testname}" \ > /dev/null; then : else - fail "Expected '%s':\\n%s\\nTor said:" \ - "$EXPECTED_LOG" \ - "$expect_log" + fail_printf "Expected '%s':\\n%s\\nTor said:" \ + "$EXPECTED_LOG" \ + "$expect_log" cat "${DATA_DIR}/output_log.${testname}" >&2 fi fi @@ -406,9 +408,9 @@ for dir in "${EXAMPLEDIR}"/*; do # This case should fail: run verify-config and see if it does. if ! test -s "$ERROR"; then - fail "Error file '%s' is empty.%s" \ - "$ERROR" \ - "(Empty error files match any output.)" + fail_printf "Error file '%s' is empty.%s" \ + "$ERROR" \ + "(Empty error files match any output.)" continue fi @@ -417,23 +419,23 @@ for dir in "${EXAMPLEDIR}"/*; do --defaults-torrc "$DEFAULTS" \ $CMDLINE \ > "${DATA_DIR}/output.${testname}" \ - && fail "'%s': Tor did not report an error." \ - "$ERROR" + && fail_printf "'%s': Tor did not report an error." \ + "$ERROR" expect_err="$(cat "${ERROR}")" if grep "$expect_err" "${DATA_DIR}/output.${testname}" > /dev/null; then echo "OK" else - fail "Expected '%s':\\n%s\\nTor said:" \ - "$ERROR" \ - "$expect_err" + fail_printf "Expected '%s':\\n%s\\nTor said:" \ + "$ERROR" \ + "$expect_err" cat "${DATA_DIR}/output.${testname}" >&2 fi else # This case is not actually configured with a success or a failure. # call that an error. - fail "Did not find ${dir}/*expected or ${dir}/*error." + fail_printf "Did not find ${dir}/*expected or ${dir}/*error." fi cd "$PREV_DIR" From 39046019ec1192bd8222821a6b8677fabc0a9968 Mon Sep 17 00:00:00 2001 From: teor Date: Wed, 13 Nov 2019 16:37:32 +1000 Subject: [PATCH 08/15] test/parseconf: Refactor and standardise, stage 1 Remove duplicate code, and standardise similar behaviour. Add some additional error checking. Cleanup after 32451. --- src/test/test_parseconf.sh | 388 +++++++++++++++++++++++++------------ 1 file changed, 266 insertions(+), 122 deletions(-) diff --git a/src/test/test_parseconf.sh b/src/test/test_parseconf.sh index 237bf33ce3..edda6c3ef8 100755 --- a/src/test/test_parseconf.sh +++ b/src/test/test_parseconf.sh @@ -128,7 +128,7 @@ fi TOR_BINARY="$(abspath "$TOR_BINARY")" -echo "TOR BINARY IS $TOR_BINARY" +echo "Using Tor binary '$TOR_BINARY'." # make a safe space for temporary files DATA_DIR=$(mktemp -d -t tor_parseconf_tests.XXXXXX) @@ -157,23 +157,32 @@ else fi FINAL_EXIT=0 - NEXT_TEST= -fail_printf() { 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() { 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; } + +# Log a failure message to stderr, using $@ as a printf string and arguments +# Set NEXT_TEST to "yes" and FINAL_EXIT to $EXITCODE. +fail_printf() +{ + 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 +} + +# Log a failure message to stderr, using $@ as a printf string and arguments +# Exit with status $EXITCODE. +die_printf() +{ + 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 FILTER="dos2unix" @@ -182,9 +191,12 @@ else fi EMPTY="${DATA_DIR}/EMPTY" - touch "$EMPTY" || die_printf "Couldn't create empty file '%s'." \ "$EMPTY" +NON_EMPTY="${DATA_DIR}/NON_EMPTY" +echo "This pattern should not match any log messages" \ + > "$NON_EMPTY" || die_printf "Couldn't create non-empty file '%s'." \ + "$NON_EMPTY" STANDARD_LIBS="libevent\\|openssl\\|zlib" # Lib names are restricted to [a-z0-9]* at the moment @@ -230,6 +242,178 @@ if test "$TOR_LIBS_ENABLED"; then fi echo "Disabled Modules: ${TOR_MODULES_DISABLED:-(None)}" +# Yes, unix uses "0" for a successful command +TRUE=0 +FALSE=1 + +# Run tor --verify-config on the torrc $1, and defaults torrc $2, which may +# be $EMPTY. Pass tor the extra command line arguments $3, which will be +# passed unquoted. +# Send tor's standard output to stderr. +log_verify_config() +{ + # We need cmdline unquoted + # shellcheck disable=SC2086 + "$TOR_BINARY" --verify-config \ + -f "$1" \ + --defaults-torrc "$2" \ + $3 \ + >&2 \ + || true +} + +# Run "tor --dump-config short" on the torrc $1, and defaults torrc $2, which +# may be $EMPTY. Pass tor the extra command line arguments $3, which will be +# passed unquoted. +# Send the standard output to $4. +# If tor fails, fail_printf() using the file name $5, and context $6, +# which may be an empty string. Then run "tor --verify-config", and log tor's +# error messages to stderr. +dump_config() +{ + if test "$6"; then + CONTEXT=" $6" + else + CONTEXT="" + fi + + # We need cmdline unquoted + # shellcheck disable=SC2086 + if ! "$TOR_BINARY" --dump-config short \ + -f "$1" \ + --defaults-torrc "$2" \ + $3 \ + > "$4"; then + fail_printf "'%s': Tor --dump-config reported an error%s. Tor said:" \ + "$5" \ + "$CONTEXT" + log_verify_config "$1" \ + "$2" \ + "$3" + fi +} + +# Run "$FILTER" on the input $1. +# Send the standard output to $2. +# If tor fails, log a failure message using the file name $3, and context $4, +# which may be an empty string. +filter() +{ + if test "$4"; then + CONTEXT=" $4" + else + CONTEXT="" + fi + + "$FILTER" "$1" \ + > "$2" \ + || fail_printf "'%s': Filter '%s' reported an error%s." \ + "$3" \ + "$FILTER" \ + "$CONTEXT" +} + +# Compare the input file $1, and output file $2. +# +# If they are different, fail. If this is the first step that failed in this +# test, run log_verify_config with torrc $3, defaults torrc $4, and command +# line $5, to log Tor's error messages. Finally, log the differences between +# the files. +# +# If the file contents are identical, returns true. Otherwise, return false. +# +# Log failure messages using fail_printf(), with the file name $6, and +# context $7, which may be an empty string. +check_diff() +{ + if test "$7"; then + CONTEXT=" $=7" + else + CONTEXT="" + fi + + if cmp "$1" "$2" > /dev/null; then + return "$TRUE" + else + # If this is the first step that failed in this test, + # show tor's logs + if test -z "$NEXT_TEST"; then + fail_printf "'%s': Tor said%s:" \ + "$6" \ + "$CONTEXT" + log_verify_config "$3" \ + "$4" \ + "$5" + fi + fail_printf "'%s' did not match%s:" \ + "$6" \ + "$CONTEXT" + diff -u "$1" "$2" >&2 \ + || true + return "$FALSE" + fi +} + +# Check if $1 is an empty file. +# If it is, fail_printf() using $2 as the type of file. +# Returns true if the file is empty, false otherwise. +check_empty_pattern() +{ + if ! test -s "$1"; then + fail_printf "%s file '%s' is empty, and will match any output." \ + "$2" \ + "$1" + return "$TRUE" + else + return "$FALSE" + fi +} + +# Run tor --verify-config on the torrc $1, and defaults torrc $2, which may +# be $EMPTY. Pass tor the extra command line arguments $3, which will be +# passed unquoted. +# Send tor's standard output to $4. +# If tor's exit status does not match the boolean $5, fail_printf() +# using the file name $6, and context $7, which is required. +verify_config() +{ + RESULT=$TRUE + # We need cmdline unquoted + # shellcheck disable=SC2086 + "$TOR_BINARY" --verify-config \ + -f "$1" \ + --defaults-torrc "$2" \ + $3 \ + > "$4" || RESULT=$FALSE + + # Convert the actual and expected results to boolean, and compare + if test $((! (! RESULT))) -ne $((! (! $5))); then + fail_printf "'%s': Tor --verify-config did not %s." \ + "$6" \ + "$7" + fi +} + +# Check for the pattern in file $1, in the lines in the output file $2. +# Uses grep with the entire contents of $1 as the pattern. (Not "grep -f".) +# +# If the pattern does not match any lines in the output file, fail. +# Log the pattern, and the entire contents of the output file. +# +# Log failure messages using fail_printf(), with the file name $1, and +# context $3, which is required. +check_pattern() +{ + expect_log="$(cat "$1")" + if ! grep "$expect_log" "$2" > /dev/null; then + fail_printf "Expected %s '%s':\\n%s\\nTor said:" \ + "$3" \ + "$1" \ + "$expect_log" + cat "$2" >&2 + fi +} + for dir in "${EXAMPLEDIR}"/*; do NEXT_TEST= @@ -306,140 +490,100 @@ for dir in "${EXAMPLEDIR}"/*; do # This case should succeed: run dump-config and see if it does. if test -f "$EXPECTED_LOG"; then - if ! test -s "$EXPECTED_LOG"; then - fail_printf "Expected log file '%s' is empty.%s" \ - "$EXPECTED_LOG" \ - "(Empty expected log files match any output.)" + if check_empty_pattern "$EXPECTED_LOG" "Expected log"; then continue fi fi - "$TOR_BINARY" -f "./torrc" \ - --defaults-torrc "$DEFAULTS" \ - --dump-config short \ - $CMDLINE > "${DATA_DIR}/output_raw.${testname}" \ - || fail_printf "'%s': Tor --dump-config reported an error." \ - "$EXPECTED" + dump_config "./torrc" \ + "$DEFAULTS" \ + "$CMDLINE" \ + "${DATA_DIR}/output_raw.${testname}" \ + "$EXPECTED" \ + "" - "$FILTER" "${DATA_DIR}/output_raw.${testname}" \ - > "${DATA_DIR}/output.${testname}" \ - || fail_printf "'%s': Filter '%s' reported an error." \ - "$EXPECTED" \ - "$FILTER" + filter "${DATA_DIR}/output_raw.${testname}" \ + "${DATA_DIR}/output.${testname}" \ + "$EXPECTED" \ + "" - if cmp "$EXPECTED" "${DATA_DIR}/output.${testname}" > /dev/null; then + if check_diff "$EXPECTED" \ + "${DATA_DIR}/output.${testname}" \ + "./torrc" \ + "$DEFAULTS" \ + "$CMDLINE" \ + "$EXPECTED" \ + ""; then # Check round-trip. - "$TOR_BINARY" -f "${DATA_DIR}/output.${testname}" \ - --defaults-torrc "$EMPTY" \ - --dump-config short \ - > "${DATA_DIR}/output_2_raw.${testname}" \ - || fail_printf "'%s': Tor --dump-config reported an %s." \ - "$EXPECTED" \ - "error on round-trip" + dump_config "${DATA_DIR}/output.${testname}" \ + "$EMPTY" \ + "" \ + "${DATA_DIR}/output_2_raw.${testname}" \ + "$EXPECTED" \ + "on round-trip" - "$FILTER" "${DATA_DIR}/output_2_raw.${testname}" \ - > "${DATA_DIR}/output_2.${testname}" \ - || fail_printf "'%s': Filter '%s' reported an error." \ - "$EXPECTED" \ - "$FILTER" + filter "${DATA_DIR}/output_2_raw.${testname}" \ + "${DATA_DIR}/output_2.${testname}" \ + "$EXPECTED" \ + "on round-trip" - if ! cmp "${DATA_DIR}/output.${testname}" \ - "${DATA_DIR}/output_2.${testname}"; then - fail_printf "'%s': did not match on round-trip:" \ - "$EXPECTED" - diff -u "${DATA_DIR}/output.${testname}" \ - "${DATA_DIR}/output_2.${testname}" >&2 \ - || true - fi - else - if test "$(wc -c < "${DATA_DIR}/output.${testname}")" = 0; then - # There was no output -- probably we failed. - fail_printf "'%s': Tor said:" \ - "$EXPECTED" - "$TOR_BINARY" -f "./torrc" \ - --defaults-torrc "$DEFAULTS" \ - --verify-config \ - $CMDLINE >&2 \ - || true - fi - fail_printf "'%s' did not match:" \ - "$EXPECTED" - diff -u "$EXPECTED" "${DATA_DIR}/output.${testname}" >&2 \ - || true + check_diff "${DATA_DIR}/output.${testname}" \ + "${DATA_DIR}/output_2.${testname}" \ + "${DATA_DIR}/output.${testname}" \ + "$EMPTY" \ + "" \ + "$EXPECTED" \ + "on round-trip" || true fi - if test -f "$EXPECTED_LOG" || test "$NEXT_TEST"; then + if test -f "$EXPECTED_LOG"; then # 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 \ - -f ./torrc \ - --defaults-torrc "$DEFAULTS" \ - $CMDLINE \ - > "${DATA_DIR}/output_log.${testname}" \ - || fail_printf "'%s': Tor --verify-config reported an error." \ - "$EXPECTED_LOG" + verify_config "./torrc" \ + "$DEFAULTS" \ + "$CMDLINE" \ + "${DATA_DIR}/output_log.${testname}" \ + "$TRUE" \ + "$EXPECTED_LOG" \ + "succeed" - expect_log="$(cat "${EXPECTED_LOG}")" - if grep "$expect_log" "${DATA_DIR}/output_log.${testname}" \ - > /dev/null; then - : - else - fail_printf "Expected '%s':\\n%s\\nTor said:" \ - "$EXPECTED_LOG" \ - "$expect_log" - cat "${DATA_DIR}/output_log.${testname}" >&2 - fi - fi - - if test -z "$NEXT_TEST"; then - echo "OK" + check_pattern "$EXPECTED_LOG" \ + "${DATA_DIR}/output_log.${testname}" \ + "log" fi elif test -f "$ERROR"; then # This case should fail: run verify-config and see if it does. if ! test -s "$ERROR"; then - fail_printf "Error file '%s' is empty.%s" \ - "$ERROR" \ - "(Empty error files match any output.)" - continue + if check_empty_pattern "$ERROR" "Error"; then + continue + fi fi - "$TOR_BINARY" --verify-config \ - -f ./torrc \ - --defaults-torrc "$DEFAULTS" \ - $CMDLINE \ - > "${DATA_DIR}/output.${testname}" \ - && fail_printf "'%s': Tor did not report an error." \ - "$ERROR" - - expect_err="$(cat "${ERROR}")" - if grep "$expect_err" "${DATA_DIR}/output.${testname}" > /dev/null; then - echo "OK" - else - fail_printf "Expected '%s':\\n%s\\nTor said:" \ - "$ERROR" \ - "$expect_err" - cat "${DATA_DIR}/output.${testname}" >&2 - fi + verify_config "./torrc" \ + "$DEFAULTS" \ + "$CMDLINE" \ + "${DATA_DIR}/output.${testname}" \ + "$FALSE" \ + "$ERROR" \ + "report an error" + check_pattern "$ERROR" \ + "${DATA_DIR}/output.${testname}" \ + "error" else # This case is not actually configured with a success or a failure. # call that an error. fail_printf "Did not find ${dir}/*expected or ${dir}/*error." fi + if test -z "$NEXT_TEST"; then + echo "OK" + fi + cd "$PREV_DIR" done -exit $FINAL_EXIT +exit "$FINAL_EXIT" From a5628cf5b318a1168d5092e26a79a7d876aa0b28 Mon Sep 17 00:00:00 2001 From: teor Date: Wed, 13 Nov 2019 17:12:30 +1000 Subject: [PATCH 09/15] test/parseconf: Refactor and simplify, stage 2 Remove more duplicate code. Eliminate some arguments. Rewrite some comments. Cleanup after 32451. --- src/test/test_parseconf.sh | 202 +++++++++++++++++++++---------------- 1 file changed, 117 insertions(+), 85 deletions(-) diff --git a/src/test/test_parseconf.sh b/src/test/test_parseconf.sh index edda6c3ef8..816ed97e31 100755 --- a/src/test/test_parseconf.sh +++ b/src/test/test_parseconf.sh @@ -264,11 +264,10 @@ log_verify_config() # Run "tor --dump-config short" on the torrc $1, and defaults torrc $2, which # may be $EMPTY. Pass tor the extra command line arguments $3, which will be -# passed unquoted. -# Send the standard output to $4. +# passed unquoted. Send tor's standard output to $4. +# # If tor fails, fail_printf() using the file name $5, and context $6, -# which may be an empty string. Then run "tor --verify-config", and log tor's -# error messages to stderr. +# which may be an empty string. Then run log_verify_config(). dump_config() { if test "$6"; then @@ -313,21 +312,21 @@ filter() "$CONTEXT" } -# Compare the input file $1, and output file $2. +# Compare the expected file $1, and output file $2. # # If they are different, fail. If this is the first step that failed in this -# test, run log_verify_config with torrc $3, defaults torrc $4, and command +# test, run log_verify_config() with torrc $3, defaults torrc $4, and command # line $5, to log Tor's error messages. Finally, log the differences between # the files. # # If the file contents are identical, returns true. Otherwise, return false. # -# Log failure messages using fail_printf(), with the file name $6, and -# context $7, which may be an empty string. +# Log failure messages using fail_printf(), with the expected file name, and +# context $6, which may be an empty string. check_diff() { - if test "$7"; then - CONTEXT=" $=7" + if test "$6"; then + CONTEXT=" $=6" else CONTEXT="" fi @@ -339,14 +338,14 @@ check_diff() # show tor's logs if test -z "$NEXT_TEST"; then fail_printf "'%s': Tor said%s:" \ - "$6" \ + "$1" \ "$CONTEXT" log_verify_config "$3" \ "$4" \ "$5" fi fail_printf "'%s' did not match%s:" \ - "$6" \ + "$1" \ "$CONTEXT" diff -u "$1" "$2" >&2 \ || true @@ -354,6 +353,50 @@ check_diff() fi } +# Run "tor --dump-config short" on the torrc $1, and defaults torrc $2, which +# may be $EMPTY. Pass tor the extra command line arguments $3, which will be +# passed unquoted. Send tor's standard output to $4, after running $FILTER +# on it. +# +# If tor fails, run log_verify_config(). +# +# Compare the expected file $5, and output file. If they are different, fail. +# If this is the first step that failed in this test, run log_verify_config(). +# +# If the file contents are identical, returns true. Otherwise, return false, +# and log the differences between the files. +# +# Log failure messages using fail_printf(), with the expected file name, and +# context $6, which may be an empty string. +check_dump_config() +{ + OUTPUT="$4" + OUTPUT_RAW="${OUTPUT}_raw" + dump_config "$1" \ + "$2" \ + "$3" \ + "$OUTPUT_RAW" \ + "$5" \ + "$6" + + filter "$OUTPUT_RAW" \ + "$OUTPUT" \ + "$5" \ + "$6" + + if check_diff "$5" \ + "$OUTPUT" \ + "$1" \ + "$2" \ + "$3" \ + "$5" \ + "$6"; then + return "$TRUE" + else + return "$FALSE" + fi +} + # Check if $1 is an empty file. # If it is, fail_printf() using $2 as the type of file. # Returns true if the file is empty, false otherwise. @@ -371,8 +414,8 @@ check_empty_pattern() # Run tor --verify-config on the torrc $1, and defaults torrc $2, which may # be $EMPTY. Pass tor the extra command line arguments $3, which will be -# passed unquoted. -# Send tor's standard output to $4. +# passed unquoted. Send tor's standard output to $4. +# # If tor's exit status does not match the boolean $5, fail_printf() # using the file name $6, and context $7, which is required. verify_config() @@ -394,14 +437,15 @@ verify_config() fi } -# Check for the pattern in file $1, in the lines in the output file $2. -# Uses grep with the entire contents of $1 as the pattern. (Not "grep -f".) +# Check for the patterns in the match file $1, in the output file $2. +# Uses grep with the entire contents of the match file as the pattern. +# (Not "grep -f".) # # If the pattern does not match any lines in the output file, fail. # Log the pattern, and the entire contents of the output file. # -# Log failure messages using fail_printf(), with the file name $1, and -# context $3, which is required. +# Log failure messages using fail_printf(), with the match file name, +# and context $3, which is required. check_pattern() { expect_log="$(cat "$1")" @@ -414,6 +458,40 @@ check_pattern() fi } +# Run tor --verify-config on the torrc $1, and defaults torrc $2, which may +# be $EMPTY. Pass tor the extra command line arguments $3, which will be +# passed unquoted. Send tor's standard output to $4. +# +# If tor's exit status does not match the boolean $5, fail. +# +# Check for the patterns in the match file $6, in the output file. +# Uses grep with the entire contents of the match file as the pattern. +# (Not "grep -f".) The match file must not be empty. +# +# If the pattern does not match any lines in the output file, fail. +# Log the pattern, and the entire contents of the output file. +# +# Log failure messages using fail_printf(), with the match file name, +# and context $7, which is required. +check_verify_config() +{ + if check_empty_pattern "$6" "$7"; then + return + fi + + verify_config "$1" \ + "$2" \ + "$3" \ + "$4" \ + "$5" \ + "$6" \ + "$7" + + check_pattern "$6" \ + "$4" \ + "$7" +} + for dir in "${EXAMPLEDIR}"/*; do NEXT_TEST= @@ -489,89 +567,43 @@ for dir in "${EXAMPLEDIR}"/*; do elif test -f "$EXPECTED"; then # This case should succeed: run dump-config and see if it does. - if test -f "$EXPECTED_LOG"; then - if check_empty_pattern "$EXPECTED_LOG" "Expected log"; then - continue - fi - fi - - dump_config "./torrc" \ - "$DEFAULTS" \ - "$CMDLINE" \ - "${DATA_DIR}/output_raw.${testname}" \ - "$EXPECTED" \ - "" - - filter "${DATA_DIR}/output_raw.${testname}" \ - "${DATA_DIR}/output.${testname}" \ - "$EXPECTED" \ - "" - - if check_diff "$EXPECTED" \ - "${DATA_DIR}/output.${testname}" \ - "./torrc" \ - "$DEFAULTS" \ - "$CMDLINE" \ - "$EXPECTED" \ - ""; then + if check_dump_config "./torrc" \ + "$DEFAULTS" \ + "$CMDLINE" \ + "${DATA_DIR}/output.${testname}" \ + "$EXPECTED" \ + ""; then # Check round-trip. - dump_config "${DATA_DIR}/output.${testname}" \ - "$EMPTY" \ - "" \ - "${DATA_DIR}/output_2_raw.${testname}" \ - "$EXPECTED" \ - "on round-trip" - - filter "${DATA_DIR}/output_2_raw.${testname}" \ - "${DATA_DIR}/output_2.${testname}" \ - "$EXPECTED" \ - "on round-trip" - - check_diff "${DATA_DIR}/output.${testname}" \ - "${DATA_DIR}/output_2.${testname}" \ - "${DATA_DIR}/output.${testname}" \ - "$EMPTY" \ - "" \ - "$EXPECTED" \ - "on round-trip" || true + check_dump_config "${DATA_DIR}/output.${testname}" \ + "$EMPTY" \ + "" \ + "${DATA_DIR}/output_2.${testname}" \ + "$EXPECTED" \ + "on round-trip" || true fi if test -f "$EXPECTED_LOG"; then # This case should succeed: run verify-config and see if it does. - verify_config "./torrc" \ + check_verify_config "./torrc" \ "$DEFAULTS" \ "$CMDLINE" \ "${DATA_DIR}/output_log.${testname}" \ "$TRUE" \ "$EXPECTED_LOG" \ - "succeed" - - check_pattern "$EXPECTED_LOG" \ - "${DATA_DIR}/output_log.${testname}" \ - "log" + "log ok" fi elif test -f "$ERROR"; then # This case should fail: run verify-config and see if it does. - if ! test -s "$ERROR"; then - if check_empty_pattern "$ERROR" "Error"; then - continue - fi - fi - - verify_config "./torrc" \ - "$DEFAULTS" \ - "$CMDLINE" \ - "${DATA_DIR}/output.${testname}" \ - "$FALSE" \ - "$ERROR" \ - "report an error" - - check_pattern "$ERROR" \ - "${DATA_DIR}/output.${testname}" \ - "error" + check_verify_config "./torrc" \ + "$DEFAULTS" \ + "$CMDLINE" \ + "${DATA_DIR}/output.${testname}" \ + "$FALSE" \ + "$ERROR" \ + "log error" else # This case is not actually configured with a success or a failure. # call that an error. From 2c4ada729e275f37a2165866a78378ff606cb451 Mon Sep 17 00:00:00 2001 From: teor Date: Thu, 14 Nov 2019 10:50:20 +1000 Subject: [PATCH 10/15] test/parseconf: Show tor command lines on failure Part of 32451. --- src/test/test_parseconf.sh | 88 +++++++++++++++++++++++++------------- 1 file changed, 59 insertions(+), 29 deletions(-) diff --git a/src/test/test_parseconf.sh b/src/test/test_parseconf.sh index 816ed97e31..2156077d7e 100755 --- a/src/test/test_parseconf.sh +++ b/src/test/test_parseconf.sh @@ -252,6 +252,15 @@ FALSE=1 # Send tor's standard output to stderr. log_verify_config() { + # show the command we're about to execute + # log_verify_config() is only called when we've failed + printf "Tor --verify-config said:\\n" >&2 + printf "$ %s %s %s %s %s %s %s\\n" \ + "$TOR_BINARY" --verify-config \ + -f "$1" \ + --defaults-torrc "$2" \ + "$3" \ + >&2 # We need cmdline unquoted # shellcheck disable=SC2086 "$TOR_BINARY" --verify-config \ @@ -266,6 +275,8 @@ log_verify_config() # may be $EMPTY. Pass tor the extra command line arguments $3, which will be # passed unquoted. Send tor's standard output to $4. # +# Set $FULL_TOR_CMD to the tor command line that was executed. +# # If tor fails, fail_printf() using the file name $5, and context $6, # which may be an empty string. Then run log_verify_config(). dump_config() @@ -276,6 +287,13 @@ dump_config() CONTEXT="" fi + # keep the command we're about to execute, and show if it we fail + FULL_TOR_CMD=$(printf "$ %s %s %s %s %s %s %s %s" \ + "$TOR_BINARY" --dump-config short \ + -f "$1" \ + --defaults-torrc "$2" \ + "$3" + ) # We need cmdline unquoted # shellcheck disable=SC2086 if ! "$TOR_BINARY" --dump-config short \ @@ -283,9 +301,10 @@ dump_config() --defaults-torrc "$2" \ $3 \ > "$4"; then - fail_printf "'%s': Tor --dump-config reported an error%s. Tor said:" \ + fail_printf "'%s': Tor --dump-config reported an error%s:\\n%s" \ "$5" \ - "$CONTEXT" + "$CONTEXT" \ + "$FULL_TOR_CMD" log_verify_config "$1" \ "$2" \ "$3" @@ -314,19 +333,18 @@ filter() # Compare the expected file $1, and output file $2. # -# If they are different, fail. If this is the first step that failed in this -# test, run log_verify_config() with torrc $3, defaults torrc $4, and command -# line $5, to log Tor's error messages. Finally, log the differences between -# the files. +# If they are different, fail. Log the differences between the files. +# Run log_verify_config() with torrc $3, defaults torrc $4, and command +# line $5, to log Tor's error messages. # # If the file contents are identical, returns true. Otherwise, return false. # -# Log failure messages using fail_printf(), with the expected file name, and -# context $6, which may be an empty string. +# Log failure messages using fail_printf(), with the expected file name, +# context $6, which may be an empty string, and the tor command line $7. check_diff() { if test "$6"; then - CONTEXT=" $=6" + CONTEXT=" $6" else CONTEXT="" fi @@ -334,21 +352,15 @@ check_diff() if cmp "$1" "$2" > /dev/null; then return "$TRUE" else - # If this is the first step that failed in this test, - # show tor's logs - if test -z "$NEXT_TEST"; then - fail_printf "'%s': Tor said%s:" \ - "$1" \ - "$CONTEXT" - log_verify_config "$3" \ - "$4" \ - "$5" - fi - fail_printf "'%s' did not match%s:" \ + fail_printf "'%s': Tor --dump-config said%s:\\n%s" \ "$1" \ - "$CONTEXT" + "$CONTEXT" \ + "$7" diff -u "$1" "$2" >&2 \ || true + log_verify_config "$3" \ + "$4" \ + "$5" return "$FALSE" fi } @@ -372,6 +384,8 @@ check_dump_config() { OUTPUT="$4" OUTPUT_RAW="${OUTPUT}_raw" + + FULL_TOR_CMD= dump_config "$1" \ "$2" \ "$3" \ @@ -389,8 +403,8 @@ check_dump_config() "$1" \ "$2" \ "$3" \ - "$5" \ - "$6"; then + "$6" \ + "$FULL_TOR_CMD"; then return "$TRUE" else return "$FALSE" @@ -416,11 +430,21 @@ check_empty_pattern() # be $EMPTY. Pass tor the extra command line arguments $3, which will be # passed unquoted. Send tor's standard output to $4. # +# Set $FULL_TOR_CMD to the tor command line that was executed. +# # If tor's exit status does not match the boolean $5, fail_printf() # using the file name $6, and context $7, which is required. verify_config() { RESULT=$TRUE + + # keep the command we're about to execute, and show if it we fail + FULL_TOR_CMD=$(printf "$ %s %s %s %s %s %s %s" \ + "$TOR_BINARY" --verify-config \ + -f "$1" \ + --defaults-torrc "$2" \ + "$3" + ) # We need cmdline unquoted # shellcheck disable=SC2086 "$TOR_BINARY" --verify-config \ @@ -431,9 +455,11 @@ verify_config() # Convert the actual and expected results to boolean, and compare if test $((! (! RESULT))) -ne $((! (! $5))); then - fail_printf "'%s': Tor --verify-config did not %s." \ + fail_printf "'%s': Tor --verify-config did not %s:\\n%s" \ "$6" \ - "$7" + "$7" \ + "$FULL_TOR_CMD" + cat "$4" >&2 fi } @@ -445,15 +471,17 @@ verify_config() # Log the pattern, and the entire contents of the output file. # # Log failure messages using fail_printf(), with the match file name, -# and context $3, which is required. +# context $3, and tor command line $4, which are required. check_pattern() { expect_log="$(cat "$1")" if ! grep "$expect_log" "$2" > /dev/null; then - fail_printf "Expected %s '%s':\\n%s\\nTor said:" \ + fail_printf "Expected %s '%s':\\n%s" \ "$3" \ "$1" \ "$expect_log" + printf "Tor --verify-config said:\\n%s\\n" \ + "$4" >&2 cat "$2" >&2 fi } @@ -479,6 +507,7 @@ check_verify_config() return fi + FULL_TOR_CMD= verify_config "$1" \ "$2" \ "$3" \ @@ -489,7 +518,8 @@ check_verify_config() check_pattern "$6" \ "$4" \ - "$7" + "$7" \ + "$FULL_TOR_CMD" } for dir in "${EXAMPLEDIR}"/*; do @@ -591,7 +621,7 @@ for dir in "${EXAMPLEDIR}"/*; do "${DATA_DIR}/output_log.${testname}" \ "$TRUE" \ "$EXPECTED_LOG" \ - "log ok" + "log success" fi elif test -f "$ERROR"; then From 51a6c0c8fd147a852a9567f1b1987b686bcc1800 Mon Sep 17 00:00:00 2001 From: teor Date: Thu, 14 Nov 2019 10:54:42 +1000 Subject: [PATCH 11/15] test/parseconf: Stop adding newlines to *_printf Cleanup after 32451. --- src/test/test_parseconf.sh | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/test/test_parseconf.sh b/src/test/test_parseconf.sh index 2156077d7e..2298f0234f 100755 --- a/src/test/test_parseconf.sh +++ b/src/test/test_parseconf.sh @@ -167,7 +167,6 @@ fail_printf() # 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 } @@ -180,7 +179,6 @@ die_printf() # The first argument is a printf string, so this warning is spurious # shellcheck disable=SC2059 printf "$@" >&2 - printf "\\n" >&2 exit $EXITCODE } @@ -191,11 +189,11 @@ else fi EMPTY="${DATA_DIR}/EMPTY" -touch "$EMPTY" || die_printf "Couldn't create empty file '%s'." \ +touch "$EMPTY" || die_printf "Couldn't create empty file '%s'.\\n" \ "$EMPTY" NON_EMPTY="${DATA_DIR}/NON_EMPTY" echo "This pattern should not match any log messages" \ - > "$NON_EMPTY" || die_printf "Couldn't create non-empty file '%s'." \ + > "$NON_EMPTY" || die_printf "Couldn't create non-empty file '%s'.\\n" \ "$NON_EMPTY" STANDARD_LIBS="libevent\\|openssl\\|zlib" @@ -216,7 +214,7 @@ TOR_LIBS_ENABLED=${TOR_LIBS_ENABLED%_} TOR_LIBS_ENABLED_COUNT="$(echo "$TOR_LIBS_ENABLED_SEARCH" \ | tr ' ' '\n' | wc -l)" if test "$TOR_LIBS_ENABLED_COUNT" -gt 3; then - die_printf "Can not handle more than 3 optional libraries" + die_printf "Can not handle more than 3 optional libraries.\\n" fi # Brute-force the combinations of libraries TOR_LIBS_ENABLED_SEARCH_3="$(echo "$TOR_LIBS_ENABLED" \ @@ -301,7 +299,7 @@ dump_config() --defaults-torrc "$2" \ $3 \ > "$4"; then - fail_printf "'%s': Tor --dump-config reported an error%s:\\n%s" \ + fail_printf "'%s': Tor --dump-config reported an error%s:\\n%s\\n" \ "$5" \ "$CONTEXT" \ "$FULL_TOR_CMD" @@ -325,7 +323,7 @@ filter() "$FILTER" "$1" \ > "$2" \ - || fail_printf "'%s': Filter '%s' reported an error%s." \ + || fail_printf "'%s': Filter '%s' reported an error%s.\\n" \ "$3" \ "$FILTER" \ "$CONTEXT" @@ -352,7 +350,7 @@ check_diff() if cmp "$1" "$2" > /dev/null; then return "$TRUE" else - fail_printf "'%s': Tor --dump-config said%s:\\n%s" \ + fail_printf "'%s': Tor --dump-config said%s:\\n%s\\n" \ "$1" \ "$CONTEXT" \ "$7" @@ -417,7 +415,7 @@ check_dump_config() check_empty_pattern() { if ! test -s "$1"; then - fail_printf "%s file '%s' is empty, and will match any output." \ + fail_printf "%s file '%s' is empty, and will match any output.\\n" \ "$2" \ "$1" return "$TRUE" @@ -455,7 +453,7 @@ verify_config() # Convert the actual and expected results to boolean, and compare if test $((! (! RESULT))) -ne $((! (! $5))); then - fail_printf "'%s': Tor --verify-config did not %s:\\n%s" \ + fail_printf "'%s': Tor --verify-config did not %s:\\n%s\\n" \ "$6" \ "$7" \ "$FULL_TOR_CMD" @@ -476,7 +474,7 @@ check_pattern() { expect_log="$(cat "$1")" if ! grep "$expect_log" "$2" > /dev/null; then - fail_printf "Expected %s '%s':\\n%s" \ + fail_printf "Expected %s '%s':\\n%s\\n" \ "$3" \ "$1" \ "$expect_log" @@ -566,7 +564,7 @@ for dir in "${EXAMPLEDIR}"/*; do # Check for broken configs if test -f "./error${suffix}"; then - fail_printf "Found both '%s' and '%s'.%s" \ + fail_printf "Found both '%s' and '%s'.%s\\n" \ "${dir}/expected${suffix}" \ "${dir}/error${suffix}" \ "(Only one of these files should exist.)" @@ -637,7 +635,7 @@ for dir in "${EXAMPLEDIR}"/*; do else # This case is not actually configured with a success or a failure. # call that an error. - fail_printf "Did not find ${dir}/*expected or ${dir}/*error." + fail_printf "Did not find ${dir}/*expected or ${dir}/*error.\\n" fi if test -z "$NEXT_TEST"; then From c7838c71fb3d023c8e255896118c59ed8af688eb Mon Sep 17 00:00:00 2001 From: teor Date: Thu, 14 Nov 2019 10:59:15 +1000 Subject: [PATCH 12/15] test/parseconf: Add failure cases in conf_failures/ These failure cases can be used to test the failure behaviour and failure logs of test_parseconf.sh. See the README for details. Part of 32451. --- src/test/conf_failures/README | 5 +++++ src/test/conf_failures/fail-error-success/error | 1 + src/test/conf_failures/fail-error-success/torrc | 0 src/test/conf_failures/fail-error/error | 1 + src/test/conf_failures/fail-error/torrc | 1 + src/test/conf_failures/fail-expected-error/expected | 0 src/test/conf_failures/fail-expected-error/torrc | 1 + src/test/conf_failures/fail-expected-log/expected | 0 src/test/conf_failures/fail-expected-log/expected_log | 1 + src/test/conf_failures/fail-expected-log/torrc | 0 src/test/conf_failures/fail-expected/expected | 1 + src/test/conf_failures/fail-expected/torrc | 0 12 files changed, 11 insertions(+) create mode 100644 src/test/conf_failures/README create mode 100644 src/test/conf_failures/fail-error-success/error create mode 100644 src/test/conf_failures/fail-error-success/torrc create mode 100644 src/test/conf_failures/fail-error/error create mode 100644 src/test/conf_failures/fail-error/torrc create mode 100644 src/test/conf_failures/fail-expected-error/expected create mode 100644 src/test/conf_failures/fail-expected-error/torrc create mode 100644 src/test/conf_failures/fail-expected-log/expected create mode 100644 src/test/conf_failures/fail-expected-log/expected_log create mode 100644 src/test/conf_failures/fail-expected-log/torrc create mode 100644 src/test/conf_failures/fail-expected/expected create mode 100644 src/test/conf_failures/fail-expected/torrc diff --git a/src/test/conf_failures/README b/src/test/conf_failures/README new file mode 100644 index 0000000000..0da470eeb4 --- /dev/null +++ b/src/test/conf_failures/README @@ -0,0 +1,5 @@ +This directory contains typical test_parseconf.sh failure cases. + +If these directories are copied into conf_examples, test_parseconf.sh will +fail. Use these failure cases to make sure test_parseconf.sh handles failures +correctly, and produces useful output. diff --git a/src/test/conf_failures/fail-error-success/error b/src/test/conf_failures/fail-error-success/error new file mode 100644 index 0000000000..569a631e86 --- /dev/null +++ b/src/test/conf_failures/fail-error-success/error @@ -0,0 +1 @@ +Tor diff --git a/src/test/conf_failures/fail-error-success/torrc b/src/test/conf_failures/fail-error-success/torrc new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/test/conf_failures/fail-error/error b/src/test/conf_failures/fail-error/error new file mode 100644 index 0000000000..4c0be97832 --- /dev/null +++ b/src/test/conf_failures/fail-error/error @@ -0,0 +1 @@ +no match diff --git a/src/test/conf_failures/fail-error/torrc b/src/test/conf_failures/fail-error/torrc new file mode 100644 index 0000000000..bb6fe186a4 --- /dev/null +++ b/src/test/conf_failures/fail-error/torrc @@ -0,0 +1 @@ +bad bad bad diff --git a/src/test/conf_failures/fail-expected-error/expected b/src/test/conf_failures/fail-expected-error/expected new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/test/conf_failures/fail-expected-error/torrc b/src/test/conf_failures/fail-expected-error/torrc new file mode 100644 index 0000000000..bb6fe186a4 --- /dev/null +++ b/src/test/conf_failures/fail-expected-error/torrc @@ -0,0 +1 @@ +bad bad bad diff --git a/src/test/conf_failures/fail-expected-log/expected b/src/test/conf_failures/fail-expected-log/expected new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/test/conf_failures/fail-expected-log/expected_log b/src/test/conf_failures/fail-expected-log/expected_log new file mode 100644 index 0000000000..bb6fe186a4 --- /dev/null +++ b/src/test/conf_failures/fail-expected-log/expected_log @@ -0,0 +1 @@ +bad bad bad diff --git a/src/test/conf_failures/fail-expected-log/torrc b/src/test/conf_failures/fail-expected-log/torrc new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/test/conf_failures/fail-expected/expected b/src/test/conf_failures/fail-expected/expected new file mode 100644 index 0000000000..67be85f127 --- /dev/null +++ b/src/test/conf_failures/fail-expected/expected @@ -0,0 +1 @@ +bad diff --git a/src/test/conf_failures/fail-expected/torrc b/src/test/conf_failures/fail-expected/torrc new file mode 100644 index 0000000000..e69de29bb2 From ced434c5869da6d6c7ac4c11a934a4d58a730afe Mon Sep 17 00:00:00 2001 From: teor Date: Tue, 12 Nov 2019 15:10:07 +1000 Subject: [PATCH 13/15] test/parseconf: Update conf_examples to use expected_log Part of 32451. --- .../badnick_1/expected_log_no_dirauth_relay | 1 + .../badnick_2/expected_log_no_dirauth_relay | 1 + .../conf_examples/bridgeauth_1/expected_log | 1 + .../expected_log_no_dirauth_relay | 1 + .../conf_examples/crypto_accel/expected_log | 1 + .../expected_log_nss} | 0 .../conf_examples/crypto_accel/expected_nss | 2 + .../crypto_accel_req/expected_log_nss | 1 + src/test/conf_examples/dirauth_1/expected_log | 1 + src/test/conf_examples/empty_1/expected_log | 1 + src/test/conf_examples/empty_2/expected_log | 1 + src/test/conf_examples/empty_3/expected_log | 1 + src/test/conf_examples/example_1/expected_log | 1 + src/test/conf_examples/example_3/expected_log | 1 + src/test/conf_examples/include_1/expected_log | 1 + .../include_bug_31408/expected_log | 1 + src/test/conf_examples/large_1/expected_log | 1 + src/test/conf_examples/lzma_zstd_1/expected | 0 .../lzma_zstd_1/{error => expected_log} | 0 .../{error_lzma => expected_log_lzma} | 0 ...error_lzma_zstd => expected_log_lzma_zstd} | 0 .../{error_zstd => expected_log_zstd} | 0 .../conf_examples/lzma_zstd_1/expected_lzma | 0 .../lzma_zstd_1/expected_lzma_zstd | 0 .../conf_examples/lzma_zstd_1/expected_zstd | 0 src/test/conf_examples/lzma_zstd_1/torrc | 5 +- src/test/conf_examples/nss_1/expected | 0 .../nss_1/{error => expected_log} | 0 src/test/conf_examples/nss_1/expected_log_nss | 1 + src/test/conf_examples/nss_1/expected_nss | 0 src/test/conf_examples/nss_1/torrc | 5 +- .../conf_examples/obsolete_1/expected_log | 1 + src/test/conf_examples/obsolete_1/torrc | 136 +++++++++--------- .../conf_examples/obsolete_2/expected_log | 1 + src/test/conf_examples/obsolete_2/torrc | 3 + src/test/conf_examples/obsolete_3/expected | 0 .../conf_examples/obsolete_3/expected_log | 1 + src/test/conf_examples/obsolete_3/torrc | 4 + src/test/conf_examples/ops_1/expected_log | 1 + src/test/conf_examples/ops_2/expected_log | 1 + src/test/conf_examples/ops_3/expected_log | 1 + src/test/conf_examples/ops_4/expected_log | 1 + src/test/conf_examples/ops_5/expected_log | 1 + src/test/conf_examples/ops_6/expected_log | 1 + src/test/conf_examples/pt_01/expected_log | 1 + .../pt_02/expected_log_no_dirauth_relay | 1 + src/test/conf_examples/pt_03/expected_log | 1 + .../pt_03/expected_log_no_dirauth_relay | 1 + .../pt_03/expected_no_dirauth_relay | 1 + src/test/conf_examples/pt_04/expected_log | 1 + .../pt_04/expected_log_no_dirauth_relay | 1 + .../pt_04/expected_no_dirauth_relay | 3 + src/test/conf_examples/pt_05/expected_log | 1 + src/test/conf_examples/pt_06/expected_log | 1 + .../pt_06/expected_log_no_dirauth_relay | 1 + .../pt_06/expected_no_dirauth_relay | 6 + src/test/conf_examples/pt_07/expected_log | 1 + .../pt_08/expected_log_no_dirauth_relay | 1 + src/test/conf_examples/relay_01/expected_log | 1 + src/test/conf_examples/relay_03/expected_log | 1 + src/test/conf_examples/relay_04/expected_log | 1 + src/test/conf_examples/relay_05/expected_log | 1 + src/test/conf_examples/relay_06/expected_log | 1 + src/test/conf_examples/relay_07/expected_log | 1 + src/test/conf_examples/relay_08/expected_log | 1 + src/test/conf_examples/relay_09/expected_log | 1 + src/test/conf_examples/relay_10/expected_log | 1 + src/test/conf_examples/relay_14/expected_log | 1 + src/test/conf_examples/relay_17/expected_log | 1 + src/test/conf_examples/relay_19/expected_log | 1 + src/test/conf_examples/relay_21/expected_log | 1 + src/test/conf_examples/relay_29/expected_log | 1 + 72 files changed, 140 insertions(+), 75 deletions(-) create mode 100644 src/test/conf_examples/badnick_1/expected_log_no_dirauth_relay create mode 100644 src/test/conf_examples/badnick_2/expected_log_no_dirauth_relay create mode 100644 src/test/conf_examples/bridgeauth_1/expected_log create mode 100644 src/test/conf_examples/contactinfo_notutf8/expected_log_no_dirauth_relay create mode 100644 src/test/conf_examples/crypto_accel/expected_log rename src/test/conf_examples/{nss_1/error_nss => crypto_accel/expected_log_nss} (100%) create mode 100644 src/test/conf_examples/crypto_accel/expected_nss create mode 100644 src/test/conf_examples/crypto_accel_req/expected_log_nss create mode 100644 src/test/conf_examples/dirauth_1/expected_log create mode 100644 src/test/conf_examples/empty_1/expected_log create mode 100644 src/test/conf_examples/empty_2/expected_log create mode 100644 src/test/conf_examples/empty_3/expected_log create mode 100644 src/test/conf_examples/example_1/expected_log create mode 100644 src/test/conf_examples/example_3/expected_log create mode 100644 src/test/conf_examples/include_1/expected_log create mode 100644 src/test/conf_examples/include_bug_31408/expected_log create mode 100644 src/test/conf_examples/large_1/expected_log create mode 100644 src/test/conf_examples/lzma_zstd_1/expected rename src/test/conf_examples/lzma_zstd_1/{error => expected_log} (100%) rename src/test/conf_examples/lzma_zstd_1/{error_lzma => expected_log_lzma} (100%) rename src/test/conf_examples/lzma_zstd_1/{error_lzma_zstd => expected_log_lzma_zstd} (100%) rename src/test/conf_examples/lzma_zstd_1/{error_zstd => expected_log_zstd} (100%) create mode 100644 src/test/conf_examples/lzma_zstd_1/expected_lzma create mode 100644 src/test/conf_examples/lzma_zstd_1/expected_lzma_zstd create mode 100644 src/test/conf_examples/lzma_zstd_1/expected_zstd create mode 100644 src/test/conf_examples/nss_1/expected rename src/test/conf_examples/nss_1/{error => expected_log} (100%) create mode 100644 src/test/conf_examples/nss_1/expected_log_nss create mode 100644 src/test/conf_examples/nss_1/expected_nss create mode 100644 src/test/conf_examples/obsolete_1/expected_log create mode 100644 src/test/conf_examples/obsolete_2/expected_log create mode 100644 src/test/conf_examples/obsolete_3/expected create mode 100644 src/test/conf_examples/obsolete_3/expected_log create mode 100644 src/test/conf_examples/obsolete_3/torrc create mode 100644 src/test/conf_examples/ops_1/expected_log create mode 100644 src/test/conf_examples/ops_2/expected_log create mode 100644 src/test/conf_examples/ops_3/expected_log create mode 100644 src/test/conf_examples/ops_4/expected_log create mode 100644 src/test/conf_examples/ops_5/expected_log create mode 100644 src/test/conf_examples/ops_6/expected_log create mode 100644 src/test/conf_examples/pt_01/expected_log create mode 100644 src/test/conf_examples/pt_02/expected_log_no_dirauth_relay create mode 100644 src/test/conf_examples/pt_03/expected_log create mode 100644 src/test/conf_examples/pt_03/expected_log_no_dirauth_relay create mode 100644 src/test/conf_examples/pt_03/expected_no_dirauth_relay create mode 100644 src/test/conf_examples/pt_04/expected_log create mode 100644 src/test/conf_examples/pt_04/expected_log_no_dirauth_relay create mode 100644 src/test/conf_examples/pt_04/expected_no_dirauth_relay create mode 100644 src/test/conf_examples/pt_05/expected_log create mode 100644 src/test/conf_examples/pt_06/expected_log create mode 100644 src/test/conf_examples/pt_06/expected_log_no_dirauth_relay create mode 100644 src/test/conf_examples/pt_06/expected_no_dirauth_relay create mode 100644 src/test/conf_examples/pt_07/expected_log create mode 100644 src/test/conf_examples/pt_08/expected_log_no_dirauth_relay create mode 100644 src/test/conf_examples/relay_01/expected_log create mode 100644 src/test/conf_examples/relay_03/expected_log create mode 100644 src/test/conf_examples/relay_04/expected_log create mode 100644 src/test/conf_examples/relay_05/expected_log create mode 100644 src/test/conf_examples/relay_06/expected_log create mode 100644 src/test/conf_examples/relay_07/expected_log create mode 100644 src/test/conf_examples/relay_08/expected_log create mode 100644 src/test/conf_examples/relay_09/expected_log create mode 100644 src/test/conf_examples/relay_10/expected_log create mode 100644 src/test/conf_examples/relay_14/expected_log create mode 100644 src/test/conf_examples/relay_17/expected_log create mode 100644 src/test/conf_examples/relay_19/expected_log create mode 100644 src/test/conf_examples/relay_21/expected_log create mode 100644 src/test/conf_examples/relay_29/expected_log diff --git a/src/test/conf_examples/badnick_1/expected_log_no_dirauth_relay b/src/test/conf_examples/badnick_1/expected_log_no_dirauth_relay new file mode 100644 index 0000000000..9190a3326b --- /dev/null +++ b/src/test/conf_examples/badnick_1/expected_log_no_dirauth_relay @@ -0,0 +1 @@ +Read configuration file .*badnick_1[./]*torrc diff --git a/src/test/conf_examples/badnick_2/expected_log_no_dirauth_relay b/src/test/conf_examples/badnick_2/expected_log_no_dirauth_relay new file mode 100644 index 0000000000..a15c7b02cb --- /dev/null +++ b/src/test/conf_examples/badnick_2/expected_log_no_dirauth_relay @@ -0,0 +1 @@ +Read configuration file .*badnick_2[./]*torrc diff --git a/src/test/conf_examples/bridgeauth_1/expected_log b/src/test/conf_examples/bridgeauth_1/expected_log new file mode 100644 index 0000000000..cabe9d3f89 --- /dev/null +++ b/src/test/conf_examples/bridgeauth_1/expected_log @@ -0,0 +1 @@ +Read configuration file .*bridgeauth_1[./]*torrc diff --git a/src/test/conf_examples/contactinfo_notutf8/expected_log_no_dirauth_relay b/src/test/conf_examples/contactinfo_notutf8/expected_log_no_dirauth_relay new file mode 100644 index 0000000000..caa07aca40 --- /dev/null +++ b/src/test/conf_examples/contactinfo_notutf8/expected_log_no_dirauth_relay @@ -0,0 +1 @@ +Read configuration file .*contactinfo_notutf8[./]*torrc diff --git a/src/test/conf_examples/crypto_accel/expected_log b/src/test/conf_examples/crypto_accel/expected_log new file mode 100644 index 0000000000..7fab0c8dad --- /dev/null +++ b/src/test/conf_examples/crypto_accel/expected_log @@ -0,0 +1 @@ +Unable to load dynamic OpenSSL engine "nonexistent_chartreuse_accelerator" diff --git a/src/test/conf_examples/nss_1/error_nss b/src/test/conf_examples/crypto_accel/expected_log_nss similarity index 100% rename from src/test/conf_examples/nss_1/error_nss rename to src/test/conf_examples/crypto_accel/expected_log_nss diff --git a/src/test/conf_examples/crypto_accel/expected_nss b/src/test/conf_examples/crypto_accel/expected_nss new file mode 100644 index 0000000000..ea80ca19dc --- /dev/null +++ b/src/test/conf_examples/crypto_accel/expected_nss @@ -0,0 +1,2 @@ +AccelName nonexistent_chartreuse_accelerator +HardwareAccel 1 diff --git a/src/test/conf_examples/crypto_accel_req/expected_log_nss b/src/test/conf_examples/crypto_accel_req/expected_log_nss new file mode 100644 index 0000000000..c0fe7b003c --- /dev/null +++ b/src/test/conf_examples/crypto_accel_req/expected_log_nss @@ -0,0 +1 @@ +Tor 0.* running on .* with Libevent .*, NSS .*, Zlib .*, Liblzma .*, and Libzstd .* diff --git a/src/test/conf_examples/dirauth_1/expected_log b/src/test/conf_examples/dirauth_1/expected_log new file mode 100644 index 0000000000..b788be2e33 --- /dev/null +++ b/src/test/conf_examples/dirauth_1/expected_log @@ -0,0 +1 @@ +Read configuration file .*dirauth_1[./]*torrc diff --git a/src/test/conf_examples/empty_1/expected_log b/src/test/conf_examples/empty_1/expected_log new file mode 100644 index 0000000000..4c6b00069f --- /dev/null +++ b/src/test/conf_examples/empty_1/expected_log @@ -0,0 +1 @@ +Read configuration file .*empty_1[./]*torrc diff --git a/src/test/conf_examples/empty_2/expected_log b/src/test/conf_examples/empty_2/expected_log new file mode 100644 index 0000000000..9c846a03f3 --- /dev/null +++ b/src/test/conf_examples/empty_2/expected_log @@ -0,0 +1 @@ +Read configuration file .*empty_2[./]*torrc\.defaults diff --git a/src/test/conf_examples/empty_3/expected_log b/src/test/conf_examples/empty_3/expected_log new file mode 100644 index 0000000000..a42514f37f --- /dev/null +++ b/src/test/conf_examples/empty_3/expected_log @@ -0,0 +1 @@ +Included configuration .*directory at recursion level 1.*included diff --git a/src/test/conf_examples/example_1/expected_log b/src/test/conf_examples/example_1/expected_log new file mode 100644 index 0000000000..8f83eec988 --- /dev/null +++ b/src/test/conf_examples/example_1/expected_log @@ -0,0 +1 @@ +Read configuration file .*example_1[./]*torrc diff --git a/src/test/conf_examples/example_3/expected_log b/src/test/conf_examples/example_3/expected_log new file mode 100644 index 0000000000..807f9c2fc8 --- /dev/null +++ b/src/test/conf_examples/example_3/expected_log @@ -0,0 +1 @@ +Read configuration file .*example_3[./]*torrc diff --git a/src/test/conf_examples/include_1/expected_log b/src/test/conf_examples/include_1/expected_log new file mode 100644 index 0000000000..f95cad040d --- /dev/null +++ b/src/test/conf_examples/include_1/expected_log @@ -0,0 +1 @@ +Included configuration file .*at recursion level 2.*nested\.inc diff --git a/src/test/conf_examples/include_bug_31408/expected_log b/src/test/conf_examples/include_bug_31408/expected_log new file mode 100644 index 0000000000..a42514f37f --- /dev/null +++ b/src/test/conf_examples/include_bug_31408/expected_log @@ -0,0 +1 @@ +Included configuration .*directory at recursion level 1.*included diff --git a/src/test/conf_examples/large_1/expected_log b/src/test/conf_examples/large_1/expected_log new file mode 100644 index 0000000000..21248bb5e4 --- /dev/null +++ b/src/test/conf_examples/large_1/expected_log @@ -0,0 +1 @@ +Your log may contain sensitive information diff --git a/src/test/conf_examples/lzma_zstd_1/expected b/src/test/conf_examples/lzma_zstd_1/expected new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/test/conf_examples/lzma_zstd_1/error b/src/test/conf_examples/lzma_zstd_1/expected_log similarity index 100% rename from src/test/conf_examples/lzma_zstd_1/error rename to src/test/conf_examples/lzma_zstd_1/expected_log diff --git a/src/test/conf_examples/lzma_zstd_1/error_lzma b/src/test/conf_examples/lzma_zstd_1/expected_log_lzma similarity index 100% rename from src/test/conf_examples/lzma_zstd_1/error_lzma rename to src/test/conf_examples/lzma_zstd_1/expected_log_lzma diff --git a/src/test/conf_examples/lzma_zstd_1/error_lzma_zstd b/src/test/conf_examples/lzma_zstd_1/expected_log_lzma_zstd similarity index 100% rename from src/test/conf_examples/lzma_zstd_1/error_lzma_zstd rename to src/test/conf_examples/lzma_zstd_1/expected_log_lzma_zstd diff --git a/src/test/conf_examples/lzma_zstd_1/error_zstd b/src/test/conf_examples/lzma_zstd_1/expected_log_zstd similarity index 100% rename from src/test/conf_examples/lzma_zstd_1/error_zstd rename to src/test/conf_examples/lzma_zstd_1/expected_log_zstd diff --git a/src/test/conf_examples/lzma_zstd_1/expected_lzma b/src/test/conf_examples/lzma_zstd_1/expected_lzma new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/test/conf_examples/lzma_zstd_1/expected_lzma_zstd b/src/test/conf_examples/lzma_zstd_1/expected_lzma_zstd new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/test/conf_examples/lzma_zstd_1/expected_zstd b/src/test/conf_examples/lzma_zstd_1/expected_zstd new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/test/conf_examples/lzma_zstd_1/torrc b/src/test/conf_examples/lzma_zstd_1/torrc index 91a4656b77..f873d79028 100644 --- a/src/test/conf_examples/lzma_zstd_1/torrc +++ b/src/test/conf_examples/lzma_zstd_1/torrc @@ -1,4 +1 @@ -# Deliberately bad options, to cause an error message -# But this test actually checks for the optional library list in tor's logs, -# not the error message -bad bad bad \ No newline at end of file +# This test checks for the optional library list in tor's logs diff --git a/src/test/conf_examples/nss_1/expected b/src/test/conf_examples/nss_1/expected new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/test/conf_examples/nss_1/error b/src/test/conf_examples/nss_1/expected_log similarity index 100% rename from src/test/conf_examples/nss_1/error rename to src/test/conf_examples/nss_1/expected_log diff --git a/src/test/conf_examples/nss_1/expected_log_nss b/src/test/conf_examples/nss_1/expected_log_nss new file mode 100644 index 0000000000..c0fe7b003c --- /dev/null +++ b/src/test/conf_examples/nss_1/expected_log_nss @@ -0,0 +1 @@ +Tor 0.* running on .* with Libevent .*, NSS .*, Zlib .*, Liblzma .*, and Libzstd .* diff --git a/src/test/conf_examples/nss_1/expected_nss b/src/test/conf_examples/nss_1/expected_nss new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/test/conf_examples/nss_1/torrc b/src/test/conf_examples/nss_1/torrc index 91a4656b77..f873d79028 100644 --- a/src/test/conf_examples/nss_1/torrc +++ b/src/test/conf_examples/nss_1/torrc @@ -1,4 +1 @@ -# Deliberately bad options, to cause an error message -# But this test actually checks for the optional library list in tor's logs, -# not the error message -bad bad bad \ No newline at end of file +# This test checks for the optional library list in tor's logs diff --git a/src/test/conf_examples/obsolete_1/expected_log b/src/test/conf_examples/obsolete_1/expected_log new file mode 100644 index 0000000000..52f6f70a2e --- /dev/null +++ b/src/test/conf_examples/obsolete_1/expected_log @@ -0,0 +1 @@ +Skipping obsolete configuration option diff --git a/src/test/conf_examples/obsolete_1/torrc b/src/test/conf_examples/obsolete_1/torrc index 3cd9a6d777..e711fe4065 100644 --- a/src/test/conf_examples/obsolete_1/torrc +++ b/src/test/conf_examples/obsolete_1/torrc @@ -1,68 +1,70 @@ # These options are obsolete as of 0.4.2 -AllowDotExit -AllowInvalidNodes -AllowSingleHopCircuits -AllowSingleHopExits -AlternateHSAuthority -AuthDirBadDir -AuthDirBadDirCCs -AuthDirRejectUnlisted -AuthDirListBadDirs -AuthDirMaxServersPerAuthAddr -CircuitIdleTimeout -ControlListenAddress -DirListenAddress -DisableIOCP -DisableV2DirectoryInfo_ -DynamicDHGroups -DNSListenAddress -TestingEnableTbEmptyEvent -ExcludeSingleHopRelays -FallbackNetworkstatusFile -FastFirstHopPK -FetchV2Networkstatus -Group -HidServDirectoryV2 -CloseHSClientCircuitsImmediatelyOnTimeout -CloseHSServiceRendCircuitsImmediatelyOnTimeout -MaxOnionsPending -NamingAuthoritativeDirectory -NATDListenAddress -PredictedPortsRelevanceTime -WarnUnsafeSocks -ORListenAddress -PathBiasDisableRate -PathBiasScaleFactor -PathBiasMultFactor -PathBiasUseCloseCounts -PortForwarding -PortForwardingHelper -PreferTunneledDirConns -RecommendedPackages -RunTesting -SchedulerLowWaterMark__ -SchedulerHighWaterMark__ -SchedulerMaxFlushCells__ -SocksListenAddress -StrictEntryNodes -StrictExitNodes -Support022HiddenServices -Tor2webMode -Tor2webRendezvousPoints -TLSECGroup -TransListenAddress -TunnelDirConns -UseEntryGuardsAsDirGuards -UseNTorHandshake -UserspaceIOCPBuffers -V1AuthoritativeDirectory -V2AuthoritativeDirectory -VoteOnHidServDirectoriesV2 -UseFilteringSSLBufferevents -__UseFilteringSSLBufferevents -TestingConsensusMaxDownloadTries -ClientBootstrapConsensusMaxDownloadTries -ClientBootstrapConsensusAuthorityOnlyMaxDownloadTries -TestingDescriptorMaxDownloadTries -TestingMicrodescMaxDownloadTries -TestingCertMaxDownloadTries +# Obsolete options without arguments, or with an empty argument, +# are silently ignored. So we give each one of these options an argument. +AllowDotExit 1 +AllowInvalidNodes 1 +AllowSingleHopCircuits 1 +AllowSingleHopExits 1 +AlternateHSAuthority 1 +AuthDirBadDir 1 +AuthDirBadDirCCs 1 +AuthDirRejectUnlisted 1 +AuthDirListBadDirs 1 +AuthDirMaxServersPerAuthAddr 1 +CircuitIdleTimeout 1 +ControlListenAddress 1 +DirListenAddress 1 +DisableIOCP 1 +DisableV2DirectoryInfo_ 1 +DynamicDHGroups 1 +DNSListenAddress 1 +TestingEnableTbEmptyEvent 1 +ExcludeSingleHopRelays 1 +FallbackNetworkstatusFile 1 +FastFirstHopPK 1 +FetchV2Networkstatus 1 +Group 1 +HidServDirectoryV2 1 +CloseHSClientCircuitsImmediatelyOnTimeout 1 +CloseHSServiceRendCircuitsImmediatelyOnTimeout 1 +MaxOnionsPending 1 +NamingAuthoritativeDirectory 1 +NATDListenAddress 1 +PredictedPortsRelevanceTime 1 +WarnUnsafeSocks 1 +ORListenAddress 1 +PathBiasDisableRate 1 +PathBiasScaleFactor 1 +PathBiasMultFactor 1 +PathBiasUseCloseCounts 1 +PortForwarding 1 +PortForwardingHelper 1 +PreferTunneledDirConns 1 +RecommendedPackages 1 +RunTesting 1 +SchedulerLowWaterMark__ 1 +SchedulerHighWaterMark__ 1 +SchedulerMaxFlushCells__ 1 +SocksListenAddress 1 +StrictEntryNodes 1 +StrictExitNodes 1 +Support022HiddenServices 1 +Tor2webMode 1 +Tor2webRendezvousPoints 1 +TLSECGroup 1 +TransListenAddress 1 +TunnelDirConns 1 +UseEntryGuardsAsDirGuards 1 +UseNTorHandshake 1 +UserspaceIOCPBuffers 1 +V1AuthoritativeDirectory 1 +V2AuthoritativeDirectory 1 +VoteOnHidServDirectoriesV2 1 +UseFilteringSSLBufferevents 1 +__UseFilteringSSLBufferevents 1 +TestingConsensusMaxDownloadTries 1 +ClientBootstrapConsensusMaxDownloadTries 1 +ClientBootstrapConsensusAuthorityOnlyMaxDownloadTries 1 +TestingDescriptorMaxDownloadTries 1 +TestingMicrodescMaxDownloadTries 1 +TestingCertMaxDownloadTries 1 diff --git a/src/test/conf_examples/obsolete_2/expected_log b/src/test/conf_examples/obsolete_2/expected_log new file mode 100644 index 0000000000..2160355ee9 --- /dev/null +++ b/src/test/conf_examples/obsolete_2/expected_log @@ -0,0 +1 @@ +Read configuration file .*obsolete_2[./]*torrc diff --git a/src/test/conf_examples/obsolete_2/torrc b/src/test/conf_examples/obsolete_2/torrc index 4f78d47625..b83e7a7369 100644 --- a/src/test/conf_examples/obsolete_2/torrc +++ b/src/test/conf_examples/obsolete_2/torrc @@ -1,2 +1,5 @@ # This option has been obsolete for some time +# Obsolete options without arguments, or with an empty argument, +# are silently ignored. AllowDotExit +AllowInvalidNodes "" diff --git a/src/test/conf_examples/obsolete_3/expected b/src/test/conf_examples/obsolete_3/expected new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/test/conf_examples/obsolete_3/expected_log b/src/test/conf_examples/obsolete_3/expected_log new file mode 100644 index 0000000000..82d76ec818 --- /dev/null +++ b/src/test/conf_examples/obsolete_3/expected_log @@ -0,0 +1 @@ +Skipping obsolete configuration option "AllowDotExit" diff --git a/src/test/conf_examples/obsolete_3/torrc b/src/test/conf_examples/obsolete_3/torrc new file mode 100644 index 0000000000..e0efe752bf --- /dev/null +++ b/src/test/conf_examples/obsolete_3/torrc @@ -0,0 +1,4 @@ +# This option has been obsolete for some time +# Obsolete options without arguments, or with an empty argument, +# are silently ignored. So we give this option an argument. +AllowDotExit 1 diff --git a/src/test/conf_examples/ops_1/expected_log b/src/test/conf_examples/ops_1/expected_log new file mode 100644 index 0000000000..b785d7fb52 --- /dev/null +++ b/src/test/conf_examples/ops_1/expected_log @@ -0,0 +1 @@ +Read configuration file .*ops_1[./]*torrc diff --git a/src/test/conf_examples/ops_2/expected_log b/src/test/conf_examples/ops_2/expected_log new file mode 100644 index 0000000000..17fbc3ffbf --- /dev/null +++ b/src/test/conf_examples/ops_2/expected_log @@ -0,0 +1 @@ +Read configuration file .*ops_2[./]*torrc diff --git a/src/test/conf_examples/ops_3/expected_log b/src/test/conf_examples/ops_3/expected_log new file mode 100644 index 0000000000..151498f0df --- /dev/null +++ b/src/test/conf_examples/ops_3/expected_log @@ -0,0 +1 @@ +Read configuration file .*ops_3[./]*torrc diff --git a/src/test/conf_examples/ops_4/expected_log b/src/test/conf_examples/ops_4/expected_log new file mode 100644 index 0000000000..7632b2290c --- /dev/null +++ b/src/test/conf_examples/ops_4/expected_log @@ -0,0 +1 @@ +Read configuration file .*ops_4[./]*torrc\.defaults diff --git a/src/test/conf_examples/ops_5/expected_log b/src/test/conf_examples/ops_5/expected_log new file mode 100644 index 0000000000..ec63cb0638 --- /dev/null +++ b/src/test/conf_examples/ops_5/expected_log @@ -0,0 +1 @@ +Read configuration file .*ops_5[./]*torrc\.defaults diff --git a/src/test/conf_examples/ops_6/expected_log b/src/test/conf_examples/ops_6/expected_log new file mode 100644 index 0000000000..f9b1ca0412 --- /dev/null +++ b/src/test/conf_examples/ops_6/expected_log @@ -0,0 +1 @@ +Read configuration file .*ops_6[./]*torrc\.defaults diff --git a/src/test/conf_examples/pt_01/expected_log b/src/test/conf_examples/pt_01/expected_log new file mode 100644 index 0000000000..65bfa7a7b7 --- /dev/null +++ b/src/test/conf_examples/pt_01/expected_log @@ -0,0 +1 @@ +Linelist option 'ExtORPort' has no value\. Skipping diff --git a/src/test/conf_examples/pt_02/expected_log_no_dirauth_relay b/src/test/conf_examples/pt_02/expected_log_no_dirauth_relay new file mode 100644 index 0000000000..0e48dca7fd --- /dev/null +++ b/src/test/conf_examples/pt_02/expected_log_no_dirauth_relay @@ -0,0 +1 @@ +Read configuration file .*pt_02[./]*torrc diff --git a/src/test/conf_examples/pt_03/expected_log b/src/test/conf_examples/pt_03/expected_log new file mode 100644 index 0000000000..285a189c28 --- /dev/null +++ b/src/test/conf_examples/pt_03/expected_log @@ -0,0 +1 @@ +We use pluggable transports but the Extended ORPort is disabled diff --git a/src/test/conf_examples/pt_03/expected_log_no_dirauth_relay b/src/test/conf_examples/pt_03/expected_log_no_dirauth_relay new file mode 100644 index 0000000000..88f4e5bdfb --- /dev/null +++ b/src/test/conf_examples/pt_03/expected_log_no_dirauth_relay @@ -0,0 +1 @@ +Read configuration file .*pt_03[./]*torrc diff --git a/src/test/conf_examples/pt_03/expected_no_dirauth_relay b/src/test/conf_examples/pt_03/expected_no_dirauth_relay new file mode 100644 index 0000000000..f849f2a78f --- /dev/null +++ b/src/test/conf_examples/pt_03/expected_no_dirauth_relay @@ -0,0 +1 @@ +ServerTransportPlugin bad3 exec / diff --git a/src/test/conf_examples/pt_04/expected_log b/src/test/conf_examples/pt_04/expected_log new file mode 100644 index 0000000000..5b3ab51d25 --- /dev/null +++ b/src/test/conf_examples/pt_04/expected_log @@ -0,0 +1 @@ +Tor is not configured as a relay but you specified a ServerTransportPlugin line.*The ServerTransportPlugin line will be ignored diff --git a/src/test/conf_examples/pt_04/expected_log_no_dirauth_relay b/src/test/conf_examples/pt_04/expected_log_no_dirauth_relay new file mode 100644 index 0000000000..2b989bf320 --- /dev/null +++ b/src/test/conf_examples/pt_04/expected_log_no_dirauth_relay @@ -0,0 +1 @@ +Read configuration file .*pt_04[./]*torrc diff --git a/src/test/conf_examples/pt_04/expected_no_dirauth_relay b/src/test/conf_examples/pt_04/expected_no_dirauth_relay new file mode 100644 index 0000000000..9087f600e0 --- /dev/null +++ b/src/test/conf_examples/pt_04/expected_no_dirauth_relay @@ -0,0 +1,3 @@ +ExtORPortCookieAuthFile / +ExtORPort 1 +ServerTransportPlugin bad3 exec / diff --git a/src/test/conf_examples/pt_05/expected_log b/src/test/conf_examples/pt_05/expected_log new file mode 100644 index 0000000000..c05a0931d6 --- /dev/null +++ b/src/test/conf_examples/pt_05/expected_log @@ -0,0 +1 @@ +Your ContactInfo config option is not set diff --git a/src/test/conf_examples/pt_06/expected_log b/src/test/conf_examples/pt_06/expected_log new file mode 100644 index 0000000000..5b3ab51d25 --- /dev/null +++ b/src/test/conf_examples/pt_06/expected_log @@ -0,0 +1 @@ +Tor is not configured as a relay but you specified a ServerTransportPlugin line.*The ServerTransportPlugin line will be ignored diff --git a/src/test/conf_examples/pt_06/expected_log_no_dirauth_relay b/src/test/conf_examples/pt_06/expected_log_no_dirauth_relay new file mode 100644 index 0000000000..f35a380c9f --- /dev/null +++ b/src/test/conf_examples/pt_06/expected_log_no_dirauth_relay @@ -0,0 +1 @@ +Read configuration file .*pt_06[./]*torrc diff --git a/src/test/conf_examples/pt_06/expected_no_dirauth_relay b/src/test/conf_examples/pt_06/expected_no_dirauth_relay new file mode 100644 index 0000000000..d5788b92c9 --- /dev/null +++ b/src/test/conf_examples/pt_06/expected_no_dirauth_relay @@ -0,0 +1,6 @@ +ExtORPortCookieAuthFile / +ExtORPortCookieAuthFileGroupReadable 1 +ExtORPort 1 +ServerTransportListenAddr bad3 127.0.0.1:2 +ServerTransportOptions bad3 a=b +ServerTransportPlugin bad3 exec / diff --git a/src/test/conf_examples/pt_07/expected_log b/src/test/conf_examples/pt_07/expected_log new file mode 100644 index 0000000000..5afaf02ba9 --- /dev/null +++ b/src/test/conf_examples/pt_07/expected_log @@ -0,0 +1 @@ +You specified a public address .* for ExtORPort diff --git a/src/test/conf_examples/pt_08/expected_log_no_dirauth_relay b/src/test/conf_examples/pt_08/expected_log_no_dirauth_relay new file mode 100644 index 0000000000..79dcbc10ca --- /dev/null +++ b/src/test/conf_examples/pt_08/expected_log_no_dirauth_relay @@ -0,0 +1 @@ +Read configuration file .*pt_08[./]*torrc diff --git a/src/test/conf_examples/relay_01/expected_log b/src/test/conf_examples/relay_01/expected_log new file mode 100644 index 0000000000..32e8c99d27 --- /dev/null +++ b/src/test/conf_examples/relay_01/expected_log @@ -0,0 +1 @@ +Linelist option 'ORPort' has no value\. Skipping diff --git a/src/test/conf_examples/relay_03/expected_log b/src/test/conf_examples/relay_03/expected_log new file mode 100644 index 0000000000..46ab723e4a --- /dev/null +++ b/src/test/conf_examples/relay_03/expected_log @@ -0,0 +1 @@ +Read configuration file .*relay_03[./]*torrc diff --git a/src/test/conf_examples/relay_04/expected_log b/src/test/conf_examples/relay_04/expected_log new file mode 100644 index 0000000000..c05a0931d6 --- /dev/null +++ b/src/test/conf_examples/relay_04/expected_log @@ -0,0 +1 @@ +Your ContactInfo config option is not set diff --git a/src/test/conf_examples/relay_05/expected_log b/src/test/conf_examples/relay_05/expected_log new file mode 100644 index 0000000000..483c2e2aae --- /dev/null +++ b/src/test/conf_examples/relay_05/expected_log @@ -0,0 +1 @@ +Read configuration file .*relay_05[./]*torrc diff --git a/src/test/conf_examples/relay_06/expected_log b/src/test/conf_examples/relay_06/expected_log new file mode 100644 index 0000000000..70eb18df19 --- /dev/null +++ b/src/test/conf_examples/relay_06/expected_log @@ -0,0 +1 @@ +Read configuration file .*relay_06[./]*torrc diff --git a/src/test/conf_examples/relay_07/expected_log b/src/test/conf_examples/relay_07/expected_log new file mode 100644 index 0000000000..14729a7ab1 --- /dev/null +++ b/src/test/conf_examples/relay_07/expected_log @@ -0,0 +1 @@ +DirCache is disabled and we are configured as a relay diff --git a/src/test/conf_examples/relay_08/expected_log b/src/test/conf_examples/relay_08/expected_log new file mode 100644 index 0000000000..b0168c803d --- /dev/null +++ b/src/test/conf_examples/relay_08/expected_log @@ -0,0 +1 @@ +Read configuration file .*relay_08[./]*torrc diff --git a/src/test/conf_examples/relay_09/expected_log b/src/test/conf_examples/relay_09/expected_log new file mode 100644 index 0000000000..d3ab4f6593 --- /dev/null +++ b/src/test/conf_examples/relay_09/expected_log @@ -0,0 +1 @@ +By default, Tor does not run as an exit relay diff --git a/src/test/conf_examples/relay_10/expected_log b/src/test/conf_examples/relay_10/expected_log new file mode 100644 index 0000000000..5b81a904e5 --- /dev/null +++ b/src/test/conf_examples/relay_10/expected_log @@ -0,0 +1 @@ +Can't set a DirPort on a bridge relay diff --git a/src/test/conf_examples/relay_14/expected_log b/src/test/conf_examples/relay_14/expected_log new file mode 100644 index 0000000000..9b0c820211 --- /dev/null +++ b/src/test/conf_examples/relay_14/expected_log @@ -0,0 +1 @@ +Read configuration file .*relay_14[./]*torrc diff --git a/src/test/conf_examples/relay_17/expected_log b/src/test/conf_examples/relay_17/expected_log new file mode 100644 index 0000000000..7711f90178 --- /dev/null +++ b/src/test/conf_examples/relay_17/expected_log @@ -0,0 +1 @@ +You have set AccountingMax to use hibernation diff --git a/src/test/conf_examples/relay_19/expected_log b/src/test/conf_examples/relay_19/expected_log new file mode 100644 index 0000000000..17656ba2cf --- /dev/null +++ b/src/test/conf_examples/relay_19/expected_log @@ -0,0 +1 @@ +Read configuration file .*relay_19[./]*torrc diff --git a/src/test/conf_examples/relay_21/expected_log b/src/test/conf_examples/relay_21/expected_log new file mode 100644 index 0000000000..ba0d56fb1c --- /dev/null +++ b/src/test/conf_examples/relay_21/expected_log @@ -0,0 +1 @@ +PublishServerDescriptor v1 has no effect diff --git a/src/test/conf_examples/relay_29/expected_log b/src/test/conf_examples/relay_29/expected_log new file mode 100644 index 0000000000..f46c609c0c --- /dev/null +++ b/src/test/conf_examples/relay_29/expected_log @@ -0,0 +1 @@ +Linelist option 'MyFamily' has no value\. Skipping From aa3e2bbd4bb52f0e8fc550841ffdcf2da3fa2fa7 Mon Sep 17 00:00:00 2001 From: teor Date: Thu, 14 Nov 2019 12:57:59 +1000 Subject: [PATCH 14/15] test/parseconf: Warn when the expected_log* file is missing Part of 32451. --- src/test/test_parseconf.sh | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/test/test_parseconf.sh b/src/test/test_parseconf.sh index 2298f0234f..4fe27d9f5d 100755 --- a/src/test/test_parseconf.sh +++ b/src/test/test_parseconf.sh @@ -614,12 +614,18 @@ for dir in "${EXAMPLEDIR}"/*; do # This case should succeed: run verify-config and see if it does. check_verify_config "./torrc" \ - "$DEFAULTS" \ - "$CMDLINE" \ - "${DATA_DIR}/output_log.${testname}" \ - "$TRUE" \ - "$EXPECTED_LOG" \ - "log success" + "$DEFAULTS" \ + "$CMDLINE" \ + "${DATA_DIR}/output_log.${testname}" \ + "$TRUE" \ + "$EXPECTED_LOG" \ + "log success" + else + printf "\\nNOTICE: Missing '%s_log' file:\\n" \ + "$EXPECTED" >&2 + log_verify_config "./torrc" \ + "$DEFAULTS" \ + "$CMDLINE" fi elif test -f "$ERROR"; then From 9f37c0f4f2cde6b0f5be04f50edcfb23ce999830 Mon Sep 17 00:00:00 2001 From: teor Date: Thu, 14 Nov 2019 13:12:42 +1000 Subject: [PATCH 15/15] changes: file for 32451 --- changes/ticket32451 | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changes/ticket32451 diff --git a/changes/ticket32451 b/changes/ticket32451 new file mode 100644 index 0000000000..dcca851e57 --- /dev/null +++ b/changes/ticket32451 @@ -0,0 +1,5 @@ + o Minor features (testing): + - Allow test_parseconf.sh to test expected log outputs for successful + configs, as well as failed configs. Closes ticket 32451. + - Add common failure cases for test_parseconf.sh in + src/test/conf_failures. Closes ticket 32451.