| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- package xray
- import (
- "testing"
- "github.com/xtls/xray-core/proxy/masque"
- )
- // Panel paths hand AddUser the client's "password"; the hot diff hands it the user
- // as GetXrayConfig emitted it, keyed "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": "[email protected]", "password": "pw-ivy"}},
- {"emitted core user", map[string]any{"email": "[email protected]", "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": "[email protected]"}); err == nil {
- t.Fatal("a MASQUE user without a password must be refused, not added unauthenticatable")
- }
- }
|