Files
3x-ui/internal/web/service/outbound/outbound_endpoints_test.go
MHSanaei b04039c2bd feat(xray): add the MASQUE protocol and transport
xray-core v26.10.10 serves MASQUE: CONNECT-IP over HTTP/3 or HTTP/2,
always behind TLS, as an inbound and an outbound protocol riding a
dedicated "masque" transport. The panel could not create either.

Inbound: MASQUE is a multi-user protocol whose users log in with their
email and password over Basic auth. The panel keeps the client's
"password" like trojan and GenXrayInboundConfig hands it to the core as
"pass", so the full-config path, the live AddInbound path and node
pushes all emit what the core reads; one user with an empty pass makes
the core refuse the whole inbound. Live user adds build a masque.Account
from either key, client-only changes diff per user so a new client does
not drop every connected tunnel, and client creation, copy, validation
and edits key on the password. The address pool and MTU get form
fields, TLS is mandatory, and the port check follows the core's
listener choice: HTTP/2 on TCP when the ALPN offers h2, HTTP/3 on UDP
when it offers h3 or not h2. Nodes may host MASQUE from v3.9.1, the
first panel release that knows to rename the password.

MASQUE has no share-link format, so links and Clash skip it; the JSON
subscription builds the client's masque outbound with its email and
password, and the subscription allowlist now lets a subId see MASQUE
inbounds at all. The IP-limit job, client pages and traffic tracking
list the protocol.

Outbound: the form edits the server, remote DNS, and the transport's
host, path, Basic credentials, headers and WARP block (enrolled key,
endpoint public key, tunnel addresses), which xray-core refuses next to
user/pass. The outbound test probes it through the core, since its
default HTTP/3 dial is UDP.
2026-10-11 10:28:49 +02:00

67 lines
1.8 KiB
Go

package outbound
import (
"reflect"
"testing"
)
func TestExtractOutboundEndpointsVLESS(t *testing.T) {
tests := []struct {
name string
settings map[string]any
want []string
}{
{
name: "vnext endpoints",
settings: map[string]any{
"vnext": []any{
map[string]any{"address": "first.example.com", "port": float64(443)},
map[string]any{"address": "second.example.com", "port": float64(8443)},
},
},
want: []string{"first.example.com:443", "second.example.com:8443"},
},
{
name: "flat endpoint",
settings: map[string]any{
"address": "legacy.example.com",
"port": float64(443),
},
want: []string{"legacy.example.com:443"},
},
{
name: "invalid vnext falls back to flat endpoint",
settings: map[string]any{
"vnext": []any{map[string]any{"address": "missing-port.example.com"}},
"address": "fallback.example.com",
"port": float64(2053),
},
want: []string{"fallback.example.com:2053"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := extractOutboundEndpoints(map[string]any{
"protocol": "vless",
"settings": tt.settings,
})
if !reflect.DeepEqual(got, tt.want) {
t.Fatalf("extractOutboundEndpoints() = %v, want %v", got, tt.want)
}
})
}
}
// A MASQUE outbound names its server flat in settings, like hysteria; without it the
// outbound test has no endpoint to resolve and reports the outbound unreachable.
func TestExtractOutboundEndpointsMasque(t *testing.T) {
got := extractOutboundEndpoints(map[string]any{
"protocol": "masque",
"settings": map[string]any{"address": "masque.example.com", "port": float64(8443)},
})
if want := []string{"masque.example.com:8443"}; !reflect.DeepEqual(got, want) {
t.Fatalf("extractOutboundEndpoints() = %v, want %v", got, want)
}
}