Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Backend/test/check_hotspot_status_test.bats
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bats
#!/data/data/com.termux/files/usr/bin/bats

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Hardcoding the absolute path to the Termux bats binary in the shebang breaks portability for non-Termux environments. Since the run.sh runner already identifies the correct BATS_BIN and invokes it explicitly, the shebang is not strictly necessary for the runner to work. It is better to use #!/usr/bin/env bats to maintain compatibility across different systems.

#!/usr/bin/env bats


# Automated testing for check_hotspot_status function, where test cases consider state tracking, transition detection
# and timestamp guard logic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ setup() {
mkdir -p "$MOCKBIN" "$TMPDIR_TEST"

cat > "$MOCKBIN/iptables" <<'EOT'
#!/usr/bin/env bash
#!/data/data/com.termux/files/usr/bin/bash
echo "$*" >> "${MOCKBIN}/iptables.log"
exit 0
EOT
Expand Down
2 changes: 1 addition & 1 deletion Backend/test/clear_internet_sessions_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ setup_env() {

# 2. Setup Mock iptables
cat > "$MOCK_DIR/iptables" <<'EOT'
#!/usr/bin/env bash
#!/data/data/com.termux/files/usr/bin/bash
echo "iptables $*" >> "${MOCK_DIR}/iptables_calls.log"
exit 0
EOT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ setup() {
mkdir -p "$MOCKBIN"

cat > "$MOCKBIN/iptables" <<'EOT'
#!/usr/bin/env bash
#!/data/data/com.termux/files/usr/bin/bash
echo "$*" >> "$MOCKBIN/iptables.log"
if [[ "$*" == *"10.0.0.999"* ]]; then
echo "iptables: Rule does not exist." >&2
Expand Down
4 changes: 2 additions & 2 deletions Backend/test/delete_user_iptables_rules_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ setup_mocks() {

# Create a mock iptables that logs all calls
cat > "$MOCK_DIR/iptables" <<'EOT'
#!/usr/bin/env bash
#!/data/data/com.termux/files/usr/bin/bash
# Log the call for verification
echo "$*" >> "${MOCK_DIR}/iptables_calls.log"
# Simulate behavior based on arguments
Expand Down Expand Up @@ -190,4 +190,4 @@ main() {

[[ $failed -eq 0 ]] && exit 0 || exit 1
}
main "$@"
main "$@"
14 changes: 14 additions & 0 deletions Backend/test/error.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Tue Apr 21 22:49:55 EDT 2026 Error in Cybercafe_internetSessionFunctions.sh: Line 24

iptables v1.6.1: Couldn't find target `iptmon_tx'

Try `iptables -h' or 'iptables --help' for more information.
iptables v1.6.1: Couldn't find target `iptmon_rx'

Try `iptables -h' or 'iptables --help' for more information.
iptables: No chain/target/match by that name.
iptables: No chain/target/match by that name.
iptables: No chain/target/match by that name.
iptables: Bad rule (does a matching rule exist in that chain?).
iptables: Bad rule (does a matching rule exist in that chain?).
RTNETLINK answers: No such file or directory
Comment on lines +1 to +14

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This file appears to be a log generated during a test run and should not be committed to the repository. Please remove it.

File renamed without changes.
26 changes: 20 additions & 6 deletions Backend/test/lifecycle_e2e_test.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
#!/usr/bin/env bash
set -e

SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR="$(cd -- "$SCRIPT_DIR/.." && pwd)"
CYBERCAFE_SH="$ROOT_DIR/cybercafe.sh"

echo "======================================="
echo "CyberCafe Lifecycle E2E Test"
echo "======================================="

LOG_DIR="/tmp/cybercafe_logs"
if [[ -n "${TMPDIR:-}" && -d "${TMPDIR}" && -w "${TMPDIR}" ]]; then
TMP_BASE="$TMPDIR"
elif [[ -d /data/local/tmp && -w /data/local/tmp ]]; then
TMP_BASE="/data/local/tmp"
elif [[ -d /tmp && -w /tmp ]]; then
TMP_BASE="/tmp"
else
TMP_BASE="./.tmp"
fi

LOG_DIR="$TMP_BASE/cybercafe_logs"
mkdir -p "$LOG_DIR"

# ---------------------------------------
# STEP 1 — Start Infrastructure
# ---------------------------------------
echo "[STEP 1] Starting infrastructure..."

bash Backend/cybercafe.sh run > "$LOG_DIR/run.log" 2>&1 &
/data/data/com.termux/files/usr/bin/bash "$CYBERCAFE_SH" run > "$LOG_DIR/run.log" 2>&1 &

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Hardcoding the absolute path to the Termux bash binary reduces the portability of the test script. Since the run.sh runner already configures the PATH to include Termux-specific directories (lines 12-21 in run.sh), you can simply use bash here. This ensures the script remains compatible with standard Linux and macOS environments while still working correctly on Termux when invoked via the runner. This applies to lines 50, 64, and 80 as well.

Suggested change
/data/data/com.termux/files/usr/bin/bash "$CYBERCAFE_SH" run > "$LOG_DIR/run.log" 2>&1 &
bash "$CYBERCAFE_SH" run > "$LOG_DIR/run.log" 2>&1 &

CYBER_PID=$!

sleep 3
Expand All @@ -33,7 +47,7 @@ fi
# ---------------------------------------
echo "[STEP 2] Checking system status..."

STATUS_OUTPUT=$(bash Backend/cybercafe.sh status 2>&1 || true)
STATUS_OUTPUT=$(/data/data/com.termux/files/usr/bin/bash "$CYBERCAFE_SH" status 2>&1 || true)
echo "$STATUS_OUTPUT"

if echo "$STATUS_OUTPUT" | grep -q "Status"; then
Expand All @@ -47,7 +61,7 @@ fi
# ---------------------------------------
echo "[STEP 3] Validating system interaction..."

LIST_OUTPUT=$(bash Backend/cybercafe.sh list users 2>&1 || true)
LIST_OUTPUT=$(/data/data/com.termux/files/usr/bin/bash "$CYBERCAFE_SH" list users 2>&1 || true)
echo "$LIST_OUTPUT"

if echo "$LIST_OUTPUT" | grep -qi "no such table"; then
Expand All @@ -63,7 +77,7 @@ fi
# ---------------------------------------
echo "[STEP 4] Shutting down infrastructure..."

bash Backend/cybercafe.sh shutdown > "$LOG_DIR/shutdown.log" 2>&1 || true
/data/data/com.termux/files/usr/bin/bash "$CYBERCAFE_SH" shutdown > "$LOG_DIR/shutdown.log" 2>&1 || true

kill $CYBER_PID 2>/dev/null || true

Expand All @@ -74,4 +88,4 @@ echo "[OK] Shutdown completed"
# ---------------------------------------
echo "======================================="
echo "Lifecycle test completed"
echo "======================================="
echo "======================================="
Loading
Loading