Skip to content

OidcIdTokenValidator ensures clockSkew is positive number #6514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public OAuth2TokenValidatorResult validate(Jwt idToken) {
*/
public final void setClockSkew(Duration clockSkew) {
Assert.notNull(clockSkew, "clockSkew cannot be null");
Assert.isTrue(clockSkew.getSeconds() >= 0, "clockSkew must be >= 0");
this.clockSkew = clockSkew;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

/**
* @author Rob Winch
Expand All @@ -46,9 +47,11 @@ public class OidcIdTokenValidatorTests {
private Instant issuedAt = Instant.now();
private Instant expiresAt = this.issuedAt.plusSeconds(3600);
private Duration clockSkew = Duration.ofSeconds(60);
private OidcIdTokenValidator idTokenValidator;

@Before
public void setup() {
this.idTokenValidator = new OidcIdTokenValidator(this.registration.build());
this.headers.put("alg", JwsAlgorithms.RS256);
this.claims.put(IdTokenClaimNames.ISS, "https://issuer.example.com");
this.claims.put(IdTokenClaimNames.SUB, "rob");
Expand All @@ -60,6 +63,19 @@ public void validateWhenValidThenNoErrors() {
assertThat(this.validateIdToken()).isEmpty();
}


@Test
public void setClockSkewWhenNullThenThrowIllegalArgumentException(){
assertThatThrownBy(() -> this.idTokenValidator.setClockSkew(null))
.isInstanceOf(IllegalArgumentException.class);
}

@Test
public void setClockSkewWhenNegativeSecondsThenThrowIllegalArgumentException(){
assertThatThrownBy(() -> this.idTokenValidator.setClockSkew(Duration.ofSeconds(-1)))
.isInstanceOf(IllegalArgumentException.class);
}

@Test
public void validateWhenIssuerNullThenHasErrors() {
this.claims.remove(IdTokenClaimNames.ISS);
Expand Down