mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-17 14:57:44 -05:00
Merge pull request #1352 from comwrg/more-cases-validator
add more test cases for `proxy/vmess/validator.go`
This commit is contained in:
commit
787f37363b
@ -36,26 +36,45 @@ func TestUserValidator(t *testing.T) {
|
|||||||
common.Must(v.Add(user))
|
common.Must(v.Add(user))
|
||||||
|
|
||||||
{
|
{
|
||||||
ts := protocol.Timestamp(time.Now().Unix())
|
testSmallLag := func(lag time.Duration) {
|
||||||
idHash := hasher(id.Bytes())
|
ts := protocol.Timestamp(time.Now().Add(time.Second * lag).Unix())
|
||||||
idHash.Write(ts.Bytes(nil))
|
idHash := hasher(id.Bytes())
|
||||||
userHash := idHash.Sum(nil)
|
idHash.Write(ts.Bytes(nil))
|
||||||
|
userHash := idHash.Sum(nil)
|
||||||
|
|
||||||
euser, ets, found := v.Get(userHash)
|
euser, ets, found := v.Get(userHash)
|
||||||
assert(found, IsTrue)
|
assert(found, IsTrue)
|
||||||
assert(euser.Email, Equals, user.Email)
|
assert(euser.Email, Equals, user.Email)
|
||||||
assert(int64(ets), Equals, int64(ts))
|
assert(int64(ets), Equals, int64(ts))
|
||||||
|
}
|
||||||
|
|
||||||
|
testSmallLag(0)
|
||||||
|
testSmallLag(40)
|
||||||
|
testSmallLag(-40)
|
||||||
|
testSmallLag(80)
|
||||||
|
testSmallLag(-80)
|
||||||
|
testSmallLag(120)
|
||||||
|
testSmallLag(-120)
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
ts := protocol.Timestamp(time.Now().Add(time.Second * 500).Unix())
|
testBigLag := func(lag time.Duration) {
|
||||||
idHash := hasher(id.Bytes())
|
ts := protocol.Timestamp(time.Now().Add(time.Second * lag).Unix())
|
||||||
idHash.Write(ts.Bytes(nil))
|
idHash := hasher(id.Bytes())
|
||||||
userHash := idHash.Sum(nil)
|
idHash.Write(ts.Bytes(nil))
|
||||||
|
userHash := idHash.Sum(nil)
|
||||||
|
|
||||||
euser, _, found := v.Get(userHash)
|
euser, _, found := v.Get(userHash)
|
||||||
assert(found, IsFalse)
|
assert(found, IsFalse)
|
||||||
assert(euser, IsNil)
|
assert(euser, IsNil)
|
||||||
|
}
|
||||||
|
|
||||||
|
testBigLag(121)
|
||||||
|
testBigLag(-121)
|
||||||
|
testBigLag(310)
|
||||||
|
testBigLag(-310)
|
||||||
|
testBigLag(500)
|
||||||
|
testBigLag(-500)
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(v.Remove(user.Email), IsTrue)
|
assert(v.Remove(user.Email), IsTrue)
|
||||||
|
Loading…
Reference in New Issue
Block a user