Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix minute/second bug

  • Loading branch information...
commit 10f0dccbedc78340753948fa14a1434360ba55e2 1 parent 8505705
Glen D Sanford authored
View
4 src/main/scala/com/twitter/joauth/Verifier.scala
@@ -75,8 +75,8 @@ extends Verifier {
def validateTimestampSecs(timestampSecs: Long): Boolean = {
val nowSecs = System.currentTimeMillis / 1000
- (maxClockFloatBehindMins < 0 || (timestampSecs >= nowSecs - maxClockFloatBehindMins)) &&
- (maxClockFloatAheadMins < 0 || (timestampSecs <= nowSecs + maxClockFloatAheadMins))
+ (maxClockFloatBehindMins < 0 || (timestampSecs >= nowSecs - maxClockFloatBehindSecs)) &&
+ (maxClockFloatAheadMins < 0 || (timestampSecs <= nowSecs + maxClockFloatAheadSecs))
}
def validateSignature(
View
10 src/test/scala/com/twitter/joauth/VerifierSpec.scala
@@ -21,9 +21,10 @@ class VerifierSpec extends Specification with Mockito {
val signer = mock[Signer]
val request = mock[OAuth1Request]
- // 10 minutes ago
val nowSecs = (new Date).getTime / 1000
+ // 10 minutes ago
val longAgoSecs = nowSecs - (10 * 60)
+ // 10 minutes fromNow
val farAheadSecs = nowSecs + (10 * 60)
val verify = new StandardVerifier(signer, 5, 5, checkNonce)
@@ -33,7 +34,12 @@ class VerifierSpec extends Specification with Mockito {
verify.validateTimestampSecs(longAgoSecs) must beFalse
}
"return true for timestamp that is new enough" in {
- verify.validateTimestampSecs((new Date).getTime / 1000) must beTrue
+ val fourMinutesAgo = nowSecs - (4 * 60)
+ verify.validateTimestampSecs(fourMinutesAgo) must beTrue
+ }
+ "return true for timestamp that is new enough" in {
+ val fourMinutesFromNow = nowSecs + (4 * 60)
+ verify.validateTimestampSecs(fourMinutesFromNow) must beTrue
}
"return false for timestamp that too new" in {
verify.validateTimestampSecs(farAheadSecs) must beFalse
Please sign in to comment.
Something went wrong with that request. Please try again.