mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-13 08:35:00 +03:00
243b5c9da7
A Host Description is appended to every raw-subscription node name as a base64 `?serverDescription=` tail. Only Happ and INCY read it; v2rayN, v2rayNG, OpenClash and the rest show it as part of the node name, and the only way out was clearing the Description (#7105). The raw subscription body now carries the tail only when the requesting User-Agent is Happ or INCY, for the endpoint links and the Hysteria2 loop alike. Copied links, QR codes and the panel's link export keep it, since the server cannot tell which client they end up in. Closes #7105
61 lines
2.0 KiB
Go
61 lines
2.0 KiB
Go
package sub
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/mhsanaei/3x-ui/v3/internal/database/model"
|
|
)
|
|
|
|
// #6738: without the host's Description on hysteria(2):// links, Happ falls back
|
|
// to its own "Hysteria | hysteria | TLS" caption on a host that also serves VLESS.
|
|
func TestGenHysteriaLinkAppendsHostServerDescription(t *testing.T) {
|
|
tests := map[string]struct {
|
|
version int
|
|
scheme string
|
|
}{
|
|
"hysteria v1": {version: 1, scheme: "hysteria://"},
|
|
"hysteria v2": {version: 2, scheme: "hysteria2://"},
|
|
}
|
|
for name, tc := range tests {
|
|
t.Run(name, func(t *testing.T) {
|
|
host := &model.Host{
|
|
Address: "hy.example.com", Port: 443,
|
|
Remark: "Poland", ServerDescription: "Wi-Fi",
|
|
}
|
|
stream := map[string]any{
|
|
"security": "tls",
|
|
"externalProxy": []any{hostToExternalProxyMap(host, "hy.example.com", 443)},
|
|
}
|
|
rawStream, err := json.Marshal(stream)
|
|
if err != nil {
|
|
t.Fatalf("marshal stream settings: %v", err)
|
|
}
|
|
// The inbound's own `version` picks the hysteria vs hysteria2 scheme.
|
|
rawSettings, err := json.Marshal(map[string]any{
|
|
"version": tc.version,
|
|
"clients": []any{map[string]any{"auth": "secret", "email": "user"}},
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("marshal inbound settings: %v", err)
|
|
}
|
|
in := &model.Inbound{
|
|
Id: 920010, Listen: "203.0.113.1", Port: 443, Protocol: model.Hysteria,
|
|
Remark: "hy", StreamSettings: string(rawStream), Settings: string(rawSettings),
|
|
}
|
|
got := (&SubService{}).genHysteriaLink(in, "user")
|
|
if !strings.HasPrefix(got, tc.scheme) {
|
|
t.Fatalf("link scheme changed.\n got: %s\nwant prefix: %s", got, tc.scheme)
|
|
}
|
|
// base64("Wi-Fi"), matching the reporter's subscription output.
|
|
if !strings.HasSuffix(got, "?serverDescription=V2ktRmk=") {
|
|
t.Fatalf("host serverDescription missing from fragment.\n got: %s\nwant suffix: ?serverDescription=V2ktRmk=", got)
|
|
}
|
|
if got := (&SubService{omitServerDescription: true}).genHysteriaLink(in, "user"); strings.Contains(got, "serverDescription") {
|
|
t.Fatalf("tail not omitted: %s", got)
|
|
}
|
|
})
|
|
}
|
|
}
|