v2ray-core/proxy/socks/protocol/udp_test.go

37 lines
905 B
Go
Raw Normal View History

2015-11-03 17:33:58 +00:00
package protocol
import (
"testing"
2016-08-20 18:55:45 +00:00
v2net "v2ray.com/core/common/net"
"v2ray.com/core/testing/assert"
2015-11-03 17:33:58 +00:00
)
2016-02-05 10:21:13 +00:00
func TestSingleByteUDPRequest(t *testing.T) {
2016-05-24 19:55:46 +00:00
assert := assert.On(t)
2015-11-03 17:33:58 +00:00
request, err := ReadUDPRequest(make([]byte, 1))
if request != nil {
t.Fail()
}
2016-11-19 13:38:13 +00:00
assert.Error(err).IsNotNil()
2015-11-03 17:33:58 +00:00
}
func TestDomainAddressRequest(t *testing.T) {
2016-05-24 19:55:46 +00:00
assert := assert.On(t)
2015-11-03 17:33:58 +00:00
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)
2016-05-24 19:55:46 +00:00
assert.Address(request.Address).EqualsString("v2ray.com")
2016-05-24 13:29:08 +00:00
assert.Port(request.Port).Equals(v2net.Port(80))
2016-12-06 10:03:42 +00:00
assert.String(request.Data.String()).Equals("Actual payload")
2015-11-03 17:33:58 +00:00
}