本文整理汇总了Golang中v2ray/com/core/testing/assert.Port函数的典型用法代码示例。如果您正苦于以下问题:Golang Port函数的具体用法?Golang Port怎么用?Golang Port使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Port函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestUDPEncoding
func TestUDPEncoding(t *testing.T) {
assert := assert.On(t)
request := &protocol.RequestHeader{
Version: Version,
Command: protocol.RequestCommandUDP,
Address: v2net.LocalHostIP,
Port: 1234,
User: &protocol.User{
Email: "[email protected]",
Account: loader.NewTypedSettings(&Account{
Password: "shadowsocks-password",
CipherType: CipherType_AES_128_CFB,
Ota: Account_Disabled,
}),
},
}
data := alloc.NewLocalBuffer(256).Clear().AppendString("test string")
encodedData, err := EncodeUDPPacket(request, data)
assert.Error(err).IsNil()
decodedRequest, decodedData, err := DecodeUDPPacket(request.User, encodedData)
assert.Error(err).IsNil()
assert.Bytes(decodedData.Value).Equals(data.Value)
assert.Address(decodedRequest.Address).Equals(request.Address)
assert.Port(decodedRequest.Port).Equals(request.Port)
}
示例2: TestUDPEncoding
func TestUDPEncoding(t *testing.T) {
assert := assert.On(t)
request := &protocol.RequestHeader{
Version: Version,
Command: protocol.RequestCommandUDP,
Address: v2net.LocalHostIP,
Port: 1234,
User: &protocol.User{
Email: "[email protected]",
Account: serial.ToTypedMessage(&Account{
Password: "shadowsocks-password",
CipherType: CipherType_AES_128_CFB,
Ota: Account_Disabled,
}),
},
}
data := buf.NewLocal(256)
data.AppendSupplier(serial.WriteString("test string"))
encodedData, err := EncodeUDPPacket(request, data)
assert.Error(err).IsNil()
decodedRequest, decodedData, err := DecodeUDPPacket(request.User, encodedData)
assert.Error(err).IsNil()
assert.Bytes(decodedData.Bytes()).Equals(data.Bytes())
assert.Address(decodedRequest.Address).Equals(request.Address)
assert.Port(decodedRequest.Port).Equals(request.Port)
}
示例3: TestTCPRequest
func TestTCPRequest(t *testing.T) {
assert := assert.On(t)
request := &protocol.RequestHeader{
Version: Version,
Command: protocol.RequestCommandTCP,
Address: v2net.LocalHostIP,
Option: RequestOptionOneTimeAuth,
Port: 1234,
User: &protocol.User{
Email: "[email protected]",
Account: loader.NewTypedSettings(&Account{
Password: "tcp-password",
CipherType: CipherType_CHACHA20,
}),
},
}
data := alloc.NewLocalBuffer(256).Clear().AppendString("test string")
cache := alloc.NewBuffer().Clear()
writer, err := WriteTCPRequest(request, cache)
assert.Error(err).IsNil()
writer.Write(data)
decodedRequest, reader, err := ReadTCPSession(request.User, cache)
assert.Error(err).IsNil()
assert.Address(decodedRequest.Address).Equals(request.Address)
assert.Port(decodedRequest.Port).Equals(request.Port)
decodedData, err := reader.Read()
assert.Error(err).IsNil()
assert.Bytes(decodedData.Value).Equals([]byte("test string"))
}
示例4: TestSwitchAccount
func TestSwitchAccount(t *testing.T) {
assert := assert.On(t)
sa := &protocol.CommandSwitchAccount{
Port: 1234,
ID: uuid.New(),
AlterIds: 1024,
Level: 128,
ValidMin: 16,
}
buffer := buf.New()
err := MarshalCommand(sa, buffer)
assert.Error(err).IsNil()
cmd, err := UnmarshalCommand(1, buffer.BytesFrom(2))
assert.Error(err).IsNil()
sa2, ok := cmd.(*protocol.CommandSwitchAccount)
assert.Bool(ok).IsTrue()
assert.Pointer(sa.Host).IsNil()
assert.Pointer(sa2.Host).IsNil()
assert.Port(sa.Port).Equals(sa2.Port)
assert.String(sa.ID.String()).Equals(sa2.ID.String())
assert.Uint16(sa.AlterIds).Equals(sa2.AlterIds)
assert.Byte(byte(sa.Level)).Equals(byte(sa2.Level))
assert.Byte(sa.ValidMin).Equals(sa2.ValidMin)
}
示例5: TestNormalGetRequest
func TestNormalGetRequest(t *testing.T) {
assert := assert.On(t)
testPacketDispatcher := testdispatcher.NewTestPacketDispatcher(nil)
port := v2net.Port(dice.Roll(20000) + 10000)
httpProxy := NewServer(
&Config{},
testPacketDispatcher,
&proxy.InboundHandlerMeta{
Address: v2net.LocalHostIP,
Port: port,
StreamSettings: &internet.StreamSettings{
Type: internet.StreamConnectionTypeRawTCP,
}})
defer httpProxy.Close()
err := httpProxy.Start()
assert.Error(err).IsNil()
assert.Port(port).Equals(httpProxy.Port())
httpClient := &http.Client{}
resp, err := httpClient.Get("http://127.0.0.1:" + port.String() + "/")
assert.Error(err).IsNil()
assert.Int(resp.StatusCode).Equals(400)
}
示例6: TestIPv6Request
func TestIPv6Request(t *testing.T) {
assert := assert.On(t)
request, err := ReadRequest(alloc.NewBuffer().Clear().AppendBytes(5, 1, 0, 4, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 0, 8))
assert.Error(err).IsNil()
assert.Byte(request.Command).Equals(1)
assert.Bytes(request.IPv6[:]).Equals([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6})
assert.Port(request.Port).Equals(8)
}
示例7: TestServerList
func TestServerList(t *testing.T) {
assert := assert.On(t)
list := NewServerList()
list.AddServer(NewServerSpec(v2net.TCPDestination(v2net.LocalHostIP, v2net.Port(1)), AlwaysValid()))
assert.Uint32(list.Size()).Equals(1)
list.AddServer(NewServerSpec(v2net.TCPDestination(v2net.LocalHostIP, v2net.Port(2)), BeforeTime(time.Now().Add(time.Second))))
assert.Uint32(list.Size()).Equals(2)
server := list.GetServer(1)
assert.Port(server.Destination().Port).Equals(2)
time.Sleep(2 * time.Second)
server = list.GetServer(1)
assert.Pointer(server).IsNil()
server = list.GetServer(0)
assert.Port(server.Destination().Port).Equals(1)
}
示例8: TestConfigParsing
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))
}
示例9: TestSocks4AuthenticationRequestRead
func TestSocks4AuthenticationRequestRead(t *testing.T) {
assert := assert.On(t)
rawRequest := []byte{
0x04, // version
0x01, // command
0x00, 0x35,
0x72, 0x72, 0x72, 0x72,
}
_, request4, err := ReadAuthentication(bytes.NewReader(rawRequest))
assert.Error(err).Equals(Socks4Downgrade)
assert.Byte(request4.Version).Equals(0x04)
assert.Byte(request4.Command).Equals(0x01)
assert.Port(request4.Port).Equals(v2net.Port(53))
assert.Bytes(request4.IP[:]).Equals([]byte{0x72, 0x72, 0x72, 0x72})
}
示例10: TestDomainAddressRequest
func TestDomainAddressRequest(t *testing.T) {
assert := assert.On(t)
payload := make([]byte, 0, 1024)
payload = append(payload, 0, 0, 1, AddrTypeDomain, byte(len("v2ray.com")))
payload = append(payload, []byte("v2ray.com")...)
payload = append(payload, 0, 80)
payload = append(payload, []byte("Actual payload")...)
request, err := ReadUDPRequest(payload)
assert.Error(err).IsNil()
assert.Byte(request.Fragment).Equals(1)
assert.Address(request.Address).EqualsString("v2ray.com")
assert.Port(request.Port).Equals(v2net.Port(80))
assert.String(request.Data.String()).Equals("Actual payload")
}
示例11: TestDnsConfigParsing
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))
}
示例12: TestRequestRead
func TestRequestRead(t *testing.T) {
assert := assert.On(t)
rawRequest := []byte{
0x05, // version
0x01, // cmd connect
0x00, // reserved
0x01, // ipv4 type
0x72, 0x72, 0x72, 0x72, // 114.114.114.114
0x00, 0x35, // port 53
}
request, err := ReadRequest(bytes.NewReader(rawRequest))
assert.Error(err).IsNil()
assert.Byte(request.Version).Equals(0x05)
assert.Byte(request.Command).Equals(0x01)
assert.Byte(request.AddrType).Equals(0x01)
assert.Bytes(request.IPv4[:]).Equals([]byte{0x72, 0x72, 0x72, 0x72})
assert.Port(request.Port).Equals(v2net.Port(53))
}
示例13: TestServerSampleConfig
func TestServerSampleConfig(t *testing.T) {
assert := assert.On(t)
GOPATH := os.Getenv("GOPATH")
baseDir := filepath.Join(GOPATH, "src", "v2ray.com", "core", "tools", "release", "config")
pointConfig, err := LoadConfig(filepath.Join(baseDir, "vpoint_vmess_freedom.json"))
assert.Error(err).IsNil()
assert.Pointer(pointConfig.InboundConfig).IsNotNil()
assert.Port(pointConfig.InboundConfig.Port).IsValid()
assert.Pointer(pointConfig.OutboundConfig).IsNotNil()
assert.String(pointConfig.InboundConfig.Protocol).Equals("vmess")
assert.Pointer(pointConfig.InboundConfig.Settings).IsNotNil()
assert.String(pointConfig.OutboundConfig.Protocol).Equals("freedom")
assert.Pointer(pointConfig.OutboundConfig.Settings).IsNotNil()
}
示例14: TestRequestSerialization
func TestRequestSerialization(t *testing.T) {
assert := assert.On(t)
user := &protocol.User{
Level: 0,
Email: "[email protected]",
}
account := &vmess.Account{
Id: uuid.New().String(),
AlterId: 0,
}
user.Account = serial.ToTypedMessage(account)
expectedRequest := &protocol.RequestHeader{
Version: 1,
User: user,
Command: protocol.RequestCommandTCP,
Option: protocol.RequestOptionConnectionReuse,
Address: v2net.DomainAddress("www.v2ray.com"),
Port: v2net.Port(443),
Security: protocol.Security(protocol.SecurityType_AES128_GCM),
}
buffer := buf.New()
client := NewClientSession(protocol.DefaultIDHash)
client.EncodeRequestHeader(expectedRequest, buffer)
userValidator := vmess.NewTimedUserValidator(protocol.DefaultIDHash)
userValidator.Add(user)
server := NewServerSession(userValidator)
actualRequest, err := server.DecodeRequestHeader(buffer)
assert.Error(err).IsNil()
assert.Byte(expectedRequest.Version).Equals(actualRequest.Version)
assert.Byte(byte(expectedRequest.Command)).Equals(byte(actualRequest.Command))
assert.Byte(byte(expectedRequest.Option)).Equals(byte(actualRequest.Option))
assert.Address(expectedRequest.Address).Equals(actualRequest.Address)
assert.Port(expectedRequest.Port).Equals(actualRequest.Port)
assert.Byte(byte(expectedRequest.Security)).Equals(byte(actualRequest.Security))
}
示例15: TestRequestSerialization
func TestRequestSerialization(t *testing.T) {
assert := assert.On(t)
user := protocol.NewUser(
protocol.UserLevelUntrusted,
"[email protected]")
user.Account = &vmess.Account{
ID: protocol.NewID(uuid.New()),
AlterIDs: nil,
}
expectedRequest := &protocol.RequestHeader{
Version: 1,
User: user,
Command: protocol.RequestCommandTCP,
Option: protocol.RequestOption(0),
Address: v2net.DomainAddress("www.v2ray.com"),
Port: v2net.Port(443),
}
buffer := alloc.NewBuffer().Clear()
client := NewClientSession(protocol.DefaultIDHash)
client.EncodeRequestHeader(expectedRequest, buffer)
userValidator := vmess.NewTimedUserValidator(protocol.DefaultIDHash)
userValidator.Add(user)
server := NewServerSession(userValidator)
actualRequest, err := server.DecodeRequestHeader(buffer)
assert.Error(err).IsNil()
assert.Byte(expectedRequest.Version).Equals(actualRequest.Version)
assert.Byte(byte(expectedRequest.Command)).Equals(byte(actualRequest.Command))
assert.Byte(byte(expectedRequest.Option)).Equals(byte(actualRequest.Option))
assert.Address(expectedRequest.Address).Equals(actualRequest.Address)
assert.Port(expectedRequest.Port).Equals(actualRequest.Port)
}