mirror of
https://github.com/m1ngsama/TNT.git
synced 2026-02-08 00:54:03 +00:00
This PR addresses critical performance bottlenecks, improves UX, and eliminates technical debt. ### Key Changes **1. Performance Optimization:** - **Startup**: Rewrote `message_load` to scan `messages.log` backwards from the end - Complexity reduced from O(FileSize) to O(MaxMessages) - Large log file startup: seconds → milliseconds - **Rendering**: Optimized TUI rendering to use line clearing (`\033[K`) instead of full-screen clearing (`\033[2J`) - Eliminated visual flicker **2. libssh API Migration:** - Replaced deprecated message-based API with callback-based server implementation - Removed `#pragma GCC diagnostic ignored "-Wdeprecated-declarations"` - Ensures future libssh compatibility **3. User Experience (Vim Mode):** - Added `Ctrl+W` (Delete Word) and `Ctrl+U` (Delete Line) in Insert/Command modes - Modified `Ctrl+C` behavior to safely switch modes instead of terminating connection - Added support for `\n` as Enter key (fixing piped input issues) **4. Project Structure:** - Moved all test scripts to `tests/` directory - Added `make test` target - Updated CI/CD to run comprehensive test suite ### Verification - ✅ All tests passing (17/17) - ✅ CI passing on Ubuntu and macOS - ✅ AddressSanitizer clean - ✅ Valgrind clean (no memory leaks) - ✅ Zero compilation warnings ### Code Quality **Rating:** 🟢 Good Taste - Algorithm-driven optimization (not hacks) - Simplified architecture (callback-based API) - Zero breaking changes (all tests pass)
90 lines
2 KiB
Bash
Executable file
90 lines
2 KiB
Bash
Executable file
#!/bin/bash
|
|
# Test anonymous SSH access
|
|
|
|
BIN="../tnt"
|
|
PORT=${PORT:-2222}
|
|
|
|
if [ ! -f "$BIN" ]; then
|
|
echo "Error: Binary $BIN not found."
|
|
exit 1
|
|
fi
|
|
|
|
echo "Starting TNT server on port $PORT..."
|
|
$BIN -p $PORT > /dev/null 2>&1 &
|
|
SERVER_PID=$!
|
|
sleep 2
|
|
|
|
cleanup() {
|
|
kill $SERVER_PID 2>/dev/null
|
|
wait 2>/dev/null
|
|
}
|
|
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_CMD 10 expect -c "
|
|
spawn ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p $PORT testuser@localhost
|
|
expect {
|
|
\"password:\" {
|
|
send \"anypassword\r\"
|
|
expect {
|
|
\"请输入用户名\" {
|
|
send \"TestUser\r\"
|
|
send \"\003\"
|
|
exit 0
|
|
}
|
|
timeout { exit 1 }
|
|
}
|
|
}
|
|
timeout { exit 1 }
|
|
}
|
|
" 2>&1 | grep -q "请输入用户名"
|
|
|
|
if [ $? -eq 0 ]; then
|
|
echo "✓ Test 1 PASSED: Can connect with any password"
|
|
else
|
|
echo "✗ Test 1 FAILED: Cannot connect with any password"
|
|
exit 1
|
|
fi
|
|
|
|
echo ""
|
|
|
|
# Test 2: Connection should work with empty password
|
|
echo "Test 2: Simple connection (standard SSH command)"
|
|
$TIMEOUT_CMD 10 expect -c "
|
|
spawn ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p $PORT anonymous@localhost
|
|
expect {
|
|
\"password:\" {
|
|
send \"\r\"
|
|
expect {
|
|
\"请输入用户名\" {
|
|
send \"\r\"
|
|
send \"\003\"
|
|
exit 0
|
|
}
|
|
timeout { exit 1 }
|
|
}
|
|
}
|
|
timeout { exit 1 }
|
|
}
|
|
" 2>&1 | grep -q "请输入用户名"
|
|
|
|
if [ $? -eq 0 ]; then
|
|
echo "✓ Test 2 PASSED: Can connect with empty password"
|
|
else
|
|
echo "✗ Test 2 FAILED: Cannot connect with empty password"
|
|
exit 1
|
|
fi
|
|
|
|
echo ""
|
|
echo "Anonymous access test completed."
|
|
exit 0
|