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/protocol"
|
|
|
|
. "v2ray.com/core/proxy/socks"
|
|
|
|
"v2ray.com/core/testing/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestUDPEncoding(t *testing.T) {
|
|
|
|
assert := assert.On(t)
|
|
|
|
|
|
|
|
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,
|
|
|
|
}
|
2017-04-21 08:51:09 -04:00
|
|
|
writer := buf.NewSequentialWriter(NewUDPWriter(request, b))
|
2017-01-08 10:31:28 -05:00
|
|
|
|
|
|
|
content := []byte{'a'}
|
|
|
|
payload := buf.New()
|
|
|
|
payload.Append(content)
|
2017-04-15 15:07:23 -04:00
|
|
|
assert.Error(writer.Write(buf.NewMultiBufferValue(payload))).IsNil()
|
2017-01-08 10:31:28 -05:00
|
|
|
|
|
|
|
reader := NewUDPReader(b)
|
|
|
|
|
|
|
|
decodedPayload, err := reader.Read()
|
|
|
|
assert.Error(err).IsNil()
|
2017-04-15 15:07:23 -04:00
|
|
|
assert.Bytes(decodedPayload[0].Bytes()).Equals(content)
|
2017-01-08 10:31:28 -05:00
|
|
|
}
|