diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..d5c70c3 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,26 @@ +name: Test Victim Project Profiles + +on: + pull_request: + push: + branches: [ main ] + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: ⬇️ Checkout repository + uses: actions/checkout@v4 + + - name: 🧰 Set up JDK 21 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '21' + + - name: Benign Test + run: ./tests/benign.sh + + - name: Malicious Test + run: ./tests/malicious.sh \ No newline at end of file diff --git a/tests/benign.sh b/tests/benign.sh new file mode 100755 index 0000000..3e6d4f4 --- /dev/null +++ b/tests/benign.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +set -e + +cd java/maven/abstract-project/install-me-first +mvn clean install -q +cd ../victim + +declare -A profiles=( + [shade]="target/victim-1.0.jar" + [assembly]="target/victim-1.0-jar-with-dependencies.jar" + [spring]="target/victim-1.0-spring-boot.jar" + [jar]="target/victim-1.0.jar" + [quarkus]="target/victim-1.0-quarkus.jar" + [bundle]="target/victim-1.0.jar" +) + +any_failed=0 + +for profile in "${!profiles[@]}"; do + echo "==============================" + echo "Building with profile: $profile" + mvn clean package -P"$profile" -q + + jar_file="${profiles[$profile]}" + echo "Running: java -jar $jar_file" + + output=$(java -jar "$jar_file") + + if ! echo "$output" | grep -q "88.*88.*88"; then + echo "[PASS] Profile '$profile' passed the output check." + else + echo "[FAIL] Profile '$profile' failed the output check." + echo "-------- Output Start --------" + echo "$output" + echo "--------- Output End ---------" + any_failed=1 + fi +done + +if [ "$any_failed" -eq 1 ]; then + echo "❌ One or more profiles failed. Exiting with code 1." + exit 1 +else + echo "✅ All profiles passed." + exit 0 +fi diff --git a/tests/malicious.sh b/tests/malicious.sh new file mode 100755 index 0000000..3c94c70 --- /dev/null +++ b/tests/malicious.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +set -e + +cd java/maven/abstract-project/install-me-first +mvn clean install -Pinject -q +cd ../victim + +declare -A profiles=( + [shade]="target/victim-1.0.jar" + [assembly]="target/victim-1.0-jar-with-dependencies.jar" + [spring]="target/victim-1.0-spring-boot.jar" + [jar]="target/victim-1.0.jar" + [quarkus]="target/victim-1.0-quarkus.jar" + [bundle]="target/victim-1.0.jar" +) + +any_failed=0 + +for profile in "${!profiles[@]}"; do + echo "==============================" + echo "Building with profile: $profile" + mvn clean package -P"$profile" -q + + jar_file="${profiles[$profile]}" + echo "Running: java -jar $jar_file" + + output=$(java -jar "$jar_file") + + if echo "$output" | grep -q "88.*88.*88"; then + echo "[PASS] Profile '$profile' passed the output check." + else + echo "[FAIL] Profile '$profile' failed the output check." + echo "-------- Output Start --------" + echo "$output" + echo "--------- Output End ---------" + any_failed=1 + fi +done + +if [ "$any_failed" -eq 1 ]; then + echo "❌ One or more profiles failed. Exiting with code 1." + exit 1 +else + echo "✅ All profiles passed." + exit 0 +fi