2828import eu .webeid .security .testutil .AbstractTestWithValidator ;
2929import eu .webeid .security .testutil .AuthTokenValidators ;
3030import eu .webeid .security .util .DateAndTime ;
31+ import org .junit .jupiter .api .AfterEach ;
32+ import org .junit .jupiter .api .BeforeEach ;
3133import org .junit .jupiter .api .Test ;
34+ import org .mockito .MockedStatic ;
3235
3336import java .security .cert .X509Certificate ;
3437
@@ -46,6 +49,22 @@ class AuthTokenSignatureTest extends AbstractTestWithValidator {
4649 "\" signature\" :\" arx164xRiwhIQDINe0J+ZxJWZFOQTx0PBtOaWaxAe7gofEIHRIbV1w0sOCYBJnvmvMem9hU4nc2+iJx2x8poYck4Z6eI3GwtiksIec3XQ9ZIk1n/XchXnmPn3GYV+HzJ\" ," +
4750 "\" format\" :\" web-eid:1.0\" }" ;
4851
52+ private MockedStatic <DateAndTime .DefaultClock > mockedClock ;
53+
54+ @ Override
55+ @ BeforeEach
56+ protected void setup () {
57+ super .setup ();
58+ mockedClock = mockStatic (DateAndTime .DefaultClock .class );
59+ // Ensure that the certificates do not expire.
60+ mockDate ("2021-07-23" , mockedClock );
61+ }
62+
63+ @ AfterEach
64+ void tearDown () {
65+ mockedClock .close ();
66+ }
67+
4968 @ Test
5069 void whenValidTokenAndNonce_thenValidationSucceeds () throws Exception {
5170 final X509Certificate result = validator .validate (validAuthToken , VALID_CHALLENGE_NONCE );
@@ -80,15 +99,11 @@ void whenValidTokenAndWrongOrigin_thenValidationFails() throws Exception {
8099
81100 @ Test
82101 void whenTokenWithWrongCert_thenValidationFails () throws Exception {
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- }
102+ final AuthTokenValidator authTokenValidator = AuthTokenValidators .getAuthTokenValidator ();
103+ final WebEidAuthToken authTokenWithWrongCert = authTokenValidator .parse (AUTH_TOKEN_WRONG_CERT );
104+ assertThatThrownBy (() -> authTokenValidator
105+ .validate (authTokenWithWrongCert , VALID_CHALLENGE_NONCE ))
106+ .isInstanceOf (AuthTokenSignatureValidationException .class );
92107 }
93108
94109}
0 commit comments