From c120cb5ac5e3528192dde75ef0ccf264f175e4ca Mon Sep 17 00:00:00 2001 From: m1ngsama Date: Sat, 7 Feb 2026 14:43:46 +0800 Subject: [PATCH] fix(ci): support macOS by using gtimeout from coreutils --- .github/workflows/ci.yml | 2 +- tests/test_anonymous_access.sh | 10 ++++++++-- tests/test_basic.sh | 10 ++++++++-- tests/test_security_features.sh | 14 ++++++++++---- tests/test_stress.sh | 8 +++++++- 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 53295e8..a562ede 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,7 +25,7 @@ jobs: - name: Install dependencies (macOS) if: runner.os == 'macOS' run: | - brew install libssh + brew install libssh coreutils - name: Build run: make diff --git a/tests/test_anonymous_access.sh b/tests/test_anonymous_access.sh index 12ef3e3..8930049 100755 --- a/tests/test_anonymous_access.sh +++ b/tests/test_anonymous_access.sh @@ -20,12 +20,18 @@ cleanup() { } trap cleanup EXIT +# Detect timeout command +TIMEOUT_CMD="timeout" +if command -v gtimeout >/dev/null 2>&1; then + TIMEOUT_CMD="gtimeout" +fi + echo "Testing anonymous SSH access to TNT server..." echo "" # Test 1: Connection with any username and password echo "Test 1: Connection with any username (should succeed)" -timeout 10 expect -c " +$TIMEOUT_CMD 10 expect -c " spawn ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p $PORT testuser@localhost expect { \"password:\" { @@ -54,7 +60,7 @@ echo "" # Test 2: Connection should work with empty password echo "Test 2: Simple connection (standard SSH command)" -timeout 10 expect -c " +$TIMEOUT_CMD 10 expect -c " spawn ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p $PORT anonymous@localhost expect { \"password:\" { diff --git a/tests/test_basic.sh b/tests/test_basic.sh index 8c4488c..5f92899 100755 --- a/tests/test_basic.sh +++ b/tests/test_basic.sh @@ -13,6 +13,12 @@ cleanup() { trap cleanup EXIT +# Detect timeout command +TIMEOUT_CMD="timeout" +if command -v gtimeout >/dev/null 2>&1; then + TIMEOUT_CMD="gtimeout" +fi + echo "=== TNT Basic Tests ===" # Path to binary @@ -39,7 +45,7 @@ else fi # Test 2: SSH connection -if timeout 5 ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \ +if $TIMEOUT_CMD 5 ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \ -o BatchMode=yes -p $PORT localhost exit 2>/dev/null; then echo "✓ SSH connection works" PASS=$((PASS + 1)) @@ -49,7 +55,7 @@ else fi # Test 3: Message logging -(echo "testuser"; echo "test message"; sleep 1) | timeout 5 ssh -o StrictHostKeyChecking=no \ +(echo "testuser"; echo "test message"; sleep 1) | $TIMEOUT_CMD 5 ssh -o StrictHostKeyChecking=no \ -o UserKnownHostsFile=/dev/null -p $PORT localhost >/dev/null 2>&1 & sleep 3 if [ -f messages.log ]; then diff --git a/tests/test_security_features.sh b/tests/test_security_features.sh index c207192..b141fbe 100755 --- a/tests/test_security_features.sh +++ b/tests/test_security_features.sh @@ -43,6 +43,12 @@ if [ ! -f "$BIN" ]; then exit 1 fi +# Detect timeout command +TIMEOUT_CMD="timeout" +if command -v gtimeout >/dev/null 2>&1; then + TIMEOUT_CMD="gtimeout" +fi + # Test 1: 4096-bit RSA Key Generation print_test "1. RSA 4096-bit Key Generation" rm -f host_key @@ -75,19 +81,19 @@ fi print_test "2. Environment Variable Configuration" # Test bind address -TNT_BIND_ADDR=127.0.0.1 timeout 3 $BIN 2>&1 | grep -q "TNT chat server" && \ +TNT_BIND_ADDR=127.0.0.1 $TIMEOUT_CMD 3 $BIN 2>&1 | grep -q "TNT chat server" && \ pass "TNT_BIND_ADDR configuration works" || fail "TNT_BIND_ADDR not working" # Test with access token set (just verify it starts) -TNT_ACCESS_TOKEN="test123" timeout 3 $BIN 2>&1 | grep -q "TNT chat server" && \ +TNT_ACCESS_TOKEN="test123" $TIMEOUT_CMD 3 $BIN 2>&1 | grep -q "TNT chat server" && \ pass "TNT_ACCESS_TOKEN configuration accepted" || fail "TNT_ACCESS_TOKEN not working" # Test max connections configuration -TNT_MAX_CONNECTIONS=10 timeout 3 $BIN 2>&1 | grep -q "TNT chat server" && \ +TNT_MAX_CONNECTIONS=10 $TIMEOUT_CMD 3 $BIN 2>&1 | grep -q "TNT chat server" && \ pass "TNT_MAX_CONNECTIONS configuration accepted" || fail "TNT_MAX_CONNECTIONS not working" # Test rate limit toggle -TNT_RATE_LIMIT=0 timeout 3 $BIN 2>&1 | grep -q "TNT chat server" && \ +TNT_RATE_LIMIT=0 $TIMEOUT_CMD 3 $BIN 2>&1 | grep -q "TNT chat server" && \ pass "TNT_RATE_LIMIT configuration accepted" || fail "TNT_RATE_LIMIT not working" sleep 1 diff --git a/tests/test_stress.sh b/tests/test_stress.sh index b89998d..949896f 100755 --- a/tests/test_stress.sh +++ b/tests/test_stress.sh @@ -12,6 +12,12 @@ if [ ! -f "$BIN" ]; then exit 1 fi +# Detect timeout command +TIMEOUT_CMD="timeout" +if command -v gtimeout >/dev/null 2>&1; then + TIMEOUT_CMD="gtimeout" +fi + echo "Starting TNT server on port $PORT..." $BIN -p $PORT & SERVER_PID=$! @@ -27,7 +33,7 @@ echo "Spawning $CLIENTS clients for ${DURATION}s..." for i in $(seq 1 $CLIENTS); do ( sleep $((i % 5)) - echo "test user $i" | timeout $DURATION ssh -o StrictHostKeyChecking=no \ + echo "test user $i" | $TIMEOUT_CMD $DURATION ssh -o StrictHostKeyChecking=no \ -o UserKnownHostsFile=/dev/null -p $PORT localhost \ >/dev/null 2>&1 ) &