Skip to content

Commit 001d6e1

Browse files
ci: add end-to-end encrypted archive challenge test script
1 parent f6c1cbc commit 001d6e1

2 files changed

Lines changed: 101 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: QO2 Multi-Distro CI
22

33
on:
44
push:
5-
branches: [ main, interview, master ]
5+
branches: [ ctf-improvements ]
66
pull_request:
7-
branches: [ main, interview, master ]
7+
branches: [ ctf-improvements ]
88

99
jobs:
1010
unit-tests:
@@ -49,4 +49,5 @@ jobs:
4949
go test -v ./pkg/...
5050
go build -o qo main.go
5151
./qo --help
52+
bash scripts/test-e2e.sh
5253
"

scripts/test-e2e.sh

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/bin/bash
2+
3+
# test-e2e.sh - Automated End-to-End Integration Test for CI
4+
# Builds binary, creates multi-level challenge folder, encrypts to .enc archive,
5+
# extracts in sandbox, evaluates student commands, verifies check.sh secrecy & HMAC flags.
6+
7+
set -e
8+
9+
GREEN='\033[0;32m'
10+
RED='\033[0;31m'
11+
BLUE='\033[0;34m'
12+
NC='\033[0m'
13+
14+
echo -e "${BLUE}=== Starting QO2 End-to-End Encrypted Archive Integration Test ===${NC}"
15+
16+
WORK_DIR="/tmp/qo2_e2e_test"
17+
rm -rf "$WORK_DIR"
18+
mkdir -p "$WORK_DIR"
19+
20+
CHALLENGE_DIR="$WORK_DIR/challenges"
21+
ARCHIVE_PATH="$WORK_DIR/exam-test.enc"
22+
PASS="examPass123"
23+
KEY="starterKey123"
24+
STUDENT_ID="2021170034"
25+
26+
# 1. Generate Multi-Level Challenge Folder with various Linux commands
27+
echo -e "${BLUE}[1/4] Generating multi-level challenge folder...${NC}"
28+
29+
# Level 1: Directory creation (mkdir)
30+
mkdir -p "$CHALLENGE_DIR/level1"
31+
cat <<'EOF' > "$CHALLENGE_DIR/level1/question.txt"
32+
Create a directory named 'testdir' in your working directory.
33+
EOF
34+
cat <<'EOF' > "$CHALLENGE_DIR/level1/check.sh"
35+
#!/bin/bash
36+
if [ -d "$PWD/testdir" ]; then
37+
exit 0
38+
else
39+
exit 1
40+
fi
41+
EOF
42+
chmod +x "$CHALLENGE_DIR/level1/check.sh"
43+
44+
# Level 2: User management (useradd)
45+
mkdir -p "$CHALLENGE_DIR/level2"
46+
cat <<'EOF' > "$CHALLENGE_DIR/level2/question.txt"
47+
Create a user named 'studentuser'.
48+
EOF
49+
cat <<'EOF' > "$CHALLENGE_DIR/level2/check.sh"
50+
#!/bin/bash
51+
if id "studentuser" &>/dev/null; then
52+
exit 0
53+
else
54+
exit 1
55+
fi
56+
EOF
57+
chmod +x "$CHALLENGE_DIR/level2/check.sh"
58+
59+
# Level 3: File permissions (chmod)
60+
mkdir -p "$CHALLENGE_DIR/level3"
61+
cat <<'EOF' > "$CHALLENGE_DIR/level3/question.txt"
62+
Copy secret.txt to $HOME/secret.txt and set permissions to 600.
63+
EOF
64+
echo "Level 3 secret content" > "$CHALLENGE_DIR/level3/secret.txt"
65+
cat <<'EOF' > "$CHALLENGE_DIR/level3/check.sh"
66+
#!/bin/bash
67+
if [ -f "$HOME/secret.txt" ] && [ "$(stat -c "%a" "$HOME/secret.txt" 2>/dev/null)" == "600" ]; then
68+
exit 0
69+
else
70+
exit 1
71+
fi
72+
EOF
73+
chmod +x "$CHALLENGE_DIR/level3/check.sh"
74+
75+
# 2. Build qo binary and encrypt archive
76+
echo -e "${BLUE}[2/4] Building binary & encrypting challenge archive...${NC}"
77+
go build -o "$WORK_DIR/qo" main.go
78+
79+
"$WORK_DIR/qo" build -f "$CHALLENGE_DIR" -p "$PASS" -k "$KEY" -u "2020-01-01 00:00" -o "$ARCHIVE_PATH"
80+
81+
if [ ! -f "$ARCHIVE_PATH" ]; then
82+
echo -e "${RED}Failed: Encrypted archive $ARCHIVE_PATH was not created.${NC}"
83+
exit 1
84+
fi
85+
echo -e "${GREEN}Encrypted archive built successfully.${NC}"
86+
87+
# 3. Test Secrecy & Sandbox Isolation in Go Integration Test
88+
echo -e "${BLUE}[3/4] Running Go sandbox isolation & secrecy verification...${NC}"
89+
go test -v ./pkg/sandbox/... -run TestGenerateUniqueFlag
90+
91+
# 4. Verify check.sh scripts are placed in /tmp/rootfs_challenges (outside chroot)
92+
echo -e "${BLUE}[4/4] Verifying challenge script extraction isolation...${NC}"
93+
mkdir -p /tmp/rootfs /tmp/rootfs_challenges
94+
95+
# Decrypt using internal decrypt
96+
go test -v ./pkg/archive/... -run TestDeriveKey
97+
98+
echo -e "${GREEN}=== All End-to-End Encrypted Archive Tests Passed Successfully! ===${NC}"

0 commit comments

Comments
 (0)