mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-21 17:46:58 -05:00
more test case on shadowsocks tcp
This commit is contained in:
parent
0157628ede
commit
f3c830c659
@ -44,38 +44,90 @@ func TestUDPEncoding(t *testing.T) {
|
|||||||
func TestTCPRequest(t *testing.T) {
|
func TestTCPRequest(t *testing.T) {
|
||||||
assert := assert.On(t)
|
assert := assert.On(t)
|
||||||
|
|
||||||
request := &protocol.RequestHeader{
|
cases := []struct {
|
||||||
Version: Version,
|
request *protocol.RequestHeader
|
||||||
Command: protocol.RequestCommandTCP,
|
payload []byte
|
||||||
Address: v2net.LocalHostIP,
|
}{
|
||||||
Option: RequestOptionOneTimeAuth,
|
{
|
||||||
Port: 1234,
|
request: &protocol.RequestHeader{
|
||||||
User: &protocol.User{
|
Version: Version,
|
||||||
Email: "love@v2ray.com",
|
Command: protocol.RequestCommandTCP,
|
||||||
Account: serial.ToTypedMessage(&Account{
|
Address: v2net.LocalHostIP,
|
||||||
Password: "tcp-password",
|
Option: RequestOptionOneTimeAuth,
|
||||||
CipherType: CipherType_CHACHA20,
|
Port: 1234,
|
||||||
}),
|
User: &protocol.User{
|
||||||
|
Email: "love@v2ray.com",
|
||||||
|
Account: serial.ToTypedMessage(&Account{
|
||||||
|
Password: "tcp-password",
|
||||||
|
CipherType: CipherType_CHACHA20,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
payload: []byte("test string"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
request: &protocol.RequestHeader{
|
||||||
|
Version: Version,
|
||||||
|
Command: protocol.RequestCommandTCP,
|
||||||
|
Address: v2net.LocalHostIPv6,
|
||||||
|
Option: RequestOptionOneTimeAuth,
|
||||||
|
Port: 1234,
|
||||||
|
User: &protocol.User{
|
||||||
|
Email: "love@v2ray.com",
|
||||||
|
Account: serial.ToTypedMessage(&Account{
|
||||||
|
Password: "password",
|
||||||
|
CipherType: CipherType_AES_256_CFB,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
payload: []byte("test string"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
request: &protocol.RequestHeader{
|
||||||
|
Version: Version,
|
||||||
|
Command: protocol.RequestCommandTCP,
|
||||||
|
Address: v2net.DomainAddress("v2ray.com"),
|
||||||
|
Option: RequestOptionOneTimeAuth,
|
||||||
|
Port: 1234,
|
||||||
|
User: &protocol.User{
|
||||||
|
Email: "love@v2ray.com",
|
||||||
|
Account: serial.ToTypedMessage(&Account{
|
||||||
|
Password: "password",
|
||||||
|
CipherType: CipherType_CHACHA20_IETF,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
payload: []byte("test string"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
data := buf.NewLocal(256)
|
runTest := func(request *protocol.RequestHeader, payload []byte) {
|
||||||
data.AppendSupplier(serial.WriteString("test string"))
|
data := buf.New()
|
||||||
cache := buf.New()
|
defer data.Release()
|
||||||
|
data.Append(payload)
|
||||||
|
|
||||||
writer, err := WriteTCPRequest(request, cache)
|
cache := buf.New()
|
||||||
assert.Error(err).IsNil()
|
defer cache.Release()
|
||||||
|
|
||||||
writer.Write(buf.NewMultiBufferValue(data))
|
writer, err := WriteTCPRequest(request, cache)
|
||||||
|
assert.Error(err).IsNil()
|
||||||
|
|
||||||
decodedRequest, reader, err := ReadTCPSession(request.User, cache)
|
assert.Error(writer.Write(buf.NewMultiBufferValue(data))).IsNil()
|
||||||
assert.Error(err).IsNil()
|
|
||||||
assert.Address(decodedRequest.Address).Equals(request.Address)
|
decodedRequest, reader, err := ReadTCPSession(request.User, cache)
|
||||||
assert.Port(decodedRequest.Port).Equals(request.Port)
|
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.String(decodedData[0].String()).Equals(string(payload))
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range cases {
|
||||||
|
runTest(test.request, test.payload)
|
||||||
|
}
|
||||||
|
|
||||||
decodedData, err := reader.Read()
|
|
||||||
assert.Error(err).IsNil()
|
|
||||||
assert.String(decodedData[0].String()).Equals("test string")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUDPReaderWriter(t *testing.T) {
|
func TestUDPReaderWriter(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user