1
0
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:
Victoria Raymond 2018-11-02 09:35:19 +01:00 committed by GitHub
commit 787f37363b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -36,7 +36,8 @@ func TestUserValidator(t *testing.T) {
common.Must(v.Add(user))
{
ts := protocol.Timestamp(time.Now().Unix())
testSmallLag := func(lag time.Duration) {
ts := protocol.Timestamp(time.Now().Add(time.Second * lag).Unix())
idHash := hasher(id.Bytes())
idHash.Write(ts.Bytes(nil))
userHash := idHash.Sum(nil)
@ -47,8 +48,18 @@ func TestUserValidator(t *testing.T) {
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) {
ts := protocol.Timestamp(time.Now().Add(time.Second * lag).Unix())
idHash := hasher(id.Bytes())
idHash.Write(ts.Bytes(nil))
userHash := idHash.Sum(nil)
@ -58,6 +69,14 @@ func TestUserValidator(t *testing.T) {
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), IsFalse)
}