tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

test_rebind.sh (1541B)


      1 #!/bin/sh
      2 
      3 umask 077
      4 set -e
      5 set -x
      6 
      7 # emulate realpath(), in case coreutils or equivalent is not installed.
      8 abspath() {
      9    f="$*"
     10    if [ -d "$f" ]; then
     11        dir="$f"
     12        base=""
     13    else
     14        dir="$(dirname "$f")"
     15        base="/$(basename "$f")"
     16    fi
     17    dir="$(cd "$dir" && pwd)"
     18    echo "$dir$base"
     19 }
     20 
     21 UNAME_OS=$(uname -s | cut -d_ -f1)
     22 if test "$UNAME_OS" = 'CYGWIN' || \
     23   test "$UNAME_OS" = 'MSYS' || \
     24   test "$UNAME_OS" = 'MINGW'; then
     25  if test "$APPVEYOR" = 'True'; then
     26    echo "This test is disabled on Windows CI, as it requires firewall exemptions. Skipping." >&2
     27    exit 77
     28  fi
     29 fi
     30 
     31 # find the tor binary
     32 if [ $# -ge 1 ]; then
     33  TOR_BINARY="${1}"
     34  shift
     35 else
     36  TOR_BINARY="${TESTING_TOR_BINARY:-./src/app/tor}"
     37 fi
     38 
     39 TOR_BINARY="$(abspath "$TOR_BINARY")"
     40 
     41 echo "TOR BINARY IS ${TOR_BINARY}"
     42 
     43 if "${TOR_BINARY}" --list-modules | grep -q "relay: no"; then
     44  echo "This test requires the relay module. Skipping." >&2
     45  exit 77
     46 fi
     47 
     48 tmpdir=
     49 # For some reasons, shellcheck is not seeing that we can call this
     50 # function from the trap below.
     51 # shellcheck disable=SC2317,SC2329
     52 clean () {
     53  if [ -n "$tmpdir" ] && [ -d "$tmpdir" ]; then
     54    ls -l "$tmpdir"
     55    rm -rf "$tmpdir"
     56  fi
     57 }
     58 
     59 trap clean EXIT HUP INT TERM
     60 
     61 tmpdir="$(mktemp -d -t tor_rebind_test.XXXXXX)"
     62 if [ -z "$tmpdir" ]; then
     63  echo >&2 mktemp failed
     64  exit 2
     65 elif [ ! -d "$tmpdir" ]; then
     66  echo >&2 mktemp failed to make a directory
     67  exit 3
     68 fi
     69 
     70 "${PYTHON:-python}" "${abs_top_srcdir:-.}/src/test/test_rebind.py" "${TOR_BINARY}" "$tmpdir"
     71 
     72 exit $?