1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-03 16:57:38 -05:00
v2fly/proxy/vmess/encoding/encoding_test.go

51 lines
1.5 KiB
Go
Raw Normal View History

2016-07-23 07:17:51 -04:00
package encoding_test
2016-02-27 16:37:14 -05:00
import (
"testing"
"github.com/v2ray/v2ray-core/common/alloc"
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/common/protocol"
"github.com/v2ray/v2ray-core/common/uuid"
2016-07-23 07:17:51 -04:00
. "github.com/v2ray/v2ray-core/proxy/vmess/encoding"
2016-02-27 16:37:14 -05:00
"github.com/v2ray/v2ray-core/testing/assert"
)
func TestRequestSerialization(t *testing.T) {
2016-05-24 15:55:46 -04:00
assert := assert.On(t)
2016-02-27 16:37:14 -05:00
user := protocol.NewUser(
2016-05-28 07:44:11 -04:00
&protocol.VMessAccount{
ID: protocol.NewID(uuid.New()),
AlterIDs: nil,
},
2016-02-27 16:37:14 -05:00
protocol.UserLevelUntrusted,
"test@v2ray.com")
expectedRequest := &protocol.RequestHeader{
Version: 1,
User: user,
Command: protocol.RequestCommandTCP,
Option: protocol.RequestOption(0),
Address: v2net.DomainAddress("www.v2ray.com"),
Port: v2net.Port(443),
}
buffer := alloc.NewBuffer().Clear()
client := NewClientSession(protocol.DefaultIDHash)
client.EncodeRequestHeader(expectedRequest, buffer)
userValidator := protocol.NewTimedUserValidator(protocol.DefaultIDHash)
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 09:29:08 -04:00
assert.Address(expectedRequest.Address).Equals(actualRequest.Address)
assert.Port(expectedRequest.Port).Equals(actualRequest.Port)
2016-02-27 16:37:14 -05:00
}