Skip to content

A free, open-source alternative to Burp Suite: an intercepting proxy and web app security testing suite with Repeater, Intruder, Collaborator and a built-in OWASP ZAP scanner. Linux, AGPL-3.0.

2.7 KB
Raw Blame
#!/usr/bin/env bash
# Compile and run the test suite.
#
# Tests live under tests/ rather than src/ so they are never packed into the
# shipped jar. They compile against the compiled application classes in build/.
set -euo pipefail
DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$DIR"

# Prefer the pinned portable JDK (fetch-jdk.sh) when present, so the tests run
# against the same toolchain the release and AppImage use. Falls back to a
# system JDK if jdk/ is absent. Without this, test.sh fails with
# "javac: command not found" on a machine with no system Java even though
# fetch-jdk.sh installed one (build.sh already does this).
if [ -x "$DIR/jdk/bin/javac" ]; then
    export JAVA_HOME="$DIR/jdk"
    export PATH="$DIR/jdk/bin:$PATH"
fi

# Java's class path is joined with ";" on Windows (Git Bash there) and ":" elsewhere.
case "$(uname -s)" in MINGW*|MSYS*|CYGWIN*) S=';' ;; *) S=':' ;; esac
echo "Compiling application..."
# Start from an empty build/ like build.sh does, so classes left by a deleted
# source or by the AppImage packaging cannot leak onto the test classpath.
rm -rf build && mkdir -p build
APP_SRCS=(); while IFS= read -r f; do APP_SRCS+=("$f"); done < <(find src -name '*.java')
javac -nowarn -d build -cp "lib/*${S}build" "${APP_SRCS[@]}"

echo "Compiling tests..."
rm -rf build-tests && mkdir -p build-tests
TEST_SRCS=(); while IFS= read -r f; do TEST_SRCS+=("$f"); done < <(find tests -name '*.java')
# The engine add-on's own rules have no engine in them, so they are tested here against what Open Suite writes for them.
TEST_SRCS+=("engine-addon/opensuite/gate/GateRules.java" "engine-addon/opensuite/gate/RuleSteps.java")
javac -nowarn -d build-tests -cp "lib/*${S}build" "${TEST_SRCS[@]}"

echo "Running tests..."
echo
# Settings persist to java.util.prefs. The tests get a preferences root of
# their own, thrown away afterwards, so nothing a test sets can reach the
# preferences of the person running them. They are held in memory
# (testkit/MemoryPreferences): macOS keeps preferences in a plist of its own,
# which a preferences root folder would not move.
PREFS="$(mktemp -d)"
trap 'rm -rf "$PREFS"' EXIT
# Git Bash on Windows: Java is handed the folder's Windows name.
if command -v cygpath >/dev/null 2>&1; then PREFS="$(cygpath -m "$PREFS")"; fi
# Sizes follow the desktop font. The tests pin the smallest size, so that a
# measured width means the same on every machine.
# Temporary files the tests make go under the same folder, so a run leaves
# nothing behind in the system's temporary folder.
mkdir -p "$PREFS/tmp"
java -Djava.io.tmpdir="$PREFS/tmp" -Dopensuite.fontSize=11 -Dopensuite.test.inMemorySettings=true -Djava.util.prefs.PreferencesFactory=opensuite.testkit.MemoryPreferences -cp "lib/*${S}build${S}build-tests" RunTests