default_template_freedom_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. package service
  2. import (
  3. "encoding/json"
  4. "testing"
  5. )
  6. // The embedded template is what every fresh install starts from, so it must not
  7. // carry the freedom strategy keys the core warns about on every config load.
  8. func TestDefaultXrayTemplateKeepsFreedomStrategyOutOfTheLegacyKeys(t *testing.T) {
  9. var cfg struct {
  10. Outbounds []map[string]any `json:"outbounds"`
  11. }
  12. if err := json.Unmarshal([]byte(xrayTemplateConfig), &cfg); err != nil {
  13. t.Fatalf("embedded config.json is not JSON: %v", err)
  14. }
  15. freedom := 0
  16. for _, ob := range cfg.Outbounds {
  17. if ob["protocol"] != "freedom" {
  18. continue
  19. }
  20. freedom++
  21. tag := ob["tag"]
  22. if _, ok := ob["targetStrategy"]; ok {
  23. t.Errorf("freedom outbound %v carries the outbound-root targetStrategy", tag)
  24. }
  25. settings, _ := ob["settings"].(map[string]any)
  26. for _, key := range []string{"domainStrategy", "targetStrategy"} {
  27. if _, ok := settings[key]; ok {
  28. t.Errorf("freedom outbound %v carries the deprecated settings.%s", tag, key)
  29. }
  30. }
  31. }
  32. if freedom == 0 {
  33. t.Fatal("the default template has no freedom outbound to check")
  34. }
  35. }