Merge pull request #360 from liquidm/fix_future_timestamps

make ServerTimeRejectionPolicy also reject timestamps AHEAD of server time
This commit is contained in:
fjy 2014-01-14 09:27:04 -08:00
commit cf018205be
2 changed files with 8 additions and 1 deletions

View File

@ -40,7 +40,12 @@ public class ServerTimeRejectionPolicyFactory implements RejectionPolicyFactory
@Override @Override
public boolean accept(long timestamp) 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 @Override

View File

@ -37,8 +37,10 @@ public class ServerTimeRejectionPolicyFactoryTest
DateTime now = new DateTime(); DateTime now = new DateTime();
DateTime past = now.minus(period).minus(1); DateTime past = now.minus(period).minus(1);
DateTime future = now.plus(period).plus(1);
Assert.assertTrue(rejectionPolicy.accept(now.getMillis())); Assert.assertTrue(rejectionPolicy.accept(now.getMillis()));
Assert.assertFalse(rejectionPolicy.accept(past.getMillis())); Assert.assertFalse(rejectionPolicy.accept(past.getMillis()));
Assert.assertFalse(rejectionPolicy.accept(future.getMillis()));
} }
} }