mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-02-22 06:26:56 +01:00
introduce api for handling token validation failed exception
This commit is contained in:
committed by
René Pfeuffer
parent
5887c5c268
commit
f2a53644b6
@@ -110,7 +110,7 @@ public class JwtAccessTokenResolverTest {
|
||||
when(validator.validate(Mockito.any(AccessToken.class))).thenReturn(false);
|
||||
|
||||
// expect exception
|
||||
expectedException.expect(AuthenticationException.class);
|
||||
expectedException.expect(TokenValidationFailedException.class);
|
||||
expectedException.expectMessage(Matchers.containsString("token"));
|
||||
|
||||
BearerToken bearer = BearerToken.valueOf(compact);
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -59,6 +60,9 @@ public class ScmAtLeastOneSuccessfulStrategyTest {
|
||||
@Mock
|
||||
TokenExpiredException tokenExpiredException;
|
||||
|
||||
@Mock
|
||||
TokenValidationFailedException tokenValidationFailedException;
|
||||
|
||||
@Mock
|
||||
AuthenticationException authenticationException;
|
||||
|
||||
@@ -77,13 +81,29 @@ public class ScmAtLeastOneSuccessfulStrategyTest {
|
||||
}
|
||||
|
||||
@Test(expected = TokenExpiredException.class)
|
||||
public void shouldRethrowException() {
|
||||
public void shouldRethrowTokenExpiredException() {
|
||||
final ScmAtLeastOneSuccessfulStrategy strategy = new ScmAtLeastOneSuccessfulStrategy();
|
||||
strategy.threadLocal.set(singletonList(tokenExpiredException));
|
||||
|
||||
strategy.afterAllAttempts(token, aggregateInfo);
|
||||
}
|
||||
|
||||
@Test(expected = TokenValidationFailedException.class)
|
||||
public void shouldRethrowTokenValidationFailedException() {
|
||||
final ScmAtLeastOneSuccessfulStrategy strategy = new ScmAtLeastOneSuccessfulStrategy();
|
||||
strategy.threadLocal.set(singletonList(tokenValidationFailedException));
|
||||
|
||||
strategy.afterAllAttempts(token, aggregateInfo);
|
||||
}
|
||||
|
||||
@Test(expected = TokenExpiredException.class)
|
||||
public void shouldPrioritizeRethrowingTokenExpiredExceptionOverTokenValidationFailedException() {
|
||||
final ScmAtLeastOneSuccessfulStrategy strategy = new ScmAtLeastOneSuccessfulStrategy();
|
||||
strategy.threadLocal.set(Arrays.asList(tokenValidationFailedException, tokenExpiredException));
|
||||
|
||||
strategy.afterAllAttempts(token, aggregateInfo);
|
||||
}
|
||||
|
||||
@Test(expected = AuthenticationException.class)
|
||||
public void shouldThrowGenericErrorIfNonTokenExpiredExceptionWasCaught() {
|
||||
final ScmAtLeastOneSuccessfulStrategy strategy = new ScmAtLeastOneSuccessfulStrategy();
|
||||
|
||||
Reference in New Issue
Block a user