2016-07-23 11:17:51 +00:00
|
|
|
package encoding_test
|
2016-02-27 21:37:14 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2016-08-20 18:55:45 +00:00
|
|
|
"v2ray.com/core/common/alloc"
|
2016-10-17 12:35:13 +00:00
|
|
|
"v2ray.com/core/common/loader"
|
2016-08-20 18:55:45 +00:00
|
|
|
v2net "v2ray.com/core/common/net"
|
|
|
|
"v2ray.com/core/common/protocol"
|
|
|
|
"v2ray.com/core/common/uuid"
|
|
|
|
"v2ray.com/core/proxy/vmess"
|
|
|
|
. "v2ray.com/core/proxy/vmess/encoding"
|
|
|
|
"v2ray.com/core/testing/assert"
|
2016-02-27 21:37:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestRequestSerialization(t *testing.T) {
|
2016-05-24 19:55:46 +00:00
|
|
|
assert := assert.On(t)
|
2016-02-27 21:37:14 +00:00
|
|
|
|
2016-09-17 22:41:21 +00:00
|
|
|
user := &protocol.User{
|
|
|
|
Level: 0,
|
|
|
|
Email: "test@v2ray.com",
|
|
|
|
}
|
2016-10-12 16:43:55 +00:00
|
|
|
account := &vmess.Account{
|
2016-09-17 22:41:21 +00:00
|
|
|
Id: uuid.New().String(),
|
|
|
|
AlterId: 0,
|
2016-07-25 15:36:24 +00:00
|
|
|
}
|
2016-10-17 12:35:13 +00:00
|
|
|
user.Account = loader.NewTypedSettings(account)
|
2016-02-27 21:37:14 +00:00
|
|
|
|
|
|
|
expectedRequest := &protocol.RequestHeader{
|
|
|
|
Version: 1,
|
|
|
|
User: user,
|
|
|
|
Command: protocol.RequestCommandTCP,
|
|
|
|
Option: protocol.RequestOption(0),
|
|
|
|
Address: v2net.DomainAddress("www.v2ray.com"),
|
|
|
|
Port: v2net.Port(443),
|
|
|
|
}
|
|
|
|
|
2016-12-06 10:03:42 +00:00
|
|
|
buffer := alloc.NewBuffer()
|
2016-02-27 21:37:14 +00:00
|
|
|
client := NewClientSession(protocol.DefaultIDHash)
|
|
|
|
client.EncodeRequestHeader(expectedRequest, buffer)
|
|
|
|
|
2016-07-25 15:36:24 +00:00
|
|
|
userValidator := vmess.NewTimedUserValidator(protocol.DefaultIDHash)
|
2016-02-27 21:37:14 +00:00
|
|
|
userValidator.Add(user)
|
|
|
|
|
|
|
|
server := NewServerSession(userValidator)
|
|
|
|
actualRequest, err := server.DecodeRequestHeader(buffer)
|
|
|
|
assert.Error(err).IsNil()
|
|
|
|
|
|
|
|
assert.Byte(expectedRequest.Version).Equals(actualRequest.Version)
|
|
|
|
assert.Byte(byte(expectedRequest.Command)).Equals(byte(actualRequest.Command))
|
|
|
|
assert.Byte(byte(expectedRequest.Option)).Equals(byte(actualRequest.Option))
|
2016-05-24 13:29:08 +00:00
|
|
|
assert.Address(expectedRequest.Address).Equals(actualRequest.Address)
|
|
|
|
assert.Port(expectedRequest.Port).Equals(actualRequest.Port)
|
2016-02-27 21:37:14 +00:00
|
|
|
}
|