Files
3x-ui/internal/xray/api_masque_test.go
T
MHSanaei a8255944bf style: trim MASQUE and XDRIVE comment blocks to two lines
The MASQUE and XDRIVE commits left four comment blocks over the
two-line cap CLAUDE.md sets for committed Go/TS.
2026-10-11 17:00:52 +02:00

43 lines
1.3 KiB
Go

package xray
import (
"testing"
"github.com/xtls/xray-core/proxy/masque"
)
// Panel paths hand AddUser the client's "password", the hot diff the emitted user's
// "pass"; without an account the core adds a MASQUE user it can never authenticate.
func TestBuildUserAccountMasque(t *testing.T) {
tests := []struct {
name string
user map[string]any
}{
{"panel client", map[string]any{"email": "ivy@example.test", "password": "pw-ivy"}},
{"emitted core user", map[string]any{"email": "ivy@example.test", "pass": "pw-ivy"}},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
typed, err := buildUserAccount("masque", tc.user)
if err != nil {
t.Fatalf("buildUserAccount: %v", err)
}
if typed == nil {
t.Fatal("buildUserAccount returned no account")
}
instance, err := typed.GetInstance()
if err != nil {
t.Fatalf("GetInstance: %v", err)
}
account, ok := instance.(*masque.Account)
if !ok || account.Password != "pw-ivy" {
t.Fatalf("account = %#v, want a masque.Account with password pw-ivy", instance)
}
})
}
if _, err := buildUserAccount("masque", map[string]any{"email": "ivy@example.test"}); err == nil {
t.Fatal("a MASQUE user without a password must be refused, not added unauthenticatable")
}
}