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

39 lines
1.0 KiB
Go
Raw Normal View History

2015-11-03 17:33:58 +00:00
package protocol
import (
"testing"
2015-12-16 22:53:38 +00:00
v2net "github.com/v2ray/v2ray-core/common/net"
2015-12-02 16:27:55 +00:00
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert"
2015-11-03 17:33:58 +00:00
"github.com/v2ray/v2ray-core/transport"
)
2016-02-05 10:21:13 +00:00
func TestSingleByteUDPRequest(t *testing.T) {
v2testing.Current(t)
2015-11-03 17:33:58 +00:00
request, err := ReadUDPRequest(make([]byte, 1))
if request != nil {
t.Fail()
}
assert.Error(err).Equals(transport.ErrorCorruptedPacket)
2015-11-03 17:33:58 +00:00
}
func TestDomainAddressRequest(t *testing.T) {
v2testing.Current(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)
2015-12-16 22:53:38 +00:00
assert.String(request.Address).Equals("v2ray.com")
2016-05-24 13:29:08 +00:00
assert.Port(request.Port).Equals(v2net.Port(80))
2015-11-03 17:33:58 +00:00
assert.Bytes(request.Data.Value).Equals([]byte("Actual payload"))
}