提交 cf018205 编写于 作者: F fjy

Merge pull request #360 from liquidm/fix_future_timestamps

make ServerTimeRejectionPolicy also reject timestamps AHEAD of server time
......@@ -40,7 +40,12 @@ public class ServerTimeRejectionPolicyFactory implements RejectionPolicyFactory
@Override
public boolean accept(long timestamp)
{
return timestamp >= (System.currentTimeMillis() - windowMillis);
long now = System.currentTimeMillis();
boolean notTooOld = timestamp >= (now - windowMillis);
boolean notTooYoung = timestamp <= (now + windowMillis);
return notTooOld && notTooYoung;
}
@Override
......
......@@ -37,8 +37,10 @@ public class ServerTimeRejectionPolicyFactoryTest
DateTime now = new DateTime();
DateTime past = now.minus(period).minus(1);
DateTime future = now.plus(period).plus(1);
Assert.assertTrue(rejectionPolicy.accept(now.getMillis()));
Assert.assertFalse(rejectionPolicy.accept(past.getMillis()));
Assert.assertFalse(rejectionPolicy.accept(future.getMillis()));
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册