config_json_test.go 765 B

12345678910111213141516171819202122232425262728293031
  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. "github.com/v2ray/v2ray-core/testing/assert"
  9. )
  10. func TestOwnHosts(t *testing.T) {
  11. assert := assert.On(t)
  12. rawJson := `{
  13. "ownHosts": [
  14. "127.0.0.1",
  15. "google.com"
  16. ]
  17. }`
  18. config := new(Config)
  19. err := json.Unmarshal([]byte(rawJson), config)
  20. assert.Error(err).IsNil()
  21. assert.Bool(config.IsOwnHost(v2net.IPAddress([]byte{127, 0, 0, 1}))).IsTrue()
  22. assert.Bool(config.IsOwnHost(v2net.DomainAddress("google.com"))).IsTrue()
  23. assert.Bool(config.IsOwnHost(v2net.DomainAddress("local.v2ray.com"))).IsTrue()
  24. assert.Bool(config.IsOwnHost(v2net.DomainAddress("v2ray.com"))).IsFalse()
  25. }