Skip to content

Commit

Permalink
jwtk#235 Replace 'Date' with 'Instant' in JwtParserTest
Browse files Browse the repository at this point in the history
Replaced all instances of 'Date' with 'Instant' in JwtParserTest to more accurately reflect variable usage. Also added a TODO in JwtDateConverter.java to clarify the handling of epochMillis vs epochSeconds.
  • Loading branch information
pveeckhout committed Dec 27, 2023
1 parent 0921e29 commit 54f3a19
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static Instant toInstant(Object v) {
} else if (v instanceof Instant) {
return (Instant) v;
} else if (v instanceof Number) {
//assume millis:
// TODO millis are assume or expected but instant is in json as epochSeconds NOT epochMillis
long millis = ((Number) v).longValue();
return Instant.ofEpochMilli(millis);
} else if (v instanceof String) {
Expand Down
12 changes: 6 additions & 6 deletions impl/src/test/groovy/io/jsonwebtoken/JwtParserTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -1460,22 +1460,22 @@ class JwtParserTest {
}

@Test
void testParseRequireCustomDate_Success() {
void testParseRequireCustomInstant_Success() {

def aDate = Instant.now()
def anInstant = Instant.now()

byte[] key = randomKey()

String compact = Jwts.builder().signWith(SignatureAlgorithm.HS256, key).
claim("aDate", aDate).
claim("anInstant", anInstant).
compact()

Jwt<Header, Claims> jwt = Jwts.parser().setSigningKey(key).
require("aDate", aDate).
require("anInstant", anInstant).
build().
parseSignedClaims(compact)

assertEquals jwt.getPayload().get("aDate", Instant.class), aDate
assertEquals jwt.getPayload().get("anInstant", Instant.class), anInstant
}

@Test
Expand Down Expand Up @@ -1505,7 +1505,7 @@ class JwtParserTest {
}

@Test
void testParseRequireCustomDate_Incorrect_Fail() {
void testParseRequireCustomInstant_Incorrect_Fail() {

def goodInstant = Instant.now()
def badInstant = Instant.now().minusMillis(10000)
Expand Down

0 comments on commit 54f3a19

Please sign in to comment.