2016-07-23 07:17:51 -04:00
|
|
|
package encoding_test
|
2016-02-26 18:05:53 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-01-31 14:57:01 -05:00
|
|
|
"github.com/google/go-cmp/cmp"
|
2021-12-06 08:22:11 -05:00
|
|
|
"github.com/stretchr/testify/assert"
|
2019-01-31 14:57:01 -05:00
|
|
|
|
2022-01-02 10:16:23 -05:00
|
|
|
"github.com/v2fly/v2ray-core/v5/common"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/common/buf"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/common/protocol"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/common/uuid"
|
|
|
|
. "github.com/v2fly/v2ray-core/v5/proxy/vmess/encoding"
|
2016-02-26 18:05:53 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSwitchAccount(t *testing.T) {
|
|
|
|
sa := &protocol.CommandSwitchAccount{
|
|
|
|
Port: 1234,
|
|
|
|
ID: uuid.New(),
|
|
|
|
AlterIds: 1024,
|
|
|
|
Level: 128,
|
|
|
|
ValidMin: 16,
|
|
|
|
}
|
|
|
|
|
2016-12-09 06:08:25 -05:00
|
|
|
buffer := buf.New()
|
2019-01-31 14:57:01 -05:00
|
|
|
common.Must(MarshalCommand(sa, buffer))
|
2016-02-26 18:05:53 -05:00
|
|
|
|
2016-12-05 15:33:24 -05:00
|
|
|
cmd, err := UnmarshalCommand(1, buffer.BytesFrom(2))
|
2019-01-31 14:57:01 -05:00
|
|
|
common.Must(err)
|
2016-02-26 18:05:53 -05:00
|
|
|
|
|
|
|
sa2, ok := cmd.(*protocol.CommandSwitchAccount)
|
2019-01-31 14:57:01 -05:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("failed to convert command to CommandSwitchAccount")
|
|
|
|
}
|
|
|
|
if r := cmp.Diff(sa2, sa); r != "" {
|
|
|
|
t.Error(r)
|
|
|
|
}
|
2016-02-26 18:05:53 -05:00
|
|
|
}
|
2021-12-05 14:15:38 -05:00
|
|
|
|
|
|
|
func TestSwitchAccountBugOffByOne(t *testing.T) {
|
|
|
|
sa := &protocol.CommandSwitchAccount{
|
|
|
|
Port: 1234,
|
|
|
|
ID: uuid.New(),
|
|
|
|
AlterIds: 1024,
|
|
|
|
Level: 128,
|
|
|
|
ValidMin: 16,
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer := buf.New()
|
|
|
|
csaf := CommandSwitchAccountFactory{}
|
|
|
|
common.Must(csaf.Marshal(sa, buffer))
|
|
|
|
|
|
|
|
Payload := buffer.Bytes()
|
|
|
|
|
|
|
|
cmd, err := csaf.Unmarshal(Payload[:len(Payload)-1])
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Nil(t, cmd)
|
|
|
|
}
|