1
0

outbound_validation_test.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package xray
  2. import (
  3. "strings"
  4. "testing"
  5. )
  6. // TestValidateOutboundConfig_RejectsUnencryptedPublicVless covers xray-core
  7. // v26.7.11's refusal to build an unencrypted vless outbound to a public
  8. // address — the check now runs in-process, so the panel can surface it before
  9. // a config reaches the core and bricks startup. A private-address outbound and
  10. // a TLS outbound stay valid.
  11. func TestValidateOutboundConfig_RejectsUnencryptedPublicVless(t *testing.T) {
  12. publicPlaintext := `{
  13. "protocol": "vless",
  14. "settings": {"address": "1.2.3.4", "port": 443, "id": "b831381d-6324-4d53-ad4f-8cda48b30811", "encryption": "none"},
  15. "streamSettings": {"network": "tcp", "security": "none"}
  16. }`
  17. if err := ValidateOutboundConfig([]byte(publicPlaintext)); err == nil {
  18. t.Fatal("expected a public unencrypted vless outbound to be rejected")
  19. } else if !strings.Contains(err.Error(), "prohibited") {
  20. t.Fatalf("expected a prohibition error, got: %v", err)
  21. }
  22. privatePlaintext := `{
  23. "protocol": "vless",
  24. "settings": {"address": "10.0.0.1", "port": 443, "id": "b831381d-6324-4d53-ad4f-8cda48b30811", "encryption": "none"},
  25. "streamSettings": {"network": "tcp", "security": "none"}
  26. }`
  27. if err := ValidateOutboundConfig([]byte(privatePlaintext)); err != nil {
  28. t.Fatalf("a private-address plaintext vless outbound must stay valid, got: %v", err)
  29. }
  30. publicTLS := `{
  31. "protocol": "vless",
  32. "settings": {"address": "1.2.3.4", "port": 443, "id": "b831381d-6324-4d53-ad4f-8cda48b30811", "encryption": "none"},
  33. "streamSettings": {"network": "tcp", "security": "tls", "tlsSettings": {"serverName": "example.com"}}
  34. }`
  35. if err := ValidateOutboundConfig([]byte(publicTLS)); err != nil {
  36. t.Fatalf("a TLS-secured public vless outbound must stay valid, got: %v", err)
  37. }
  38. }