Merge branch 'support/2.6.x' into develop

This commit is contained in:
René Pfeuffer
2020-10-09 12:16:23 +02:00
7 changed files with 103 additions and 8 deletions

View File

@@ -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);

View File

@@ -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();