-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·155 lines (130 loc) · 4.83 KB
/
test.sh
File metadata and controls
executable file
·155 lines (130 loc) · 4.83 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/bin/bash
# Simple test script for TailProxy
set -e
echo "=== TailProxy Test Script ==="
echo
# Check if built
if [ ! -f "./tailproxy" ] || [ ! -f "./libtailproxy.so" ]; then
echo "Error: tailproxy or libtailproxy.so not found. Run 'make build' first."
exit 1
fi
# Source .env for authkey if it exists
if [ -f ".env" ]; then
source .env
echo "Loaded .env (AUTHKEY set: ${AUTHKEY:+yes})"
fi
# Build authkey flag if available
AUTHKEY_FLAG=""
if [ -n "$AUTHKEY" ]; then
AUTHKEY_FLAG="-authkey=$AUTHKEY"
fi
echo "1. Testing verbose output..."
echo " Running: ./tailproxy -verbose echo 'Hello from TailProxy'"
./tailproxy -verbose echo "Hello from TailProxy" 2>&1 | head -5
echo
echo "2. Testing with network command (requires Tailscale auth)..."
echo " This will require you to authenticate with Tailscale on first run."
echo " Press Ctrl+C to skip this test, or Enter to continue..."
read -t 5 || echo "Continuing..."
echo
echo " Running: ./tailproxy -verbose $AUTHKEY_FLAG curl -s https://ifconfig.me"
echo " Note: This will show your Tailscale exit IP if configured"
./tailproxy -verbose $AUTHKEY_FLAG curl -s https://ifconfig.me 2>&1 || echo "Test completed (may have failed if not authenticated)"
echo
echo "3. Testing export listeners..."
echo " This test starts a server with -export-listeners and connects via tailnet."
echo " Logs will be written to /tmp/tailproxy-test-*.log"
echo
# Clean up any previous test logs
rm -f /tmp/tailproxy-test-server.log /tmp/tailproxy-test-client.log
# Generate unique hostname for this test run
TEST_HOSTNAME="exporttest-$$"
SERVER_PORT=18090
SERVER_PROXY_PORT=19080
CLIENT_PROXY_PORT=19081
echo " Starting server: ./tailproxy -export-listeners -hostname=$TEST_HOSTNAME -port=$SERVER_PROXY_PORT -verbose $AUTHKEY_FLAG python -m http.server $SERVER_PORT"
./tailproxy -export-listeners -hostname="$TEST_HOSTNAME" -port="$SERVER_PROXY_PORT" -verbose $AUTHKEY_FLAG python -m http.server "$SERVER_PORT" \
> /tmp/tailproxy-test-server.log 2>&1 &
SERVER_PID=$!
echo " Server PID: $SERVER_PID"
echo " Waiting for server to initialize (checking for tailnet ready)..."
# Wait for server to be ready - look for tsnet to be up
MAX_WAIT=60
WAITED=0
SERVER_READY=0
while [ $WAITED -lt $MAX_WAIT ]; do
if grep -q "Exporting port $SERVER_PORT on tailnet" /tmp/tailproxy-test-server.log 2>/dev/null; then
SERVER_READY=1
break
fi
if ! kill -0 $SERVER_PID 2>/dev/null; then
echo " ERROR: Server process died unexpectedly"
echo " Server log:"
cat /tmp/tailproxy-test-server.log
exit 1
fi
sleep 1
WAITED=$((WAITED + 1))
if [ $((WAITED % 10)) -eq 0 ]; then
echo " Still waiting... ($WAITED seconds)"
fi
done
if [ $SERVER_READY -eq 0 ]; then
echo " ERROR: Server did not become ready within $MAX_WAIT seconds"
echo " Server log tail:"
tail -50 /tmp/tailproxy-test-server.log
kill $SERVER_PID 2>/dev/null || true
exit 1
fi
echo " Server ready after $WAITED seconds"
# Extract server's Tailscale IP from logs (tsnet doesn't configure system DNS, so we need the IP)
SERVER_IP=$(strings /tmp/tailproxy-test-server.log | grep -oP 'netstack: registered IP \K[0-9.]+' | head -1)
if [ -z "$SERVER_IP" ]; then
echo " ERROR: Could not extract server Tailscale IP from logs"
kill $SERVER_PID 2>/dev/null || true
exit 1
fi
echo " Server Tailscale IP: $SERVER_IP"
echo
# Give it a moment to fully stabilize
sleep 2
echo " Running client: ./tailproxy -hostname=testclient-$$ -port=$CLIENT_PROXY_PORT -verbose $AUTHKEY_FLAG curl -s http://$SERVER_IP:$SERVER_PORT/"
./tailproxy -hostname="testclient-$$" -port="$CLIENT_PROXY_PORT" -verbose $AUTHKEY_FLAG curl -s --max-time 30 "http://$SERVER_IP:$SERVER_PORT/" \
> /tmp/tailproxy-test-client.log 2>&1
CLIENT_EXIT=$?
echo " Client exit code: $CLIENT_EXIT"
echo
# Check results
if [ $CLIENT_EXIT -eq 0 ] && grep -q "Directory listing" /tmp/tailproxy-test-client.log 2>/dev/null; then
echo " SUCCESS: Export listeners test passed!"
EXPORT_TEST_PASSED=1
else
echo " FAILED: Export listeners test failed"
EXPORT_TEST_PASSED=0
fi
# Clean up server
echo " Stopping server..."
kill $SERVER_PID 2>/dev/null || true
wait $SERVER_PID 2>/dev/null || true
echo
echo " Log files saved to:"
echo " Server: /tmp/tailproxy-test-server.log"
echo " Client: /tmp/tailproxy-test-client.log"
if [ $EXPORT_TEST_PASSED -eq 0 ]; then
echo
echo " === Server log (last 30 lines) ==="
tail -30 /tmp/tailproxy-test-server.log
echo
echo " === Client log ==="
cat /tmp/tailproxy-test-client.log
fi
echo
echo "=== Test completed ==="
echo
echo "To use TailProxy:"
echo " ./tailproxy [options] <command>"
echo
echo "To use with exit node:"
echo " ./tailproxy -exit-node=your-exit-node curl https://ifconfig.me"
echo
echo "For more info, see README.md"