-
Notifications
You must be signed in to change notification settings - Fork 1
496 lines (447 loc) · 17.1 KB
/
e2e.yaml
File metadata and controls
496 lines (447 loc) · 17.1 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
name: E2E Protocol Tests
on:
workflow_dispatch:
pull_request:
branches: [main]
paths-ignore:
- '.github/workflows/**'
- '*.md'
- 'LICENSE'
env:
DROPLET_NAME: "e2e-lantern-box-${{ github.run_id }}"
SSH_KEY_NAME: "e2e-lantern-box-${{ github.run_id }}"
jobs:
e2e:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: "go.mod"
- name: Grant private modules access
run: |
git config --global url."https://${{ secrets.CI_PRIVATE_REPOS_GH_TOKEN }}:x-oauth-basic@github.com/".insteadOf "https://github.com/"
- name: Build lantern-box (linux/amd64)
run: |
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build \
-tags "with_gvisor,with_quic,with_dhcp,with_wireguard,with_utls,with_acme,with_clash_api" \
-ldflags="-s -w" \
-o lantern-box \
./cmd
ls -lh lantern-box
- name: Generate test credentials
id: creds
run: |
# Samizdat X25519 keypair
openssl genpkey -algorithm X25519 -out samizdat_priv.pem
SAMIZDAT_PRIV=$(openssl pkey -in samizdat_priv.pem -outform DER \
| tail -c 32 | xxd -p | tr -d '\n')
SAMIZDAT_PUB=$(openssl pkey -in samizdat_priv.pem -pubout -outform DER \
| tail -c 32 | xxd -p | tr -d '\n')
SAMIZDAT_SHORT_ID=$(openssl rand -hex 8)
# Self-signed TLS cert for Samizdat
openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 \
-keyout key.pem -out cert.pem -days 1 -nodes \
-subj "/CN=example.com"
# Locate plain.wasm from Go module cache
WATER_MOD_DIR="$(go env GOPATH)/pkg/mod/github.com/refraction-networking/water@v0.7.1-alpha"
WASM_PATH="${WATER_MOD_DIR}/transport/v1/testdata/plain.wasm"
if [ ! -f "$WASM_PATH" ]; then
echo "plain.wasm not found at $WASM_PATH, downloading module..."
go mod download github.com/refraction-networking/water@v0.7.1-alpha
WATER_MOD_DIR="$(go env GOPATH)/pkg/mod/github.com/refraction-networking/water@v0.7.1-alpha"
WASM_PATH="${WATER_MOD_DIR}/transport/v1/testdata/plain.wasm"
fi
WASM_HASH=$(sha256sum "$WASM_PATH" | awk '{print $1}')
cp "$WASM_PATH" plain.wasm
echo "::add-mask::$SAMIZDAT_PRIV"
echo "samizdat_priv=$SAMIZDAT_PRIV" >> "$GITHUB_OUTPUT"
echo "samizdat_pub=$SAMIZDAT_PUB" >> "$GITHUB_OUTPUT"
echo "samizdat_short_id=$SAMIZDAT_SHORT_ID" >> "$GITHUB_OUTPUT"
echo "wasm_hash=$WASM_HASH" >> "$GITHUB_OUTPUT"
- name: Install doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DO_API_TOKEN }}
- name: Create DO droplet
id: droplet
run: |
# Generate ephemeral SSH key
ssh-keygen -t ed25519 -f e2e_key -N "" -q
SSH_PUB=$(cat e2e_key.pub)
# Upload SSH key to DO
SSH_KEY_ID=$(doctl compute ssh-key create "$SSH_KEY_NAME" \
--public-key "$SSH_PUB" --format ID --no-header)
echo "ssh_key_id=$SSH_KEY_ID" >> "$GITHUB_OUTPUT"
# Create droplet
DROPLET_ID=$(doctl compute droplet create "$DROPLET_NAME" \
--image ubuntu-24-04-x64 \
--size s-2vcpu-2gb \
--region nyc3 \
--ssh-keys "$SSH_KEY_ID" \
--wait \
--format ID --no-header)
echo "droplet_id=$DROPLET_ID" >> "$GITHUB_OUTPUT"
# Get droplet IP
DROPLET_IP=$(doctl compute droplet get "$DROPLET_ID" \
--format PublicIPv4 --no-header)
echo "droplet_ip=$DROPLET_IP" >> "$GITHUB_OUTPUT"
echo "Droplet $DROPLET_ID created at $DROPLET_IP"
# Wait for SSH readiness
SSH_READY=0
for i in $(seq 1 30); do
if ssh -o StrictHostKeyChecking=no -o ConnectTimeout=5 \
-i e2e_key root@"$DROPLET_IP" echo ready 2>/dev/null; then
echo "SSH is ready"
SSH_READY=1
break
fi
echo "Waiting for SSH... attempt $i/30"
sleep 10
done
if [ "$SSH_READY" -ne 1 ]; then
echo "ERROR: SSH never became ready after 30 attempts"
exit 1
fi
- name: Deploy to droplet
env:
DROPLET_IP: ${{ steps.droplet.outputs.droplet_ip }}
SAMIZDAT_PRIV: ${{ steps.creds.outputs.samizdat_priv }}
SAMIZDAT_SHORT_ID: ${{ steps.creds.outputs.samizdat_short_id }}
WASM_HASH: ${{ steps.creds.outputs.wasm_hash }}
run: |
SSH_OPTS="-o StrictHostKeyChecking=no -o ServerAliveInterval=30 -i e2e_key"
# Compress binary before upload
gzip -1 -c lantern-box > lantern-box.gz
ls -lh lantern-box.gz
# Upload files
echo "Starting SCP upload..."
scp $SSH_OPTS lantern-box.gz cert.pem key.pem plain.wasm root@"$DROPLET_IP":/root/
echo "SCP upload complete"
# Decompress and make binary executable
echo "Decompressing binary..."
ssh $SSH_OPTS root@"$DROPLET_IP" \
"gzip -d /root/lantern-box.gz && chmod +x /root/lantern-box"
echo "Binary ready"
# Start Python HTTP server to serve plain.wasm (for WATER)
echo "Starting WASM HTTP server..."
ssh -f $SSH_OPTS root@"$DROPLET_IP" \
"cd /root && python3 -m http.server 8888 > /root/wasm-server.log 2>&1"
echo "WASM HTTP server started"
# --- ALGeneva server config ---
cat > /tmp/algeneva-server.json << 'JSONEOF'
{
"log": {"level": "trace"},
"inbounds": [{
"type": "algeneva",
"tag": "algeneva-in",
"listen": "::",
"listen_port": 9001
}],
"outbounds": [{
"type": "direct",
"tag": "direct"
}]
}
JSONEOF
scp $SSH_OPTS /tmp/algeneva-server.json root@"$DROPLET_IP":/root/algeneva-server.json
# --- Samizdat server config ---
cat > /tmp/samizdat-server.json << JSONEOF
{
"log": {"level": "debug"},
"inbounds": [{
"type": "samizdat",
"tag": "samizdat-in",
"listen": "::",
"listen_port": 9002,
"private_key": "${SAMIZDAT_PRIV}",
"short_ids": ["${SAMIZDAT_SHORT_ID}"],
"cert_path": "/root/cert.pem",
"key_path": "/root/key.pem",
"masquerade_domain": "example.com"
}],
"outbounds": [{
"type": "direct",
"tag": "direct"
}]
}
JSONEOF
scp $SSH_OPTS /tmp/samizdat-server.json root@"$DROPLET_IP":/root/samizdat-server.json
# --- WATER server config ---
cat > /tmp/water-server.json << JSONEOF
{
"log": {"level": "debug"},
"inbounds": [{
"type": "water",
"tag": "water-in",
"listen": "::",
"listen_port": 9003,
"transport": "plain",
"hashsum": "${WASM_HASH}",
"wasm_available_at": ["http://127.0.0.1:8888/plain.wasm"],
"config": {}
}],
"outbounds": [{
"type": "direct",
"tag": "direct"
}]
}
JSONEOF
scp $SSH_OPTS /tmp/water-server.json root@"$DROPLET_IP":/root/water-server.json
# Start all 3 server processes
echo "Starting servers..."
ssh $SSH_OPTS root@"$DROPLET_IP" "nohup /root/lantern-box run --config /root/algeneva-server.json > /root/algeneva-server.log 2>&1 < /dev/null &
nohup /root/lantern-box run --config /root/samizdat-server.json > /root/samizdat-server.log 2>&1 < /dev/null &
nohup /root/lantern-box run --config /root/water-server.json > /root/water-server.log 2>&1 < /dev/null &
sleep 1"
echo "Servers launched"
# Wait for servers to be ready (WATER needs time to download/compile WASM)
echo "Checking port readiness..."
# Note: must use bash explicitly since Ubuntu default shell is dash (no /dev/tcp support)
ssh $SSH_OPTS root@"$DROPLET_IP" bash << 'READYEOF'
for port in 9001 9002 9003; do
echo "Waiting for port $port to be ready..."
for i in $(seq 1 60); do
if echo > /dev/tcp/127.0.0.1/$port 2>/dev/null; then
echo "Port $port is ready"
break
fi
if [ "$i" -eq 60 ]; then
echo "Port $port not ready after 60 seconds" >&2
cat /root/*.log
exit 1
fi
sleep 1
done
done
READYEOF
- name: Test ALGeneva
id: test_algeneva
continue-on-error: true
env:
DROPLET_IP: ${{ steps.droplet.outputs.droplet_ip }}
run: |
# Generate client config
# Use a simple strategy that only modifies the host header (not the CONNECT request line)
cat > /tmp/algeneva-client.json << JSONEOF
{
"log": {"level": "trace"},
"inbounds": [{
"type": "mixed",
"tag": "mixed-in",
"listen": "127.0.0.1",
"listen_port": 1081
}],
"outbounds": [{
"type": "algeneva",
"tag": "algeneva-out",
"server": "${DROPLET_IP}",
"server_port": 9001,
"strategy": "[HTTP:host:*]-changecase{lower}-|"
}]
}
JSONEOF
# Start client
./lantern-box run --config /tmp/algeneva-client.json > /tmp/algeneva-client.log 2>&1 &
CLIENT_PID=$!
sleep 3
# Verify client is running
if ! kill -0 $CLIENT_PID 2>/dev/null; then
echo "ALGeneva client failed to start"
cat /tmp/algeneva-client.log
exit 1
fi
# Test
set +e
RESPONSE=$(curl -sf -x socks5h://127.0.0.1:1081 -m 30 http://example.com)
CURL_EXIT=$?
set -e
if echo "$RESPONSE" | grep -q "Example Domain"; then
echo "ALGeneva test PASSED"
else
echo "ALGeneva test FAILED (curl exit code: $CURL_EXIT)"
echo "Response: $RESPONSE"
cat /tmp/algeneva-client.log
kill $CLIENT_PID 2>/dev/null || true
exit 1
fi
kill $CLIENT_PID 2>/dev/null || true
- name: Test Samizdat
id: test_samizdat
continue-on-error: true
env:
DROPLET_IP: ${{ steps.droplet.outputs.droplet_ip }}
SAMIZDAT_PUB: ${{ steps.creds.outputs.samizdat_pub }}
SAMIZDAT_SHORT_ID: ${{ steps.creds.outputs.samizdat_short_id }}
run: |
cat > /tmp/samizdat-client.json << JSONEOF
{
"log": {"level": "debug"},
"inbounds": [{
"type": "mixed",
"tag": "mixed-in",
"listen": "127.0.0.1",
"listen_port": 1082
}],
"outbounds": [{
"type": "samizdat",
"tag": "samizdat-out",
"server": "${DROPLET_IP}",
"server_port": 9002,
"public_key": "${SAMIZDAT_PUB}",
"short_id": "${SAMIZDAT_SHORT_ID}",
"server_name": "example.com"
}]
}
JSONEOF
./lantern-box run --config /tmp/samizdat-client.json > /tmp/samizdat-client.log 2>&1 &
CLIENT_PID=$!
sleep 3
if ! kill -0 $CLIENT_PID 2>/dev/null; then
echo "Samizdat client failed to start"
cat /tmp/samizdat-client.log
exit 1
fi
set +e
RESPONSE=$(curl -sf -x socks5h://127.0.0.1:1082 -m 30 http://example.com)
CURL_EXIT=$?
set -e
if echo "$RESPONSE" | grep -q "Example Domain"; then
echo "Samizdat test PASSED"
else
echo "Samizdat test FAILED (curl exit code: $CURL_EXIT)"
echo "Response: $RESPONSE"
cat /tmp/samizdat-client.log
kill $CLIENT_PID 2>/dev/null || true
exit 1
fi
kill $CLIENT_PID 2>/dev/null || true
- name: Test WATER
id: test_water
continue-on-error: true
env:
DROPLET_IP: ${{ steps.droplet.outputs.droplet_ip }}
WASM_HASH: ${{ steps.creds.outputs.wasm_hash }}
run: |
cat > /tmp/water-client.json << JSONEOF
{
"log": {"level": "debug"},
"inbounds": [{
"type": "mixed",
"tag": "mixed-in",
"listen": "127.0.0.1",
"listen_port": 1083
}],
"outbounds": [{
"type": "water",
"tag": "water-out",
"server": "${DROPLET_IP}",
"server_port": 9003,
"transport": "plain",
"hashsum": "${WASM_HASH}",
"wasm_available_at": ["http://${DROPLET_IP}:8888/plain.wasm"],
"download_timeout": "60s",
"water_dir": "/tmp/water",
"config": {}
}]
}
JSONEOF
./lantern-box run --config /tmp/water-client.json > /tmp/water-client.log 2>&1 &
CLIENT_PID=$!
sleep 5
if ! kill -0 $CLIENT_PID 2>/dev/null; then
echo "WATER client failed to start"
cat /tmp/water-client.log
exit 1
fi
set +e
RESPONSE=$(curl -sf -x socks5h://127.0.0.1:1083 -m 30 http://example.com)
CURL_EXIT=$?
set -e
if echo "$RESPONSE" | grep -q "Example Domain"; then
echo "WATER test PASSED"
else
echo "WATER test FAILED (curl exit code: $CURL_EXIT)"
echo "Response: $RESPONSE"
cat /tmp/water-client.log
kill $CLIENT_PID 2>/dev/null || true
exit 1
fi
kill $CLIENT_PID 2>/dev/null || true
- name: Check test results
if: always()
run: |
FAILED=0
echo "=== E2E Test Results ==="
if [ "${{ steps.test_algeneva.outcome }}" = "success" ]; then
echo "ALGeneva: PASSED"
else
echo "ALGeneva: FAILED"
FAILED=1
fi
if [ "${{ steps.test_samizdat.outcome }}" = "success" ]; then
echo "Samizdat: PASSED"
else
echo "Samizdat: FAILED"
FAILED=1
fi
if [ "${{ steps.test_water.outcome }}" = "success" ]; then
echo "WATER: PASSED"
else
echo "WATER: FAILED"
FAILED=1
fi
echo "========================"
if [ "$FAILED" -ne 0 ]; then
echo "One or more tests failed"
exit 1
fi
- name: Collect server logs
if: always()
env:
DROPLET_IP: ${{ steps.droplet.outputs.droplet_ip }}
run: |
SSH_OPTS="-o StrictHostKeyChecking=no -o ConnectTimeout=10 -i e2e_key"
mkdir -p /tmp/server-logs
scp $SSH_OPTS root@"$DROPLET_IP":/root/*.log /tmp/server-logs/ 2>/dev/null || true
# Also grab client logs
cp /tmp/*-client.log /tmp/server-logs/ 2>/dev/null || true
- name: Upload logs
if: always()
uses: actions/upload-artifact@v4
with:
name: e2e-logs
path: /tmp/server-logs/
retention-days: 7
- name: Cleanup DO resources
if: always()
env:
DO_API_TOKEN: ${{ secrets.DO_API_TOKEN }}
run: |
DROPLET_ID="${{ steps.droplet.outputs.droplet_id }}"
SSH_KEY_ID="${{ steps.droplet.outputs.ssh_key_id }}"
# Fall back to DO API directly if doctl is not available
if command -v doctl &>/dev/null; then
if [ -n "$DROPLET_ID" ]; then
echo "Destroying droplet $DROPLET_ID..."
doctl compute droplet delete "$DROPLET_ID" --force || true
fi
if [ -n "$SSH_KEY_ID" ]; then
echo "Deleting SSH key $SSH_KEY_ID..."
doctl compute ssh-key delete "$SSH_KEY_ID" --force || true
fi
else
echo "doctl not available, using DO API directly"
if [ -n "$DROPLET_ID" ]; then
echo "Destroying droplet $DROPLET_ID..."
curl -sf -X DELETE "https://api.digitalocean.com/v2/droplets/$DROPLET_ID" \
-H "Authorization: Bearer $DO_API_TOKEN" || true
fi
if [ -n "$SSH_KEY_ID" ]; then
echo "Deleting SSH key $SSH_KEY_ID..."
curl -sf -X DELETE "https://api.digitalocean.com/v2/account/keys/$SSH_KEY_ID" \
-H "Authorization: Bearer $DO_API_TOKEN" || true
fi
fi