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,7 +44,12 @@ func TestUDPEncoding(t *testing.T) {
|
||||
func TestTCPRequest(t *testing.T) {
|
||||
assert := assert.On(t)
|
||||
|
||||
request := &protocol.RequestHeader{
|
||||
cases := []struct {
|
||||
request *protocol.RequestHeader
|
||||
payload []byte
|
||||
}{
|
||||
{
|
||||
request: &protocol.RequestHeader{
|
||||
Version: Version,
|
||||
Command: protocol.RequestCommandTCP,
|
||||
Address: v2net.LocalHostIP,
|
||||
@ -57,16 +62,57 @@ func TestTCPRequest(t *testing.T) {
|
||||
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)
|
||||
data.AppendSupplier(serial.WriteString("test string"))
|
||||
runTest := func(request *protocol.RequestHeader, payload []byte) {
|
||||
data := buf.New()
|
||||
defer data.Release()
|
||||
data.Append(payload)
|
||||
|
||||
cache := buf.New()
|
||||
defer cache.Release()
|
||||
|
||||
writer, err := WriteTCPRequest(request, cache)
|
||||
assert.Error(err).IsNil()
|
||||
|
||||
writer.Write(buf.NewMultiBufferValue(data))
|
||||
assert.Error(writer.Write(buf.NewMultiBufferValue(data))).IsNil()
|
||||
|
||||
decodedRequest, reader, err := ReadTCPSession(request.User, cache)
|
||||
assert.Error(err).IsNil()
|
||||
@ -75,7 +121,13 @@ func TestTCPRequest(t *testing.T) {
|
||||
|
||||
decodedData, err := reader.Read()
|
||||
assert.Error(err).IsNil()
|
||||
assert.String(decodedData[0].String()).Equals("test string")
|
||||
assert.String(decodedData[0].String()).Equals(string(payload))
|
||||
}
|
||||
|
||||
for _, test := range cases {
|
||||
runTest(test.request, test.payload)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestUDPReaderWriter(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user