1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-01-02 23:47:07 -05:00
v2fly/proxy/socks/protocol/udp_test.go

37 lines
909 B
Go
Raw Normal View History

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