tor

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

test_include.sh (2768B)


      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' || \
     25   test "$UNAME_OS" = 'MINGW32' || \
     26   test "$UNAME_OS" = 'MINGW64'; then
     27  if test "$APPVEYOR" = 'True'; then
     28    echo "This test is disabled on Windows CI, as it requires firewall exemptions. Skipping." >&2
     29    exit 77
     30  fi
     31 fi
     32 
     33 # find the tor binary
     34 if [ $# -ge 1 ]; then
     35  TOR_BINARY="${1}"
     36  shift
     37 else
     38  TOR_BINARY="${TESTING_TOR_BINARY:-./src/app/tor}"
     39 fi
     40 
     41 TOR_BINARY="$(abspath "$TOR_BINARY")"
     42 
     43 echo "TOR BINARY IS ${TOR_BINARY}"
     44 
     45 if "${TOR_BINARY}" --list-modules | grep -q "relay: no"; then
     46  echo "This test requires the relay module. Skipping." >&2
     47  exit 77
     48 fi
     49 
     50 tmpdir=
     51 # For some reasons, shellcheck is not seeing that we can call this
     52 # function from the trap below.
     53 # shellcheck disable=SC2317,SC2329
     54 clean () {
     55  if [ -n "$tmpdir" ] && [ -d "$tmpdir" ]; then
     56    rm -rf "$tmpdir"
     57  fi
     58 }
     59 
     60 trap clean EXIT HUP INT TERM
     61 
     62 tmpdir="$(mktemp -d -t tor_include_test.XXXXXX)"
     63 if [ -z "$tmpdir" ]; then
     64  echo >&2 mktemp failed
     65  exit 2
     66 elif [ ! -d "$tmpdir" ]; then
     67  echo >&2 mktemp failed to make a directory
     68  exit 3
     69 fi
     70 
     71 datadir="$tmpdir/data"
     72 mkdir "$datadir"
     73 
     74 configdir="$tmpdir/config"
     75 mkdir "$configdir"
     76 
     77 # translate paths to windows format
     78 if test "$UNAME_OS" = 'CYGWIN' || \
     79   test "$UNAME_OS" = 'MSYS' || \
     80   test "$UNAME_OS" = 'MINGW' || \
     81   test "$UNAME_OS" = 'MINGW32' || \
     82   test "$UNAME_OS" = 'MINGW64'; then
     83    datadir=$(cygpath --windows "$datadir")
     84    configdir=$(cygpath --windows "$configdir")
     85 fi
     86 
     87 # create test folder structure in configdir
     88 torrcd="$configdir/torrc.d"
     89 mkdir "$torrcd"
     90 mkdir "$torrcd/folder"
     91 mkdir "$torrcd/empty_folder"
     92 echo "NodeFamily 1" > "$torrcd/01_one.conf"
     93 echo "NodeFamily 2" > "$torrcd/02_two.conf"
     94 echo "NodeFamily 3" > "$torrcd/aa_three.conf"
     95 echo "NodeFamily 42" > "$torrcd/.hidden.conf"
     96 echo "NodeFamily 6" > "$torrcd/foo"
     97 touch "$torrcd/empty.conf"
     98 echo "# comment" > "$torrcd/comment.conf"
     99 echo "NodeFamily 4" > "$torrcd/folder/04_four.conf"
    100 echo "NodeFamily 5" > "$torrcd/folder/05_five.conf"
    101 torrc="$configdir/torrc"
    102 echo "Sandbox 1" > "$torrc"
    103 echo "
    104 %include $torrcd/*.conf
    105 %include $torrcd/f*
    106 %include $torrcd/*/*
    107 %include $torrcd/empty_folder
    108 %include $torrcd/empty.conf
    109 %include $torrcd/comment.conf
    110 " >> "$torrc"
    111 
    112 "${PYTHON:-python}" "${abs_top_srcdir:-.}/src/test/test_include.py" "${TOR_BINARY}" "$datadir" "$configdir"
    113 
    114 exit $?