generated from stratosphereips/awesome-code-template
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathrun_tests.sh
executable file
·100 lines (85 loc) · 2.52 KB
/
run_tests.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash
# Check if sshpass is installed
if ! command -v sshpass &> /dev/null; then
echo "Error: sshpass is not installed. Please install it and try again." >&2
exit 1
fi
# Check if docker is installed
if ! command -v docker &> /dev/null; then
echo "Error: docker is not installed. Please install it and try again." >&2
exit 1
fi
# Fire up all the containers
echo ""
echo "Starting the project"
docker compose up -d --build --force-recreate
echo "Project started"
# Wait for the dashboard to initialize
sleep 2
LABUSER='root'
LABPASS='ByteThem123'
LABHOST='127.0.0.1'
LABPORT=2222
CHALLENGES_DIR="challenges"
echo ""
echo "Starting all challenges"
response=$(curl -s -X POST http://127.0.0.1/api/challenges/start/all)
if [ "$response" != "All started! 🎉" ]; then
echo "Error starting all the challenges, got response: $response"
exit 3
fi
echo "All challenges started"
failed=false
for chal_dir in "$CHALLENGES_DIR"/*/; do
if [[ "$chal_dir" == "challenges/template/" ]]; then
# skip template
continue
fi
echo ""
echo "Testing $chal_dir:"
solve_script="$chal_dir/auto-solve.sh"
if [ -f "$solve_script" ]; then
# Copy auto-solve script into /tmp dir in hackerlab container
# We use ssh instead of docker exec to test also the SSH connection
sshpass -p "$LABPASS" scp -O \
-o LogLevel=error \
-o UserKnownHostsFile=/dev/null \
-o StrictHostKeyChecking=no \
-P $LABPORT \
$solve_script \
$LABUSER@$LABHOST:/tmp/auto-solve.sh
# Run the auto-solve script from within the hackerlab container
sshpass -p "$LABPASS" ssh \
-o LogLevel=error \
-o UserKnownHostsFile=/dev/null \
-o StrictHostKeyChecking=no \
-p $LABPORT \
$LABUSER@$LABHOST \
/tmp/auto-solve.sh
retVal=$?
if [ $retVal -ne 0 ]; then
failed=true
fi
else
echo "WARNING - missing $solve_script script"
fi
done
echo ""
echo "Stopping all challenges"
response=$(curl -s -X POST http://127.0.0.1/api/challenges/stop/all)
if [ "$response" != "All stopped! 🎉" ]; then
echo "Error stopping all the challenges, got response: $response"
exit 3
fi
echo "All challenges stopped"
echo ""
echo "Stopping the project"
docker compose down
echo "Project stopped"
echo ""
if [ "$failed" = true ]; then
echo "❌ TEST FAILED - some auto-solve.sh script fialed"
exit 2
else
echo "✅ ALL TESTS PASSED"
fi