config_json_test.go 812 B

1234567891011121314151617181920212223242526272829303132
  1. // +build json
  2. package http_test
  3. import (
  4. "encoding/json"
  5. "testing"
  6. v2net "github.com/v2ray/v2ray-core/common/net"
  7. . "github.com/v2ray/v2ray-core/proxy/http"
  8. v2testing "github.com/v2ray/v2ray-core/testing"
  9. "github.com/v2ray/v2ray-core/testing/assert"
  10. )
  11. func TestOwnHosts(t *testing.T) {
  12. v2testing.Current(t)
  13. rawJson := `{
  14. "ownHosts": [
  15. "127.0.0.1",
  16. "google.com"
  17. ]
  18. }`
  19. config := new(Config)
  20. err := json.Unmarshal([]byte(rawJson), config)
  21. assert.Error(err).IsNil()
  22. assert.Bool(config.IsOwnHost(v2net.IPAddress([]byte{127, 0, 0, 1}))).IsTrue()
  23. assert.Bool(config.IsOwnHost(v2net.DomainAddress("google.com"))).IsTrue()
  24. assert.Bool(config.IsOwnHost(v2net.DomainAddress("local.v2ray.com"))).IsTrue()
  25. assert.Bool(config.IsOwnHost(v2net.DomainAddress("v2ray.com"))).IsFalse()
  26. }