|
27 | 27 | import eu.webeid.security.exceptions.AuthTokenSignatureValidationException;
|
28 | 28 | import eu.webeid.security.testutil.AbstractTestWithValidator;
|
29 | 29 | import eu.webeid.security.testutil.AuthTokenValidators;
|
| 30 | +import eu.webeid.security.util.DateAndTime; |
30 | 31 | import org.junit.jupiter.api.Test;
|
31 | 32 |
|
32 | 33 | import java.security.cert.X509Certificate;
|
33 | 34 |
|
| 35 | +import static eu.webeid.security.testutil.DateMocker.mockDate; |
34 | 36 | import static eu.webeid.security.util.Strings.toTitleCase;
|
35 | 37 | import static org.assertj.core.api.Assertions.assertThat;
|
36 | 38 | import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
| 39 | +import static org.mockito.Mockito.mockStatic; |
37 | 40 |
|
38 | 41 | class AuthTokenSignatureTest extends AbstractTestWithValidator {
|
39 | 42 |
|
@@ -77,11 +80,15 @@ void whenValidTokenAndWrongOrigin_thenValidationFails() throws Exception {
|
77 | 80 |
|
78 | 81 | @Test
|
79 | 82 | void whenTokenWithWrongCert_thenValidationFails() throws Exception {
|
80 |
| - final AuthTokenValidator authTokenValidator = AuthTokenValidators.getAuthTokenValidator(); |
81 |
| - final WebEidAuthToken authTokenWithWrongCert = authTokenValidator.parse(AUTH_TOKEN_WRONG_CERT); |
82 |
| - assertThatThrownBy(() -> authTokenValidator |
83 |
| - .validate(authTokenWithWrongCert, VALID_CHALLENGE_NONCE)) |
84 |
| - .isInstanceOf(AuthTokenSignatureValidationException.class); |
| 83 | + // Ensure that the certificate does not expire. |
| 84 | + try (final var mockedClock = mockStatic(DateAndTime.DefaultClock.class)) { |
| 85 | + mockDate("2024-08-01", mockedClock); |
| 86 | + final AuthTokenValidator authTokenValidator = AuthTokenValidators.getAuthTokenValidator(); |
| 87 | + final WebEidAuthToken authTokenWithWrongCert = authTokenValidator.parse(AUTH_TOKEN_WRONG_CERT); |
| 88 | + assertThatThrownBy(() -> authTokenValidator |
| 89 | + .validate(authTokenWithWrongCert, VALID_CHALLENGE_NONCE)) |
| 90 | + .isInstanceOf(AuthTokenSignatureValidationException.class); |
| 91 | + } |
85 | 92 | }
|
86 | 93 |
|
87 | 94 | }
|
0 commit comments