1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 10:08:15 -05:00
v2fly/proxy/socks/protocol_test.go

36 lines
810 B
Go
Raw Normal View History

2017-01-08 10:31:28 -05:00
package socks_test
import (
"testing"
"v2ray.com/core/common/buf"
"v2ray.com/core/common/net"
_ "v2ray.com/core/common/net/testing"
2017-01-08 10:31:28 -05:00
"v2ray.com/core/common/protocol"
. "v2ray.com/core/proxy/socks"
2017-10-24 10:15:35 -04:00
. "v2ray.com/ext/assert"
2017-01-08 10:31:28 -05:00
)
func TestUDPEncoding(t *testing.T) {
2017-10-24 10:15:35 -04:00
assert := With(t)
2017-01-08 10:31:28 -05:00
b := buf.New()
request := &protocol.RequestHeader{
Address: net.IPAddress([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6}),
Port: 1024,
}
2018-07-31 07:43:27 -04:00
writer := &buf.SequentialWriter{Writer: NewUDPWriter(request, b)}
2017-01-08 10:31:28 -05:00
content := []byte{'a'}
payload := buf.New()
2018-04-19 16:56:55 -04:00
payload.Write(content)
2017-11-09 16:33:15 -05:00
assert(writer.WriteMultiBuffer(buf.NewMultiBufferValue(payload)), IsNil)
2017-01-08 10:31:28 -05:00
reader := NewUDPReader(b)
2017-11-09 16:33:15 -05:00
decodedPayload, err := reader.ReadMultiBuffer()
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
assert(decodedPayload[0].Bytes(), Equals, content)
2017-01-08 10:31:28 -05:00
}