api_masque_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 the emitted user's
  7. // "pass"; without an account the core adds a MASQUE user it can never authenticate.
  8. func TestBuildUserAccountMasque(t *testing.T) {
  9. tests := []struct {
  10. name string
  11. user map[string]any
  12. }{
  13. {"panel client", map[string]any{"email": "[email protected]", "password": "pw-ivy"}},
  14. {"emitted core user", map[string]any{"email": "[email protected]", "pass": "pw-ivy"}},
  15. }
  16. for _, tc := range tests {
  17. t.Run(tc.name, func(t *testing.T) {
  18. typed, err := buildUserAccount("masque", tc.user)
  19. if err != nil {
  20. t.Fatalf("buildUserAccount: %v", err)
  21. }
  22. if typed == nil {
  23. t.Fatal("buildUserAccount returned no account")
  24. }
  25. instance, err := typed.GetInstance()
  26. if err != nil {
  27. t.Fatalf("GetInstance: %v", err)
  28. }
  29. account, ok := instance.(*masque.Account)
  30. if !ok || account.Password != "pw-ivy" {
  31. t.Fatalf("account = %#v, want a masque.Account with password pw-ivy", instance)
  32. }
  33. })
  34. }
  35. if _, err := buildUserAccount("masque", map[string]any{"email": "[email protected]"}); err == nil {
  36. t.Fatal("a MASQUE user without a password must be refused, not added unauthenticatable")
  37. }
  38. }