Skip to content

Commit

Permalink
Merge pull request #96 from Nirusu/decimal-timeclaim
Browse files Browse the repository at this point in the history
Add support for high-precision decimal TimeClaims
  • Loading branch information
DolphFlynn authored Jan 11, 2025
2 parents af8abc1 + 9e7366b commit 8c57c37
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.json.JSONException;
import org.json.JSONObject;

import java.math.BigDecimal;
import java.time.Instant;
import java.time.ZonedDateTime;
import java.time.format.DateTimeParseException;
Expand All @@ -34,8 +35,8 @@

public class TimeClaimFactory {

public static TimeClaim fromEpochSeconds(TimeClaimType type, String value, Long epochSeconds) {
return new TimeClaim(type, value, dateTimeValue(epochSeconds));
public static TimeClaim fromEpochSeconds(TimeClaimType type, String value) {
return new TimeClaim(type, value, dateTimeValue(value));
}

public static TimeClaim fromIsoDateTime(TimeClaimType type, String value) {
Expand All @@ -56,10 +57,8 @@ static List<TimeClaim> fromPayloadJson(String payloadJson) {
.map(type -> {
String value = jsonObject.get(type.name).toString();

if (value.matches("\\d+")) {
Long epochSeconds = numberValue(jsonObject, type.name);

return fromEpochSeconds(type, value, epochSeconds);
if (value.matches("\\d+(.\\d+)?")) {
return fromEpochSeconds(type, value);
} else {
return fromIsoDateTime(type, value);
}
Expand All @@ -76,22 +75,31 @@ private static Optional<JSONObject> parsePayload(String payloadJson) {
}
}

private static Long numberValue(JSONObject jsonObject, String name) {
try {
return jsonObject.getLong(name);
} catch (JSONException e) {
private static ZonedDateTime dateTimeValue(String numberValue) {
if (numberValue == null) {
return null;
}
}

private static ZonedDateTime dateTimeValue(Long numberValue) {
if (numberValue == null || numberValue < 0) {
try {
// Try to parse string time value as BigDecimal to keep the floating point precision
BigDecimal epochSecondsDecimal = new BigDecimal(numberValue);

// Truncate decimal part of the value to get the seconds
long seconds = epochSecondsDecimal.longValue();
if (seconds < 0) {
return null;
}

// Get decimal part as nanoseconds
long nanoseconds = epochSecondsDecimal.subtract(new BigDecimal(seconds))
.movePointRight(9)
.longValue();

Instant instant = Instant.ofEpochSecond(seconds, nanoseconds);
return ZonedDateTime.ofInstant(instant, UTC);
} catch (NumberFormatException | ArithmeticException e) {
return null;
}

Instant instant = Instant.ofEpochSecond(numberValue);

return ZonedDateTime.ofInstant(instant, UTC);
}

private static ZonedDateTime parseDateTime(String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ void givenJWSWithNoTimeClaims_thenTimeClaimsIsEmpty() throws ParseException {
void givenJWSWithExpTimeClaims_thenTimeClaimsCorrect(String data) throws ParseException {
JWS jws = JWSFactory.parse(data);

assertThat(jws.claims().timeClaims()).containsExactly(TimeClaimFactory.fromEpochSeconds(EXPIRATION_TIME, "1716239022", 1716239022L));
assertThat(jws.claims().timeClaims()).containsExactly(TimeClaimFactory.fromEpochSeconds(EXPIRATION_TIME, "1716239022"));
}

private static Stream<String> jwsWithValidExpValues() {
return Stream.of(
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiZXhwIjoyMzE2MjM5MDIyfQ.nmCDcUHT-yLgrRG1LKMH9E2FQs2xWcB8CncxoqKdQEQ",
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiZXhwIjoiMjMxNjIzOTAyMiJ9.kDOLZJTcFVwrSVSDeFK31EIx7Q4e4Ya33iNCk4QZ10c",
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiZXhwIjoyMzE2MjM5MDIyLjEyMzQ1Nn0.H1-2jQa-px7ubm0npoG1-cWzDWNOh2IDQlsz4-Wwcyk",
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWI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9O-U4t_RwV9wBz588gqB99M"
);
}

Expand All @@ -90,7 +93,9 @@ void givenJWSWithExpTimeClaims_whenExpiryDateInvalid_thenTimeClaimNotValid(Strin
private static Stream<String> jwsWithExpValuesInThePast() {
return Stream.of(
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJleHAiOjE1MTYyMzkwMjJ9.mVGXFv3OuwtuZPsdaf_oGUYm2uOH-T-JRTDQE1c10q0",
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJleHAiOjB9.eVVhRMapPD77WuMWIHKBqYw0cjJHC49On-mHEuonYjk"
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJleHAiOjE1MTYyMzkwMjIuMTIzNDU2fQ.Nx2K7VSNCFGSOzLvB4cKyqUJfnYJUekVx3kvctsLYZk",
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJleHAiOjB9.eVVhRMapPD77WuMWIHKBqYw0cjJHC49On-mHEuonYjk",
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJleHAiOjB9.z4UM0Z_ZONsVCh4Cw9NyNKy3GN9PmBWCvVo6Dw12CiY"
);
}

Expand All @@ -108,12 +113,22 @@ void givenJWSWithExpTimeClaims_whenExpiryDateIsInThePast_thenTimeClaimNotValid(S
@ParameterizedTest
@ValueSource(strings = {
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwibmJmIjoxNzE2MjM5MDIyfQ.mZ_wGwRA0BBp_m6LJOPOBfwMosKrhTf9DbnKZYTzBzg",
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwibmJmIjoiMTcxNjIzOTAyMiJ9.JD7t6jE6sOzuaFi5Lj5e3RhnoRDDWW9QHv_U3bFgEKM"
})
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwibmJmIjoiMTcxNjIzOTAyMiJ9.JD7t6jE6sOzuaFi5Lj5e3RhnoRDDWW9QHv_U3bFgEKM"})
void givenJWSWithNbfTimeClaims_thenTimeClaimsCorrect(String data) throws ParseException {
JWS jws = JWSFactory.parse(data);

assertThat(jws.claims().timeClaims()).containsExactly(TimeClaimFactory.fromEpochSeconds(NOT_BEFORE_TIME, "1716239022", 1716239022L));
assertThat(jws.claims().timeClaims()).containsExactly(TimeClaimFactory.fromEpochSeconds(NOT_BEFORE_TIME, "1716239022"));
}

@ParameterizedTest
@ValueSource(strings = {
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwibmJmIjoxNzE2MjM5MDIyLjEyMzQ1Nn0.22WbREJsZuvAaRiGNXSENHg0JC81QL5nUxKpWOtVSR8",
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwibmJmIjoiMTcxNjIzOTAyMi4xMjM0NTYifQ.B_WI9vnukq93HeQ1xeWqQms4zZU0BAWL9irQdhoGfh0"
})
void givenJWSWithNbfTimeClaimsMicroseconds_thenTimeClaimsCorrect(String data) throws ParseException {
JWS jws = JWSFactory.parse(data);

assertThat(jws.claims().timeClaims()).containsExactly(TimeClaimFactory.fromEpochSeconds(NOT_BEFORE_TIME, "1716239022.123456"));
}

private static Stream<String> jwsWithValidNbfValues() {
Expand All @@ -123,6 +138,8 @@ private static Stream<String> jwsWithValidNbfValues() {
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJuYmYiOjE1MTYyMzkwMjJ9.1OhNEYnVM64dytXGZ1kj_Z3fV73xGFxWyba52S5r7wc",
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJuYmYiOjB9.AqIAHlKSdpcDp7mD6sWsfKCQxI2hyJYsI7Y4Dh6N6pI",
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJuYmYiOjE3MjIxNjc0Nzd9.2almhOGrigs8lXH9DLKBkkUCS6r5j7zpJXYsXJN39d4",
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJuYmYiOjE3MjIxNjc0NzcuMTIzNDU2fQ.Jhjav96AdbK5WDM3yyd48nPZgXs5bU1LNypxc0EiY8g",
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJuYmYiOiIxNzIyMTY3NDc3LjEyMzQ1NiJ9.AjRS20zLSXrDUW9YuD7xly_iRkRJb9UyKwd72MpNKf8",
"eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwibmJmIjoiMjAyNC0wNS0yMFQyMjowMzo0MiswMTowMCJ9."
);
}
Expand All @@ -142,7 +159,8 @@ private static Stream<String> jwsWithInvalidNbfValues() {
return Stream.of(
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwibmJmIjoiemVvbGl0ZSJ9.kmx4FteQrcATfc2Zx47WypsqrIC-e1IM4opeLJxLyrI",
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwibmJmIjpudWxsfQ.Nyai4iIAzjR5OcUwaE8xQYbArYuBIzbKxaJDnvu1J_I",
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwibmJmIjotMTIzNDV9.rlnrK7unNEaaghPFhNQnDp1GRbCU0rGORO2yDf5YIZk"
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwibmJmIjotMTIzNDV9.rlnrK7unNEaaghPFhNQnDp1GRbCU0rGORO2yDf5YIZk",
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwibmJmIjotMTIzNDUuNjc4OX0.bXoLasbuZk8NZNyYj3HCNIIvXGUb96ffvfveXwHIX4g"
);
}

Expand All @@ -159,7 +177,8 @@ void givenJWSWithNbfTimeClaims_whenNotBeforeDateInvalid_thenTimeClaimNotValid(St
private static Stream<String> jwsWithFutureNbfValues() {
return Stream.of(
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJuYmYiOjIzMjIxNjc0Nzd9.cMocfo6ghvuYBqDwZ9GBdfbCnMLsUcZe2GZRuaah0-c",
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJuYmYiOjE4MjIxNjc0Nzd9._m-Rhio9DLcVRfWo7S-KIvlTk29QuDgal-tqreN4y4E"
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJuYmYiOjE4MjIxNjc0Nzd9._m-Rhio9DLcVRfWo7S-KIvlTk29QuDgal-tqreN4y4E",
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJuYmYiOjIzMjIxNjc0NzcuMTIzNDU2fQ.VC7D0b27ETWQMuxbWsLdmHfPvIbwadH5qQHCoP7o_g0"
);
}

Expand All @@ -186,7 +205,22 @@ private static Stream<String> jwsWithValidIatValues() {
void givenJWSWithIatTimeClaims_thenTimeClaimsCorrect(String data) throws ParseException {
JWS jws = JWSFactory.parse(data);

assertThat(jws.claims().timeClaims()).containsExactly(TimeClaimFactory.fromEpochSeconds(ISSUED_AT_TIME, "1716239022", 1716239022L));
assertThat(jws.claims().timeClaims()).containsExactly(TimeClaimFactory.fromEpochSeconds(ISSUED_AT_TIME, "1716239022"));
}

private static Stream<String> jwsWithValidIatValuesMicroseconds() {
return Stream.of(
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJpYXQiOjE3MTYyMzkwMjIuMTIzNDU2fQ.UinUyun2D9gvOzWrY4cUfSwxB7RhisK3et9x-9PyDC4",
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJpYXQiOiIxNzE2MjM5MDIyLjEyMzQ1NiJ9.qNgTvt_NlseJDTQ06s3JIAh2NPSwzrUQ8VM3-iJ94Eg"
);
}

@ParameterizedTest
@MethodSource("jwsWithValidIatValuesMicroseconds")
void givenJWSWithIatTimeClaimsMicroseconds_thenTimeClaimsCorrect(String data) throws ParseException {
JWS jws = JWSFactory.parse(data);

assertThat(jws.claims().timeClaims()).containsExactly(TimeClaimFactory.fromEpochSeconds(ISSUED_AT_TIME, "1716239022.123456"));
}

private static Stream<String> jwsWithValidIatDatesInThePast() {
Expand All @@ -196,6 +230,8 @@ private static Stream<String> jwsWithValidIatDatesInThePast() {
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVC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i-hImBCsHTs__K-0LU612y3EW92J1TbINlDGc-k",
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJpYXQiOi0xMjM0NX0.gVkVHyEasqw2NZ63un0T9Yd6bW8bmY9uMYndlptiQzQ");
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJpYXQiOi0xMjM0NX0.gVkVHyEasqw2NZ63un0T9Yd6bW8bmY9uMYndlptiQzQ",
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJpYXQiOi0xMjM0NS42Nzg5fQ.kWOjxuK9euJp7rcgG4WcaXuEwjk2goaVrIEdS_lmwnU"
);
}

@ParameterizedTest
Expand All @@ -232,7 +270,8 @@ void givenJWSWithIatTimeClaims_whenIssuedAtDateInvalid_thenTimeClaimNotValid(Str
private static Stream<String> jwsWithFutureIatDates() {
return Stream.of(
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJpYXQiOjIzMjIxNjc0Nzd9.3UYGoLpdXRhnlai81VFV_iWmW90xnCimcYverY1-Zk4",
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJpYXQiOjE4MjIxNjc0Nzd9._H-G7WjMbg8IVADVbz1Lsd7I_bGQZBYKPf8S2Q9vxf4"
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJpYXQiOjE4MjIxNjc0Nzd9._H-G7WjMbg8IVADVbz1Lsd7I_bGQZBYKPf8S2Q9vxf4",
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJpYXQiOjIzMjIxNjc0NzcuMTIzNDU2fQ.7ue0C6Wo06Hb_HoVHnQ7eMUPkQFN_Q6YyyNzqVQ8Qq8"
);
}
@ParameterizedTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TimeClaimTest {
@EnumSource(TimeClaimType.class)
@ParameterizedTest
void invalidEpochTime(TimeClaimType type) {
TimeClaim timeClaim = TimeClaimFactory.fromEpochSeconds(type, "-1", -1L);
TimeClaim timeClaim = TimeClaimFactory.fromEpochSeconds(type, "-1");

assertThat(timeClaim.type()).isEqualTo(type);
assertThat(timeClaim.value()).isEqualTo("-1");
Expand Down Expand Up @@ -92,7 +92,7 @@ static Stream<Arguments> epochDateTimes() {
void testIssuedAtTimeClaimsForEpochTimes(long epochDateTime, String expectedDateTimeString) {
String epochDateTimeValue = Long.toString(epochDateTime);

TimeClaim timeClaim = TimeClaimFactory.fromEpochSeconds(ISSUED_AT_TIME, epochDateTimeValue, epochDateTime);
TimeClaim timeClaim = TimeClaimFactory.fromEpochSeconds(ISSUED_AT_TIME, epochDateTimeValue);

assertThat(timeClaim.type()).isEqualTo(ISSUED_AT_TIME);
assertThat(timeClaim.value()).isEqualTo(epochDateTimeValue);
Expand All @@ -107,7 +107,7 @@ void testExpiredDatesInThePastAreInvalid() {
long epochSeconds = Instant.now().getEpochSecond() - 1;
String epochSecondsValue = Long.toString(epochSeconds);

TimeClaim timeClaim = TimeClaimFactory.fromEpochSeconds(EXPIRATION_TIME, epochSecondsValue, epochSeconds);
TimeClaim timeClaim = TimeClaimFactory.fromEpochSeconds(EXPIRATION_TIME, epochSecondsValue);

assertThat(timeClaim.type()).isEqualTo(EXPIRATION_TIME);
assertThat(timeClaim.value()).isEqualTo(epochSecondsValue);
Expand All @@ -122,7 +122,7 @@ void testExpiredDatesInTheFutureAreValid() {
long epochSeconds = Instant.now().getEpochSecond() + 5;
String epochSecondsValue = Long.toString(epochSeconds);

TimeClaim timeClaim = TimeClaimFactory.fromEpochSeconds(EXPIRATION_TIME, epochSecondsValue, epochSeconds);
TimeClaim timeClaim = TimeClaimFactory.fromEpochSeconds(EXPIRATION_TIME, epochSecondsValue);

assertThat(timeClaim.type()).isEqualTo(EXPIRATION_TIME);
assertThat(timeClaim.value()).isEqualTo(epochSecondsValue);
Expand All @@ -137,7 +137,7 @@ void testIssuedAtDatesInThePastAreValid() {
long epochSeconds = Instant.now().getEpochSecond() - 1;
String epochSecondsValue = Long.toString(epochSeconds);

TimeClaim timeClaim = TimeClaimFactory.fromEpochSeconds(ISSUED_AT_TIME, epochSecondsValue, epochSeconds);
TimeClaim timeClaim = TimeClaimFactory.fromEpochSeconds(ISSUED_AT_TIME, epochSecondsValue);

assertThat(timeClaim.type()).isEqualTo(ISSUED_AT_TIME);
assertThat(timeClaim.value()).isEqualTo(epochSecondsValue);
Expand All @@ -152,7 +152,7 @@ void testIssuedAtDatesInTheFutureAreInvalid() {
long epochSeconds = Instant.now().getEpochSecond() + 5;
String epochSecondsValue = Long.toString(epochSeconds);

TimeClaim timeClaim = TimeClaimFactory.fromEpochSeconds(ISSUED_AT_TIME, epochSecondsValue, epochSeconds);
TimeClaim timeClaim = TimeClaimFactory.fromEpochSeconds(ISSUED_AT_TIME, epochSecondsValue);

assertThat(timeClaim.type()).isEqualTo(ISSUED_AT_TIME);
assertThat(timeClaim.value()).isEqualTo(epochSecondsValue);
Expand All @@ -166,7 +166,7 @@ void testNotBeforeDatesInThePastAreValid() {
long epochSeconds = Instant.now().getEpochSecond() - 1;
String epochSecondsValue = Long.toString(epochSeconds);

TimeClaim timeClaim = TimeClaimFactory.fromEpochSeconds(NOT_BEFORE_TIME, epochSecondsValue, epochSeconds);
TimeClaim timeClaim = TimeClaimFactory.fromEpochSeconds(NOT_BEFORE_TIME, epochSecondsValue);

assertThat(timeClaim.type()).isEqualTo(NOT_BEFORE_TIME);
assertThat(timeClaim.value()).isEqualTo(epochSecondsValue);
Expand All @@ -181,7 +181,7 @@ void testNotBeforeDatesInTheFutureAreInvalid() {
long epochSeconds = Instant.now().getEpochSecond() + 5;
String epochSecondsValue = Long.toString(epochSeconds);

TimeClaim timeClaim = TimeClaimFactory.fromEpochSeconds(NOT_BEFORE_TIME, epochSecondsValue, epochSeconds);
TimeClaim timeClaim = TimeClaimFactory.fromEpochSeconds(NOT_BEFORE_TIME, epochSecondsValue);

assertThat(timeClaim.type()).isEqualTo(NOT_BEFORE_TIME);
assertThat(timeClaim.value()).isEqualTo(epochSecondsValue);
Expand Down
Loading

0 comments on commit 8c57c37

Please sign in to comment.