api_masque_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package xray
  2. import (
  3. "testing"
  4. "github.com/xtls/xray-core/proxy/masque"
  5. )
  6. // Panel paths hand AddUser the client's "password"; the hot diff hands it the user
  7. // as GetXrayConfig emitted it, keyed "pass". Without an account the core adds a
  8. // MASQUE user it can never authenticate.
  9. func TestBuildUserAccountMasque(t *testing.T) {
  10. tests := []struct {
  11. name string
  12. user map[string]any
  13. }{
  14. {"panel client", map[string]any{"email": "[email protected]", "password": "pw-ivy"}},
  15. {"emitted core user", map[string]any{"email": "[email protected]", "pass": "pw-ivy"}},
  16. }
  17. for _, tc := range tests {
  18. t.Run(tc.name, func(t *testing.T) {
  19. typed, err := buildUserAccount("masque", tc.user)
  20. if err != nil {
  21. t.Fatalf("buildUserAccount: %v", err)
  22. }
  23. if typed == nil {
  24. t.Fatal("buildUserAccount returned no account")
  25. }
  26. instance, err := typed.GetInstance()
  27. if err != nil {
  28. t.Fatalf("GetInstance: %v", err)
  29. }
  30. account, ok := instance.(*masque.Account)
  31. if !ok || account.Password != "pw-ivy" {
  32. t.Fatalf("account = %#v, want a masque.Account with password pw-ivy", instance)
  33. }
  34. })
  35. }
  36. if _, err := buildUserAccount("masque", map[string]any{"email": "[email protected]"}); err == nil {
  37. t.Fatal("a MASQUE user without a password must be refused, not added unauthenticatable")
  38. }
  39. }