From 03253614c532f86294df7ff5bd6a929d6b47764d Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Sat, 18 Apr 2026 20:42:13 +0800 Subject: [PATCH] chore: add test for xhttp over vless encryption --- listener/inbound/vless_test.go | 120 +++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/listener/inbound/vless_test.go b/listener/inbound/vless_test.go index e7975ad3..f506beb0 100644 --- a/listener/inbound/vless_test.go +++ b/listener/inbound/vless_test.go @@ -489,6 +489,77 @@ func TestInboundVless_XHTTP_Reality(t *testing.T) { } } +func TestInboundVless_XHTTP_Encryption(t *testing.T) { + privateKeyBase64, passwordBase64, _, err := encryption.GenX25519("") + if err != nil { + t.Fatal(err) + return + } + testCases := []struct { + mode string + }{ + {mode: "auto"}, + {mode: "stream-one"}, + {mode: "stream-up"}, + {mode: "packet-up"}, + } + for _, testCase := range testCases { + testCase := testCase + t.Run(testCase.mode, func(t *testing.T) { + getConfig := func() (inbound.VlessOption, outbound.VlessOption) { + inboundOptions := inbound.VlessOption{ + Decryption: "mlkem768x25519plus.native.600s." + privateKeyBase64, + XHTTPConfig: inbound.XHTTPConfig{ + Path: "/vless-xhttp", + Host: "example.com", + Mode: testCase.mode, + }, + } + outboundOptions := outbound.VlessOption{ + Encryption: "mlkem768x25519plus.native.0rtt." + passwordBase64, + Network: "xhttp", + XHTTPOpts: outbound.XHTTPOptions{ + Path: "/vless-xhttp", + Host: "example.com", + Mode: testCase.mode, + }, + } + return inboundOptions, outboundOptions + } + + t.Run("nosplit", func(t *testing.T) { + t.Run("single", func(t *testing.T) { + inboundOptions, outboundOptions := getConfig() + testInboundVless(t, inboundOptions, outboundOptions) + }) + + t.Run("reuse", func(t *testing.T) { + inboundOptions, outboundOptions := getConfig() + testInboundVless(t, inboundOptions, withXHTTPReuse(outboundOptions)) + }) + }) + + t.Run("split", func(t *testing.T) { + if testCase.mode == "stream-one" { // stream-one not supported download settings + return + } + + t.Run("single", func(t *testing.T) { + inboundOptions, outboundOptions := getConfig() + outboundOptions.XHTTPOpts.DownloadSettings = &outbound.XHTTPDownloadSettings{} + testInboundVless(t, inboundOptions, outboundOptions) + }) + + t.Run("reuse", func(t *testing.T) { + inboundOptions, outboundOptions := getConfig() + outboundOptions.XHTTPOpts.DownloadSettings = &outbound.XHTTPDownloadSettings{} + testInboundVless(t, inboundOptions, withXHTTPReuse(outboundOptions)) + }) + }) + }) + } +} + func TestInboundVless_XHTTP_PacketUp_H1(t *testing.T) { getConfig := func() (inbound.VlessOption, outbound.VlessOption) { inboundOptions := inbound.VlessOption{ @@ -525,6 +596,55 @@ func TestInboundVless_XHTTP_PacketUp_H1(t *testing.T) { }) } +func TestInboundVless_XHTTP_PacketUp_H1_Encryption(t *testing.T) { + privateKeyBase64, passwordBase64, _, err := encryption.GenX25519("") + if err != nil { + t.Fatal(err) + return + } + getConfig := func() (inbound.VlessOption, outbound.VlessOption) { + inboundOptions := inbound.VlessOption{ + Decryption: "mlkem768x25519plus.native.600s." + privateKeyBase64, + XHTTPConfig: inbound.XHTTPConfig{ + Path: "/vless-xhttp", + Host: "example.com", + Mode: "packet-up", + }, + } + outboundOptions := outbound.VlessOption{ + Encryption: "mlkem768x25519plus.native.0rtt." + passwordBase64, + Network: "xhttp", + ALPN: []string{"http/1.1"}, + XHTTPOpts: outbound.XHTTPOptions{ + Path: "/vless-xhttp", + Host: "example.com", + Mode: "packet-up", + }, + } + return inboundOptions, outboundOptions + } + + t.Run("default", func(t *testing.T) { + inboundOptions, outboundOptions := getConfig() + testInboundVless(t, inboundOptions, outboundOptions) + t.Run("xtls-rprx-vision", func(t *testing.T) { + outboundOptions := outboundOptions + outboundOptions.Flow = "xtls-rprx-vision" + testInboundVless(t, inboundOptions, outboundOptions) + }) + }) + + t.Run("reuse", func(t *testing.T) { + inboundOptions, outboundOptions := getConfig() + testInboundVless(t, inboundOptions, outboundOptions) + t.Run("xtls-rprx-vision", func(t *testing.T) { + outboundOptions := outboundOptions + outboundOptions.Flow = "xtls-rprx-vision" + testInboundVless(t, inboundOptions, outboundOptions) + }) + }) +} + func withXHTTPReuse(out outbound.VlessOption) outbound.VlessOption { out.XHTTPOpts.ReuseSettings = &outbound.XHTTPReuseSettings{ MaxConnections: "0",