2015-11-03 12:33:58 -05:00
|
|
|
package protocol
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2015-12-16 17:53:38 -05:00
|
|
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
2015-12-02 09:27:18 -05:00
|
|
|
"github.com/v2ray/v2ray-core/testing/assert"
|
2015-11-03 12:33:58 -05:00
|
|
|
"github.com/v2ray/v2ray-core/transport"
|
|
|
|
)
|
|
|
|
|
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-06-27 02:53:35 -04:00
|
|
|
assert.Error(err).Equals(transport.ErrCorruptedPacket)
|
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"))
|
|
|
|
}
|