1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-02-20 23:47:21 -05:00

Fix TestUserValidator

This commit is contained in:
yuhan6665 2021-11-12 20:58:32 -05:00 committed by Xiaokang Wang (Shelikhoo)
parent 81ef92c077
commit 9484390b18
2 changed files with 10 additions and 6 deletions

View File

@ -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

View File

@ -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)