Skip to content

Commit 72a989a

Browse files
fix(test): Fix race condition in RoundtripTest.shouldOptionsIat
closes auth0#28
1 parent e040916 commit 72a989a

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/test/java/com/auth0/jwt/RoundtripTest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,17 @@ public void shouldBoolean() throws Exception {
9797
@Test
9898
public void shouldOptionsIat() throws Exception {
9999
HashMap<String, Object> claims = new HashMap<String, Object>();
100-
String token = signer.sign(claims,
101-
new JWTSigner.Options().setIssuedAt(true));
100+
long before = System.currentTimeMillis();
101+
String token = signer.sign(claims, new JWTSigner.Options().setIssuedAt(true));
102+
long after = System.currentTimeMillis();
102103
Map<String, Object> decoded = verifier.verify(token);
104+
103105
assertEquals(decoded.size(), 1);
104106
long iat = ((Number) decoded.get("iat")).longValue();
105-
assertTrue(iat >= System.currentTimeMillis() / 1000l);
106-
assertTrue(iat < System.currentTimeMillis() / 1000l + 10);
107+
assertTrue(iat >= before / 1000l);
108+
assertTrue(iat <= after / 1000l);
107109
}
108-
110+
109111
@Test
110112
public void shouldOptionsTimestamps() throws Exception {
111113
HashMap<String, Object> claims = new HashMap<String, Object>();

0 commit comments

Comments
 (0)