mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-30 09:18:34 +00:00
Fix some tests and format code (#830)
* Increase some tls test timeout * Fix TestUserValidator * Change all tests to VMessAEAD Old VMess MD5 tests will be rejected and fail in 2022 * Chore: auto format code
This commit is contained in:
parent
d5a7901601
commit
e93da4bd02
77 changed files with 137 additions and 234 deletions
|
@ -5,11 +5,10 @@ import (
|
|||
"encoding/binary"
|
||||
"hash/fnv"
|
||||
|
||||
"github.com/xtls/xray-core/common"
|
||||
|
||||
"github.com/xtls/xray-core/common/crypto"
|
||||
|
||||
"golang.org/x/crypto/sha3"
|
||||
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/crypto"
|
||||
)
|
||||
|
||||
// Authenticate authenticates a byte array using Fnv hash.
|
||||
|
|
|
@ -28,8 +28,7 @@ func TestRequestSerialization(t *testing.T) {
|
|||
}
|
||||
id := uuid.New()
|
||||
account := &vmess.Account{
|
||||
Id: id.String(),
|
||||
AlterId: 0,
|
||||
Id: id.String(),
|
||||
}
|
||||
user.Account = toAccount(account)
|
||||
|
||||
|
@ -78,8 +77,7 @@ func TestInvalidRequest(t *testing.T) {
|
|||
}
|
||||
id := uuid.New()
|
||||
account := &vmess.Account{
|
||||
Id: id.String(),
|
||||
AlterId: 0,
|
||||
Id: id.String(),
|
||||
}
|
||||
user.Account = toAccount(account)
|
||||
|
||||
|
@ -120,8 +118,7 @@ func TestMuxRequest(t *testing.T) {
|
|||
}
|
||||
id := uuid.New()
|
||||
account := &vmess.Account{
|
||||
Id: id.String(),
|
||||
AlterId: 0,
|
||||
Id: id.String(),
|
||||
}
|
||||
user.Account = toAccount(account)
|
||||
|
||||
|
|
|
@ -9,8 +9,6 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/xtls/xray-core/transport/internet/stat"
|
||||
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/buf"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
|
@ -28,6 +26,7 @@ import (
|
|||
"github.com/xtls/xray-core/features/routing"
|
||||
"github.com/xtls/xray-core/proxy/vmess"
|
||||
"github.com/xtls/xray-core/proxy/vmess/encoding"
|
||||
"github.com/xtls/xray-core/transport/internet/stat"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
|
@ -9,8 +9,6 @@ import (
|
|||
"hash/crc64"
|
||||
"time"
|
||||
|
||||
"github.com/xtls/xray-core/transport/internet/stat"
|
||||
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/buf"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
|
@ -27,6 +25,7 @@ import (
|
|||
"github.com/xtls/xray-core/proxy/vmess/encoding"
|
||||
"github.com/xtls/xray-core/transport"
|
||||
"github.com/xtls/xray-core/transport/internet"
|
||||
"github.com/xtls/xray-core/transport/internet/stat"
|
||||
)
|
||||
|
||||
// Handler is an outbound connection handler for VMess protocol.
|
||||
|
|
|
@ -71,6 +71,11 @@ func NewTimedUserValidator(hasher protocol.IDHash) *TimedUserValidator {
|
|||
return tuv
|
||||
}
|
||||
|
||||
// visible for testing
|
||||
func (v *TimedUserValidator) GetBaseTime() protocol.Timestamp {
|
||||
return v.baseTime
|
||||
}
|
||||
|
||||
func (v *TimedUserValidator) generateNewHashes(nowSec protocol.Timestamp, user *user) {
|
||||
var hashValue [16]byte
|
||||
genEndSec := nowSec + cacheDurationSec
|
||||
|
|
|
@ -2,7 +2,6 @@ package vmess_test
|
|||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/protocol"
|
||||
|
@ -26,15 +25,14 @@ func TestUserValidator(t *testing.T) {
|
|||
user := &protocol.MemoryUser{
|
||||
Email: "test",
|
||||
Account: toAccount(&Account{
|
||||
Id: id.String(),
|
||||
AlterId: 8,
|
||||
Id: id.String(),
|
||||
}),
|
||||
}
|
||||
common.Must(v.Add(user))
|
||||
|
||||
{
|
||||
testSmallLag := func(lag time.Duration) {
|
||||
ts := protocol.Timestamp(time.Now().Add(time.Second * lag).Unix())
|
||||
testSmallLag := func(lag int64) {
|
||||
ts := int64(v.GetBaseTime()) + lag + 240
|
||||
idHash := hasher(id.Bytes())
|
||||
common.Must2(serial.WriteUint64(idHash, uint64(ts)))
|
||||
userHash := idHash.Sum(nil)
|
||||
|
@ -46,7 +44,7 @@ func TestUserValidator(t *testing.T) {
|
|||
if euser.Email != user.Email {
|
||||
t.Error("unexpected user email: ", euser.Email, " want ", user.Email)
|
||||
}
|
||||
if ets != ts {
|
||||
if int64(ets) != ts {
|
||||
t.Error("unexpected timestamp: ", ets, " want ", ts)
|
||||
}
|
||||
}
|
||||
|
@ -61,8 +59,8 @@ func TestUserValidator(t *testing.T) {
|
|||
}
|
||||
|
||||
{
|
||||
testBigLag := func(lag time.Duration) {
|
||||
ts := protocol.Timestamp(time.Now().Add(time.Second * lag).Unix())
|
||||
testBigLag := func(lag int64) {
|
||||
ts := int64(v.GetBaseTime()) + lag + 240
|
||||
idHash := hasher(id.Bytes())
|
||||
common.Must2(serial.WriteUint64(idHash, uint64(ts)))
|
||||
userHash := idHash.Sum(nil)
|
||||
|
@ -99,8 +97,7 @@ func BenchmarkUserValidator(b *testing.B) {
|
|||
v.Add(&protocol.MemoryUser{
|
||||
Email: "test",
|
||||
Account: toAccount(&Account{
|
||||
Id: id.String(),
|
||||
AlterId: 16,
|
||||
Id: id.String(),
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue