diff --git a/proxy/vmess/validator.go b/proxy/vmess/validator.go index 65e007b8d..76bae8d36 100644 --- a/proxy/vmess/validator.go +++ b/proxy/vmess/validator.go @@ -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 diff --git a/proxy/vmess/validator_test.go b/proxy/vmess/validator_test.go index abb50968a..c76b270cc 100644 --- a/proxy/vmess/validator_test.go +++ b/proxy/vmess/validator_test.go @@ -2,7 +2,6 @@ package vmess_test import ( "testing" - "time" "github.com/v2fly/v2ray-core/v5/common" "github.com/v2fly/v2ray-core/v5/common/protocol" @@ -33,8 +32,8 @@ func TestUserValidator(t *testing.T) { 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 +45,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 +60,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)