Esempio n. 1
0
func TestUDPDestination(t *testing.T) {
	assert := assert.On(t)

	dest := v2net.UDPDestination(v2net.IPAddress([]byte{0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88}), 53)
	assert.Destination(dest).IsNotTCP()
	assert.Destination(dest).IsUDP()
	assert.Destination(dest).EqualsString("udp:[2001:4860:4860::8888]:53")
}
Esempio n. 2
0
func TestTCPDestination(t *testing.T) {
	assert := assert.On(t)

	dest := v2net.TCPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80)
	assert.Destination(dest).IsTCP()
	assert.Destination(dest).IsNotUDP()
	assert.Destination(dest).EqualsString("tcp:1.2.3.4:80")
}
Esempio n. 3
0
func TestIPResolution(t *testing.T) {
	assert := assert.On(t)

	space := app.NewSpace()
	space.BindApp(proxyman.APP_ID_OUTBOUND_MANAGER, outbound.New())
	space.BindApp(dispatcher.APP_ID, dispatchers.NewDefaultDispatcher(space))
	r := router.NewRouter(&router.Config{}, space)
	space.BindApp(router.APP_ID, r)
	dnsServer := dnsserver.NewCacheServer(space, &dns.Config{
		Hosts: map[string]*v2net.IPOrDomain{
			"v2ray.com": v2net.NewIPOrDomain(v2net.LocalHostIP),
		},
	})
	space.BindApp(dns.APP_ID, dnsServer)

	freedom := NewFreedomConnection(
		&Config{DomainStrategy: Config_USE_IP},
		space,
		&proxy.OutboundHandlerMeta{
			Address: v2net.AnyIP,
			StreamSettings: &internet.StreamConfig{
				Network: v2net.Network_RawTCP,
			},
		})

	space.Initialize()

	ipDest := freedom.ResolveIP(v2net.TCPDestination(v2net.DomainAddress("v2ray.com"), v2net.Port(80)))
	assert.Destination(ipDest).IsTCP()
	assert.Address(ipDest.Address).Equals(v2net.LocalHostIP)
}
Esempio n. 4
0
func TestIPResolution(t *testing.T) {
	assert := assert.On(t)

	space := app.NewSpace()
	space.BindApp(proxyman.APP_ID_OUTBOUND_MANAGER, proxyman.NewDefaultOutboundHandlerManager())
	space.BindApp(dispatcher.APP_ID, dispatchers.NewDefaultDispatcher(space))
	r, _ := router.CreateRouter("rules", &rules.RouterRuleConfig{}, space)
	space.BindApp(router.APP_ID, r)
	dnsServer := dns.NewCacheServer(space, &dns.Config{
		Hosts: map[string]net.IP{
			"v2ray.com": net.IP([]byte{127, 0, 0, 1}),
		},
	})
	space.BindApp(dns.APP_ID, dnsServer)

	freedom := NewFreedomConnection(
		&Config{DomainStrategy: DomainStrategyUseIP},
		space,
		&proxy.OutboundHandlerMeta{
			Address: v2net.AnyIP,
			StreamSettings: &internet.StreamSettings{
				Type: internet.StreamConnectionTypeRawTCP,
			},
		})

	space.Initialize()

	ipDest := freedom.ResolveIP(v2net.TCPDestination(v2net.DomainAddress("v2ray.com"), v2net.Port(80)))
	assert.Destination(ipDest).IsTCP()
	assert.Address(ipDest.Address()).Equals(v2net.LocalHostIP)
}
Esempio n. 5
0
func TestConfigTargetParsing(t *testing.T) {
	assert := assert.On(t)

	rawJson := `{
    "vnext": [{
      "address": "127.0.0.1",
      "port": 80,
      "users": [
        {
          "id": "e641f5ad-9397-41e3-bf1a-e8740dfed019",
          "email": "*****@*****.**",
          "level": 255
        }
      ]
    }]
  }`

	rawConfig := new(VMessOutboundConfig)
	err := json.Unmarshal([]byte(rawJson), &rawConfig)
	assert.Error(err).IsNil()

	ts, err := rawConfig.Build()
	assert.Error(err).IsNil()

	iConfig, err := ts.GetInstance()
	assert.Error(err).IsNil()

	config := iConfig.(*outbound.Config)
	specPB := config.Receiver[0]
	spec := protocol.NewServerSpecFromPB(*specPB)
	assert.Destination(spec.Destination()).EqualsString("tcp:127.0.0.1:80")
}
Esempio n. 6
0
func TestConfigParsing(t *testing.T) {
	assert := assert.On(t)

	rawJson := `{
    "servers": ["8.8.8.8"]
  }`

	config := new(Config)
	err := json.Unmarshal([]byte(rawJson), config)
	assert.Error(err).IsNil()
	assert.Int(len(config.NameServers)).Equals(1)
	assert.Destination(config.NameServers[0]).IsUDP()
	assert.Address(config.NameServers[0].Address()).Equals(v2net.IPAddress([]byte{8, 8, 8, 8}))
	assert.Port(config.NameServers[0].Port()).Equals(v2net.Port(53))
}
Esempio n. 7
0
func TestDnsConfigParsing(t *testing.T) {
	assert := assert.On(t)

	rawJson := `{
    "servers": ["8.8.8.8"]
  }`

	jsonConfig := new(DnsConfig)
	err := json.Unmarshal([]byte(rawJson), jsonConfig)
	assert.Error(err).IsNil()

	config := jsonConfig.Build()
	assert.Int(len(config.NameServers)).Equals(1)
	dest := config.NameServers[0].AsDestination()
	assert.Destination(dest).IsUDP()
	assert.Address(dest.Address).Equals(v2net.IPAddress([]byte{8, 8, 8, 8}))
	assert.Port(dest.Port).Equals(v2net.Port(53))
}
Esempio n. 8
0
func TestSocksOutboundConfig(t *testing.T) {
	assert := assert.On(t)

	rawJson := `{
    "servers": [{
      "address": "127.0.0.1",
      "port": 1234,
      "users": [
        {"user": "******", "pass": "******", "email": "*****@*****.**"}
      ]
    }]
  }`

	config := new(SocksClientConfig)
	err := json.Unmarshal([]byte(rawJson), &config)
	assert.Error(err).IsNil()

	message, err := config.Build()
	assert.Error(err).IsNil()

	iConfig, err := message.GetInstance()
	assert.Error(err).IsNil()

	socksConfig := iConfig.(*socks.ClientConfig)
	assert.Int(len(socksConfig.Server)).Equals(1)

	ss := protocol.NewServerSpecFromPB(*socksConfig.Server[0])
	assert.Destination(ss.Destination()).EqualsString("tcp:127.0.0.1:1234")

	user := ss.PickUser()
	assert.String(user.Email).Equals("*****@*****.**")

	account, err := user.GetTypedAccount()
	assert.Error(err).IsNil()

	socksAccount := account.(*socks.Account)
	assert.String(socksAccount.Username).Equals("test user")
	assert.String(socksAccount.Password).Equals("test pass")
}
Esempio n. 9
0
func TestConfigTargetParsing(t *testing.T) {
	assert := assert.On(t)

	rawJson := `{
    "vnext": [{
      "address": "127.0.0.1",
      "port": 80,
      "users": [
        {
          "id": "e641f5ad-9397-41e3-bf1a-e8740dfed019",
          "email": "*****@*****.**",
          "level": 255
        }
      ]
    }]
  }`

	config := new(Config)
	err := json.Unmarshal([]byte(rawJson), &config)
	assert.Error(err).IsNil()
	assert.Destination(config.Receivers[0].Destination()).EqualsString("tcp:127.0.0.1:80")
}