Merge Remove Redudant Throws
Fixes gh-7301
This commit is contained in:
@@ -78,7 +78,7 @@ public class FilterChainProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toStringCallSucceeds() throws Exception {
|
||||
public void toStringCallSucceeds() {
|
||||
fcp.afterPropertiesSet();
|
||||
fcp.toString();
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ public class FilterInvocationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dummyRequestIsSupportedByUrlUtils() throws Exception {
|
||||
public void dummyRequestIsSupportedByUrlUtils() {
|
||||
DummyRequest request = new DummyRequest();
|
||||
request.setContextPath("");
|
||||
request.setRequestURI("/something");
|
||||
|
||||
@@ -34,7 +34,7 @@ public class PortMapperImplTests {
|
||||
// ~ Methods
|
||||
// ========================================================================================================
|
||||
@Test
|
||||
public void testDefaultMappingsAreKnown() throws Exception {
|
||||
public void testDefaultMappingsAreKnown() {
|
||||
PortMapperImpl portMapper = new PortMapperImpl();
|
||||
assertThat(portMapper.lookupHttpPort(443)).isEqualTo(
|
||||
Integer.valueOf(80));
|
||||
@@ -47,7 +47,7 @@ public class PortMapperImplTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDetectsEmptyMap() throws Exception {
|
||||
public void testDetectsEmptyMap() {
|
||||
PortMapperImpl portMapper = new PortMapperImpl();
|
||||
|
||||
try {
|
||||
@@ -60,7 +60,7 @@ public class PortMapperImplTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDetectsNullMap() throws Exception {
|
||||
public void testDetectsNullMap() {
|
||||
PortMapperImpl portMapper = new PortMapperImpl();
|
||||
|
||||
try {
|
||||
|
||||
@@ -32,7 +32,7 @@ public class PortResolverImplTests {
|
||||
// ~ Methods
|
||||
// ========================================================================================================
|
||||
@Test
|
||||
public void testDetectsBuggyIeHttpRequest() throws Exception {
|
||||
public void testDetectsBuggyIeHttpRequest() {
|
||||
PortResolverImpl pr = new PortResolverImpl();
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
@@ -42,7 +42,7 @@ public class PortResolverImplTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDetectsBuggyIeHttpsRequest() throws Exception {
|
||||
public void testDetectsBuggyIeHttpsRequest() {
|
||||
PortResolverImpl pr = new PortResolverImpl();
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
@@ -52,7 +52,7 @@ public class PortResolverImplTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDetectsEmptyPortMapper() throws Exception {
|
||||
public void testDetectsEmptyPortMapper() {
|
||||
PortResolverImpl pr = new PortResolverImpl();
|
||||
|
||||
try {
|
||||
@@ -65,7 +65,7 @@ public class PortResolverImplTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGettersSetters() throws Exception {
|
||||
public void testGettersSetters() {
|
||||
PortResolverImpl pr = new PortResolverImpl();
|
||||
assertThat(pr.getPortMapper() != null).isTrue();
|
||||
pr.setPortMapper(new PortMapperImpl());
|
||||
@@ -73,7 +73,7 @@ public class PortResolverImplTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNormalOperation() throws Exception {
|
||||
public void testNormalOperation() {
|
||||
PortResolverImpl pr = new PortResolverImpl();
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
|
||||
@@ -62,8 +62,7 @@ public class DefaultWebInvocationPrivilegeEvaluatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void permitsAccessIfNoMatchingAttributesAndPublicInvocationsAllowed()
|
||||
throws Exception {
|
||||
public void permitsAccessIfNoMatchingAttributesAndPublicInvocationsAllowed() {
|
||||
DefaultWebInvocationPrivilegeEvaluator wipe = new DefaultWebInvocationPrivilegeEvaluator(
|
||||
interceptor);
|
||||
when(ods.getAttributes(anyObject())).thenReturn(null);
|
||||
@@ -72,8 +71,7 @@ public class DefaultWebInvocationPrivilegeEvaluatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deniesAccessIfNoMatchingAttributesAndPublicInvocationsNotAllowed()
|
||||
throws Exception {
|
||||
public void deniesAccessIfNoMatchingAttributesAndPublicInvocationsNotAllowed() {
|
||||
DefaultWebInvocationPrivilegeEvaluator wipe = new DefaultWebInvocationPrivilegeEvaluator(
|
||||
interceptor);
|
||||
when(ods.getAttributes(anyObject())).thenReturn(null);
|
||||
@@ -83,14 +81,14 @@ public class DefaultWebInvocationPrivilegeEvaluatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deniesAccessIfAuthenticationIsNull() throws Exception {
|
||||
public void deniesAccessIfAuthenticationIsNull() {
|
||||
DefaultWebInvocationPrivilegeEvaluator wipe = new DefaultWebInvocationPrivilegeEvaluator(
|
||||
interceptor);
|
||||
assertThat(wipe.isAllowed("/foo/index.jsp", null)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allowsAccessIfAccessDecisionManagerDoes() throws Exception {
|
||||
public void allowsAccessIfAccessDecisionManagerDoes() {
|
||||
Authentication token = new TestingAuthenticationToken("test", "Password",
|
||||
"MOCK_INDEX");
|
||||
DefaultWebInvocationPrivilegeEvaluator wipe = new DefaultWebInvocationPrivilegeEvaluator(
|
||||
@@ -100,7 +98,7 @@ public class DefaultWebInvocationPrivilegeEvaluatorTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void deniesAccessIfAccessDecisionManagerDoes() throws Exception {
|
||||
public void deniesAccessIfAccessDecisionManagerDoes() {
|
||||
Authentication token = new TestingAuthenticationToken("test", "Password",
|
||||
"MOCK_INDEX");
|
||||
DefaultWebInvocationPrivilegeEvaluator wipe = new DefaultWebInvocationPrivilegeEvaluator(
|
||||
|
||||
@@ -61,7 +61,7 @@ public class ExceptionTranslationFilterTests {
|
||||
|
||||
@After
|
||||
@Before
|
||||
public void clearContext() throws Exception {
|
||||
public void clearContext() {
|
||||
SecurityContextHolder.clearContext();
|
||||
}
|
||||
|
||||
@@ -257,12 +257,12 @@ public class ExceptionTranslationFilterTests {
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void startupDetectsMissingAuthenticationEntryPoint() throws Exception {
|
||||
public void startupDetectsMissingAuthenticationEntryPoint() {
|
||||
new ExceptionTranslationFilter(null);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void startupDetectsMissingRequestCache() throws Exception {
|
||||
public void startupDetectsMissingRequestCache() {
|
||||
new ExceptionTranslationFilter(mockEntryPoint, null);
|
||||
}
|
||||
|
||||
@@ -305,7 +305,7 @@ public class ExceptionTranslationFilterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doFilterWhenResponseCommittedThenRethrowsException() throws Exception {
|
||||
public void doFilterWhenResponseCommittedThenRethrowsException() {
|
||||
this.mockEntryPoint = mock(AuthenticationEntryPoint.class);
|
||||
FilterChain chain = (request, response) -> {
|
||||
HttpServletResponse httpResponse = (HttpServletResponse) response;
|
||||
|
||||
@@ -23,7 +23,6 @@ import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -62,8 +61,7 @@ public class ChannelDecisionManagerImplTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCannotSetIncorrectObjectTypesIntoChannelProcessorsList()
|
||||
throws Exception {
|
||||
public void testCannotSetIncorrectObjectTypesIntoChannelProcessorsList() {
|
||||
ChannelDecisionManagerImpl cdm = new ChannelDecisionManagerImpl();
|
||||
List list = new Vector();
|
||||
list.add("THIS IS NOT A CHANNELPROCESSOR");
|
||||
@@ -210,7 +208,7 @@ public class ChannelDecisionManagerImplTests {
|
||||
}
|
||||
|
||||
public void decide(FilterInvocation invocation,
|
||||
Collection<ConfigAttribute> config) throws IOException, ServletException {
|
||||
Collection<ConfigAttribute> config) throws IOException {
|
||||
Iterator iter = config.iterator();
|
||||
|
||||
if (this.failIfCalled) {
|
||||
|
||||
@@ -23,7 +23,6 @@ import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
@@ -43,7 +42,7 @@ public class ChannelProcessingFilterTests {
|
||||
// ========================================================================================================
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testDetectsMissingChannelDecisionManager() throws Exception {
|
||||
public void testDetectsMissingChannelDecisionManager() {
|
||||
ChannelProcessingFilter filter = new ChannelProcessingFilter();
|
||||
|
||||
MockFilterInvocationDefinitionMap fids = new MockFilterInvocationDefinitionMap(
|
||||
@@ -54,15 +53,14 @@ public class ChannelProcessingFilterTests {
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testDetectsMissingFilterInvocationSecurityMetadataSource()
|
||||
throws Exception {
|
||||
public void testDetectsMissingFilterInvocationSecurityMetadataSource() {
|
||||
ChannelProcessingFilter filter = new ChannelProcessingFilter();
|
||||
filter.setChannelDecisionManager(new MockChannelDecisionManager(false, "MOCK"));
|
||||
filter.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDetectsSupportedConfigAttribute() throws Exception {
|
||||
public void testDetectsSupportedConfigAttribute() {
|
||||
ChannelProcessingFilter filter = new ChannelProcessingFilter();
|
||||
filter.setChannelDecisionManager(new MockChannelDecisionManager(false,
|
||||
"SUPPORTS_MOCK_ONLY"));
|
||||
@@ -76,7 +74,7 @@ public class ChannelProcessingFilterTests {
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testDetectsUnsupportedConfigAttribute() throws Exception {
|
||||
public void testDetectsUnsupportedConfigAttribute() {
|
||||
ChannelProcessingFilter filter = new ChannelProcessingFilter();
|
||||
filter.setChannelDecisionManager(new MockChannelDecisionManager(false,
|
||||
"SUPPORTS_MOCK_ONLY"));
|
||||
@@ -148,7 +146,7 @@ public class ChannelProcessingFilterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetterSetters() throws Exception {
|
||||
public void testGetterSetters() {
|
||||
ChannelProcessingFilter filter = new ChannelProcessingFilter();
|
||||
filter.setChannelDecisionManager(new MockChannelDecisionManager(false, "MOCK"));
|
||||
assertThat(filter.getChannelDecisionManager() != null).isTrue();
|
||||
@@ -175,7 +173,7 @@ public class ChannelProcessingFilterTests {
|
||||
}
|
||||
|
||||
public void decide(FilterInvocation invocation, Collection<ConfigAttribute> config)
|
||||
throws IOException, ServletException {
|
||||
throws IOException {
|
||||
if (commitAResponse) {
|
||||
invocation.getHttpResponse().sendRedirect("/redirected");
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class RetryWithHttpEntryPointTests {
|
||||
// ~ Methods
|
||||
// ========================================================================================================
|
||||
@Test
|
||||
public void testDetectsMissingPortMapper() throws Exception {
|
||||
public void testDetectsMissingPortMapper() {
|
||||
RetryWithHttpEntryPoint ep = new RetryWithHttpEntryPoint();
|
||||
|
||||
try {
|
||||
@@ -54,7 +54,7 @@ public class RetryWithHttpEntryPointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDetectsMissingPortResolver() throws Exception {
|
||||
public void testDetectsMissingPortResolver() {
|
||||
RetryWithHttpEntryPoint ep = new RetryWithHttpEntryPoint();
|
||||
|
||||
try {
|
||||
|
||||
@@ -38,7 +38,7 @@ public class RetryWithHttpsEntryPointTests {
|
||||
// ~ Methods
|
||||
// ========================================================================================================
|
||||
@Test
|
||||
public void testDetectsMissingPortMapper() throws Exception {
|
||||
public void testDetectsMissingPortMapper() {
|
||||
RetryWithHttpsEntryPoint ep = new RetryWithHttpsEntryPoint();
|
||||
|
||||
try {
|
||||
@@ -50,7 +50,7 @@ public class RetryWithHttpsEntryPointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDetectsMissingPortResolver() throws Exception {
|
||||
public void testDetectsMissingPortResolver() {
|
||||
RetryWithHttpsEntryPoint ep = new RetryWithHttpsEntryPoint();
|
||||
|
||||
try {
|
||||
|
||||
@@ -63,7 +63,7 @@ public class DefaultWebSecurityExpressionHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void expressionPropertiesAreResolvedAgainstAppContextBeans() throws Exception {
|
||||
public void expressionPropertiesAreResolvedAgainstAppContextBeans() {
|
||||
StaticApplicationContext appContext = new StaticApplicationContext();
|
||||
RootBeanDefinition bean = new RootBeanDefinition(SecurityConfig.class);
|
||||
bean.getConstructorArgumentValues().addGenericArgumentValue("ROLE_A");
|
||||
|
||||
@@ -51,7 +51,7 @@ public class ExpressionBasedFilterInvocationSecurityMetadataSourceTests {
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void invalidExpressionIsRejected() throws Exception {
|
||||
public void invalidExpressionIsRejected() {
|
||||
LinkedHashMap<RequestMatcher, Collection<ConfigAttribute>> requestMap = new LinkedHashMap<>();
|
||||
requestMap.put(AnyRequestMatcher.INSTANCE,
|
||||
SecurityConfig.createList("hasRole('X'"));
|
||||
|
||||
@@ -46,7 +46,7 @@ public class WebExpressionVoterTests {
|
||||
private Authentication user = new TestingAuthenticationToken("user", "pass", "X");
|
||||
|
||||
@Test
|
||||
public void supportsWebConfigAttributeAndFilterInvocation() throws Exception {
|
||||
public void supportsWebConfigAttributeAndFilterInvocation() {
|
||||
WebExpressionVoter voter = new WebExpressionVoter();
|
||||
assertThat(voter.supports(new WebExpressionConfigAttribute(mock(Expression.class),
|
||||
mock(EvaluationContextPostProcessor.class)))).isTrue();
|
||||
|
||||
@@ -36,7 +36,7 @@ import org.springframework.security.web.access.expression.WebSecurityExpressionR
|
||||
public class WebSecurityExpressionRootTests {
|
||||
|
||||
@Test
|
||||
public void ipAddressMatchesForEqualIpAddresses() throws Exception {
|
||||
public void ipAddressMatchesForEqualIpAddresses() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.setRequestURI("/test");
|
||||
// IPv4
|
||||
@@ -53,7 +53,7 @@ public class WebSecurityExpressionRootTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addressesInIpRangeMatch() throws Exception {
|
||||
public void addressesInIpRangeMatch() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.setRequestURI("/test");
|
||||
WebSecurityExpressionRoot root = new WebSecurityExpressionRoot(
|
||||
|
||||
@@ -133,7 +133,7 @@ public class DefaultFilterInvocationSecurityMetadataSourceTests {
|
||||
|
||||
// SEC-1236
|
||||
@Test
|
||||
public void mixingPatternsWithAndWithoutHttpMethodsIsSupported() throws Exception {
|
||||
public void mixingPatternsWithAndWithoutHttpMethodsIsSupported() {
|
||||
LinkedHashMap<RequestMatcher, Collection<ConfigAttribute>> requestMap = new LinkedHashMap<>();
|
||||
Collection<ConfigAttribute> userAttrs = SecurityConfig.createList("A");
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ public class FilterSecurityInterceptorTests {
|
||||
// ========================================================================================================
|
||||
|
||||
@Before
|
||||
public final void setUp() throws Exception {
|
||||
public final void setUp() {
|
||||
interceptor = new FilterSecurityInterceptor();
|
||||
am = mock(AuthenticationManager.class);
|
||||
ods = mock(FilterInvocationSecurityMetadataSource.class);
|
||||
@@ -76,7 +76,7 @@ public class FilterSecurityInterceptorTests {
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
public void tearDown() {
|
||||
SecurityContextHolder.clearContext();
|
||||
}
|
||||
|
||||
|
||||
@@ -66,10 +66,9 @@ public class RequestKeyTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void keysWithNullUrlFailsAssertion() throws Exception {
|
||||
public void keysWithNullUrlFailsAssertion() {
|
||||
assertThatThrownBy(() -> new RequestKey(null, null))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("url cannot be null");
|
||||
|
||||
@@ -24,10 +24,7 @@ import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -85,7 +82,7 @@ public class AbstractAuthenticationProcessingFilterTests {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setUp() {
|
||||
successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
|
||||
successHandler.setDefaultTargetUrl("/logged_in.jsp");
|
||||
failureHandler = new SimpleUrlAuthenticationFailureHandler();
|
||||
@@ -94,12 +91,12 @@ public class AbstractAuthenticationProcessingFilterTests {
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
public void tearDown() {
|
||||
SecurityContextHolder.clearContext();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultProcessesFilterUrlMatchesWithPathParameter() throws Exception {
|
||||
public void testDefaultProcessesFilterUrlMatchesWithPathParameter() {
|
||||
MockHttpServletRequest request = createMockAuthenticationRequest();
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
MockAuthenticationFilter filter = new MockAuthenticationFilter();
|
||||
@@ -143,7 +140,7 @@ public class AbstractAuthenticationProcessingFilterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGettersSetters() throws Exception {
|
||||
public void testGettersSetters() {
|
||||
AbstractAuthenticationProcessingFilter filter = new MockAuthenticationFilter();
|
||||
filter.setAuthenticationManager(mock(AuthenticationManager.class));
|
||||
filter.setFilterProcessesUrl("/p");
|
||||
@@ -216,7 +213,7 @@ public class AbstractAuthenticationProcessingFilterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartupDetectsInvalidAuthenticationManager() throws Exception {
|
||||
public void testStartupDetectsInvalidAuthenticationManager() {
|
||||
AbstractAuthenticationProcessingFilter filter = new MockAuthenticationFilter();
|
||||
filter.setAuthenticationFailureHandler(failureHandler);
|
||||
successHandler.setDefaultTargetUrl("/");
|
||||
@@ -234,7 +231,7 @@ public class AbstractAuthenticationProcessingFilterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartupDetectsInvalidFilterProcessesUrl() throws Exception {
|
||||
public void testStartupDetectsInvalidFilterProcessesUrl() {
|
||||
AbstractAuthenticationProcessingFilter filter = new MockAuthenticationFilter();
|
||||
filter.setAuthenticationFailureHandler(failureHandler);
|
||||
filter.setAuthenticationManager(mock(AuthenticationManager.class));
|
||||
@@ -469,8 +466,7 @@ public class AbstractAuthenticationProcessingFilterTests {
|
||||
this.expectToProceed = expectToProceed;
|
||||
}
|
||||
|
||||
public void doFilter(ServletRequest request, ServletResponse response)
|
||||
throws IOException, ServletException {
|
||||
public void doFilter(ServletRequest request, ServletResponse response) {
|
||||
if (expectToProceed) {
|
||||
|
||||
}
|
||||
|
||||
@@ -59,17 +59,17 @@ public class AnonymousAuthenticationFilterTests {
|
||||
|
||||
@Before
|
||||
@After
|
||||
public void clearContext() throws Exception {
|
||||
public void clearContext() {
|
||||
SecurityContextHolder.clearContext();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testDetectsMissingKey() throws Exception {
|
||||
public void testDetectsMissingKey() {
|
||||
new AnonymousAuthenticationFilter(null);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testDetectsUserAttribute() throws Exception {
|
||||
public void testDetectsUserAttribute() {
|
||||
new AnonymousAuthenticationFilter("qwerty", null, null);
|
||||
}
|
||||
|
||||
@@ -124,8 +124,7 @@ public class AnonymousAuthenticationFilterTests {
|
||||
this.expectToProceed = expectToProceed;
|
||||
}
|
||||
|
||||
public void doFilter(ServletRequest request, ServletResponse response)
|
||||
throws IOException, ServletException {
|
||||
public void doFilter(ServletRequest request, ServletResponse response) {
|
||||
if (!expectToProceed) {
|
||||
fail("Did not expect filter chain to proceed");
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ public class AuthenticationFilterTests {
|
||||
}
|
||||
|
||||
@After
|
||||
public void clearContext() throws Exception {
|
||||
public void clearContext() {
|
||||
SecurityContextHolder.clearContext();
|
||||
}
|
||||
|
||||
|
||||
@@ -37,19 +37,19 @@ public class LoginUrlAuthenticationEntryPointTests {
|
||||
// ========================================================================================================
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testDetectsMissingLoginFormUrl() throws Exception {
|
||||
public void testDetectsMissingLoginFormUrl() {
|
||||
new LoginUrlAuthenticationEntryPoint(null);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testDetectsMissingPortMapper() throws Exception {
|
||||
public void testDetectsMissingPortMapper() {
|
||||
LoginUrlAuthenticationEntryPoint ep = new LoginUrlAuthenticationEntryPoint(
|
||||
"/login");
|
||||
ep.setPortMapper(null);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testDetectsMissingPortResolver() throws Exception {
|
||||
public void testDetectsMissingPortResolver() {
|
||||
LoginUrlAuthenticationEntryPoint ep = new LoginUrlAuthenticationEntryPoint(
|
||||
"/login");
|
||||
ep.setPortResolver(null);
|
||||
|
||||
@@ -19,8 +19,6 @@ package org.springframework.security.web.authentication;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
@@ -40,7 +38,7 @@ public class UsernamePasswordAuthenticationFilterTests {
|
||||
// ========================================================================================================
|
||||
|
||||
@Test
|
||||
public void testNormalOperation() throws Exception {
|
||||
public void testNormalOperation() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("POST", "/");
|
||||
request.addParameter(
|
||||
UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_USERNAME_KEY,
|
||||
@@ -60,7 +58,7 @@ public class UsernamePasswordAuthenticationFilterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullPasswordHandledGracefully() throws Exception {
|
||||
public void testNullPasswordHandledGracefully() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("POST", "/");
|
||||
request.addParameter(
|
||||
UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_USERNAME_KEY,
|
||||
@@ -73,7 +71,7 @@ public class UsernamePasswordAuthenticationFilterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullUsernameHandledGracefully() throws Exception {
|
||||
public void testNullUsernameHandledGracefully() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("POST", "/");
|
||||
request.addParameter(
|
||||
UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_PASSWORD_KEY,
|
||||
@@ -86,7 +84,7 @@ public class UsernamePasswordAuthenticationFilterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUsingDifferentParameterNamesWorksAsExpected() throws ServletException {
|
||||
public void testUsingDifferentParameterNamesWorksAsExpected() {
|
||||
UsernamePasswordAuthenticationFilter filter = new UsernamePasswordAuthenticationFilter();
|
||||
filter.setAuthenticationManager(createAuthenticationManager());
|
||||
filter.setUsernameParameter("x");
|
||||
@@ -103,7 +101,7 @@ public class UsernamePasswordAuthenticationFilterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpacesAreTrimmedCorrectlyFromUsername() throws Exception {
|
||||
public void testSpacesAreTrimmedCorrectlyFromUsername() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("POST", "/");
|
||||
request.addParameter(
|
||||
UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_USERNAME_KEY,
|
||||
@@ -144,7 +142,7 @@ public class UsernamePasswordAuthenticationFilterTests {
|
||||
* SEC-571
|
||||
*/
|
||||
@Test
|
||||
public void noSessionIsCreatedIfAllowSessionCreationIsFalse() throws Exception {
|
||||
public void noSessionIsCreatedIfAllowSessionCreationIsFalse() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.setMethod("POST");
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ public class HttpStatusReturningLogoutSuccessHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThatSettNullHttpStatusThrowsException() throws Exception {
|
||||
public void testThatSettNullHttpStatusThrowsException() {
|
||||
|
||||
try {
|
||||
new HttpStatusReturningLogoutSuccessHandler(null);
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.springframework.security.web.firewall.DefaultHttpFirewall;
|
||||
public class LogoutHandlerTests {
|
||||
LogoutFilter filter;
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setUp() {
|
||||
filter = new LogoutFilter("/success", new SecurityContextLogoutHandler());
|
||||
}
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ public class AbstractPreAuthenticatedProcessingFilterTests {
|
||||
|
||||
// SEC-2045
|
||||
@Test
|
||||
public void testAfterPropertiesSetInvokesSuper() throws Exception {
|
||||
public void testAfterPropertiesSetInvokesSuper() {
|
||||
ConcretePreAuthenticatedProcessingFilter filter = new ConcretePreAuthenticatedProcessingFilter();
|
||||
AuthenticationManager am = mock(AuthenticationManager.class);
|
||||
filter.setAuthenticationManager(am);
|
||||
@@ -384,8 +384,7 @@ public class AbstractPreAuthenticatedProcessingFilterTests {
|
||||
grantAccess);
|
||||
}
|
||||
|
||||
private static ConcretePreAuthenticatedProcessingFilter getFilter(boolean grantAccess)
|
||||
throws Exception {
|
||||
private static ConcretePreAuthenticatedProcessingFilter getFilter(boolean grantAccess) {
|
||||
ConcretePreAuthenticatedProcessingFilter filter = new ConcretePreAuthenticatedProcessingFilter();
|
||||
AuthenticationManager am = mock(AuthenticationManager.class);
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
@@ -43,8 +42,5 @@ public class Http403ForbiddenEntryPointTests {
|
||||
catch (IOException e) {
|
||||
fail("Unexpected exception thrown: " + e);
|
||||
}
|
||||
catch (ServletException e) {
|
||||
fail("Unexpected exception thrown: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class PreAuthenticatedAuthenticationProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void nullPrincipalReturnsNullAuthentication() throws Exception {
|
||||
public final void nullPrincipalReturnsNullAuthentication() {
|
||||
PreAuthenticatedAuthenticationProvider provider = new PreAuthenticatedAuthenticationProvider();
|
||||
Authentication request = new PreAuthenticatedAuthenticationToken(null,
|
||||
"dummyPwd");
|
||||
@@ -115,8 +115,7 @@ public class PreAuthenticatedAuthenticationProviderTests {
|
||||
assertThat(333).isEqualTo(provider.getOrder());
|
||||
}
|
||||
|
||||
private PreAuthenticatedAuthenticationProvider getProvider(UserDetails aUserDetails)
|
||||
throws Exception {
|
||||
private PreAuthenticatedAuthenticationProvider getProvider(UserDetails aUserDetails) {
|
||||
PreAuthenticatedAuthenticationProvider result = new PreAuthenticatedAuthenticationProvider();
|
||||
result.setPreAuthenticatedUserDetailsService(
|
||||
getPreAuthenticatedUserDetailsService(aUserDetails));
|
||||
|
||||
@@ -37,7 +37,7 @@ public class SubjectDnX509PrincipalExtractorTests {
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void invalidRegexFails() throws Exception {
|
||||
public void invalidRegexFails() {
|
||||
extractor.setSubjectDnRegex("CN=(.*?,"); // missing closing bracket on group
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ public class AbstractRememberMeServicesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cookieShouldBeCorrectlyEncodedAndDecoded() throws Exception {
|
||||
public void cookieShouldBeCorrectlyEncodedAndDecoded() {
|
||||
String[] cookie = new String[] { "name:with:colon", "cookie", "tokens", "blah" };
|
||||
MockRememberMeServices services = new MockRememberMeServices(uds);
|
||||
|
||||
@@ -99,7 +99,7 @@ public class AbstractRememberMeServicesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cookieWithOpenIDidentifierAsNameIsEncodedAndDecoded() throws Exception {
|
||||
public void cookieWithOpenIDidentifierAsNameIsEncodedAndDecoded() {
|
||||
String[] cookie = new String[] { "https://id.openid.zz", "cookie", "tokens",
|
||||
"blah" };
|
||||
MockRememberMeServices services = new MockRememberMeServices(uds);
|
||||
@@ -153,7 +153,7 @@ public class AbstractRememberMeServicesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void autoLoginShouldFailIfCookieIsNotBase64() throws Exception {
|
||||
public void autoLoginShouldFailIfCookieIsNotBase64() {
|
||||
MockRememberMeServices services = new MockRememberMeServices(uds);
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
@@ -167,7 +167,7 @@ public class AbstractRememberMeServicesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void autoLoginShouldFailIfCookieIsEmpty() throws Exception {
|
||||
public void autoLoginShouldFailIfCookieIsEmpty() {
|
||||
MockRememberMeServices services = new MockRememberMeServices(uds);
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
@@ -246,7 +246,7 @@ public class AbstractRememberMeServicesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void logoutShouldCancelCookie() throws Exception {
|
||||
public void logoutShouldCancelCookie() {
|
||||
MockRememberMeServices services = new MockRememberMeServices(uds);
|
||||
services.setCookieDomain("spring.io");
|
||||
|
||||
@@ -347,7 +347,7 @@ public class AbstractRememberMeServicesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setCookieSetsSecureFlagIfConfigured() throws Exception {
|
||||
public void setCookieSetsSecureFlagIfConfigured() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
request.setContextPath("contextpath");
|
||||
@@ -366,7 +366,7 @@ public class AbstractRememberMeServicesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setCookieSetsIsHttpOnlyFlagByDefault() throws Exception {
|
||||
public void setCookieSetsIsHttpOnlyFlagByDefault() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
request.setContextPath("contextpath");
|
||||
|
||||
@@ -68,7 +68,7 @@ public class JdbcTokenRepositoryImplTests {
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void clearDataSource() throws Exception {
|
||||
public static void clearDataSource() {
|
||||
dataSource.destroy();
|
||||
dataSource = null;
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ public class PersistentTokenBasedRememberMeServicesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void logoutClearsUsersTokenAndCookie() throws Exception {
|
||||
public void logoutClearsUsersTokenAndCookie() {
|
||||
Cookie cookie = new Cookie("mycookiename", "somevalue");
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.setCookies(cookie);
|
||||
|
||||
@@ -102,7 +102,7 @@ public class TokenBasedRememberMeServicesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void autoLoginReturnsNullIfNoCookiePresented() throws Exception {
|
||||
public void autoLoginReturnsNullIfNoCookiePresented() {
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
|
||||
Authentication result = services
|
||||
@@ -113,7 +113,7 @@ public class TokenBasedRememberMeServicesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void autoLoginIgnoresUnrelatedCookie() throws Exception {
|
||||
public void autoLoginIgnoresUnrelatedCookie() {
|
||||
Cookie cookie = new Cookie("unrelated_cookie", "foobar");
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.setCookies(cookie);
|
||||
@@ -126,7 +126,7 @@ public class TokenBasedRememberMeServicesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void autoLoginReturnsNullForExpiredCookieAndClearsCookie() throws Exception {
|
||||
public void autoLoginReturnsNullForExpiredCookieAndClearsCookie() {
|
||||
Cookie cookie = new Cookie(SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY,
|
||||
generateCorrectCookieContentForToken(
|
||||
System.currentTimeMillis() - 1000000, "someone", "password",
|
||||
@@ -144,8 +144,7 @@ public class TokenBasedRememberMeServicesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void autoLoginReturnsNullAndClearsCookieIfMissingThreeTokensInCookieValue()
|
||||
throws Exception {
|
||||
public void autoLoginReturnsNullAndClearsCookieIfMissingThreeTokensInCookieValue() {
|
||||
Cookie cookie = new Cookie(SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY, new String(
|
||||
Base64.encodeBase64("x".getBytes())));
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
@@ -161,7 +160,7 @@ public class TokenBasedRememberMeServicesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void autoLoginClearsNonBase64EncodedCookie() throws Exception {
|
||||
public void autoLoginClearsNonBase64EncodedCookie() {
|
||||
Cookie cookie = new Cookie(SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY,
|
||||
"NOT_BASE_64_ENCODED");
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
@@ -177,8 +176,7 @@ public class TokenBasedRememberMeServicesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void autoLoginClearsCookieIfSignatureBlocksDoesNotMatchExpectedValue()
|
||||
throws Exception {
|
||||
public void autoLoginClearsCookieIfSignatureBlocksDoesNotMatchExpectedValue() {
|
||||
udsWillReturnUser();
|
||||
Cookie cookie = new Cookie(SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY,
|
||||
generateCorrectCookieContentForToken(
|
||||
@@ -198,8 +196,7 @@ public class TokenBasedRememberMeServicesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void autoLoginClearsCookieIfTokenDoesNotContainANumberInCookieValue()
|
||||
throws Exception {
|
||||
public void autoLoginClearsCookieIfTokenDoesNotContainANumberInCookieValue() {
|
||||
Cookie cookie = new Cookie(SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY, new String(
|
||||
Base64.encodeBase64("username:NOT_A_NUMBER:signature".getBytes())));
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
@@ -215,7 +212,7 @@ public class TokenBasedRememberMeServicesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void autoLoginClearsCookieIfUserNotFound() throws Exception {
|
||||
public void autoLoginClearsCookieIfUserNotFound() {
|
||||
udsWillThrowNotFound();
|
||||
Cookie cookie = new Cookie(SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY,
|
||||
generateCorrectCookieContentForToken(
|
||||
@@ -250,7 +247,7 @@ public class TokenBasedRememberMeServicesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void autoLoginWithValidTokenAndUserSucceeds() throws Exception {
|
||||
public void autoLoginWithValidTokenAndUserSucceeds() {
|
||||
udsWillReturnUser();
|
||||
Cookie cookie = new Cookie(SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY,
|
||||
generateCorrectCookieContentForToken(
|
||||
@@ -349,7 +346,7 @@ public class TokenBasedRememberMeServicesTests {
|
||||
|
||||
// SEC-933
|
||||
@Test
|
||||
public void obtainPasswordReturnsNullForTokenWithNullCredentials() throws Exception {
|
||||
public void obtainPasswordReturnsNullForTokenWithNullCredentials() {
|
||||
TestingAuthenticationToken token = new TestingAuthenticationToken("username",
|
||||
null);
|
||||
assertThat(services.retrievePassword(token)).isNull();
|
||||
@@ -357,8 +354,7 @@ public class TokenBasedRememberMeServicesTests {
|
||||
|
||||
// SEC-949
|
||||
@Test
|
||||
public void negativeValidityPeriodIsSetOnCookieButExpiryTimeRemainsAtTwoWeeks()
|
||||
throws Exception {
|
||||
public void negativeValidityPeriodIsSetOnCookieButExpiryTimeRemainsAtTwoWeeks() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.addParameter(DEFAULT_PARAMETER, "true");
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ public class ConcurrentSessionControlAuthenticationStrategyTests {
|
||||
private ConcurrentSessionControlAuthenticationStrategy strategy;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
public void setup() {
|
||||
authentication = new TestingAuthenticationToken("user", "password", "ROLE_USER");
|
||||
request = new MockHttpServletRequest();
|
||||
response = new MockHttpServletResponse();
|
||||
|
||||
@@ -171,7 +171,7 @@ public class SwitchUserFilterTests {
|
||||
}
|
||||
|
||||
@Test(expected = UsernameNotFoundException.class)
|
||||
public void attemptSwitchToUnknownUserFails() throws Exception {
|
||||
public void attemptSwitchToUnknownUserFails() {
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.addParameter(SwitchUserFilter.SPRING_SECURITY_SWITCH_USERNAME_KEY,
|
||||
@@ -183,27 +183,27 @@ public class SwitchUserFilterTests {
|
||||
}
|
||||
|
||||
@Test(expected = DisabledException.class)
|
||||
public void attemptSwitchToUserThatIsDisabledFails() throws Exception {
|
||||
public void attemptSwitchToUserThatIsDisabledFails() {
|
||||
switchToUser("mcgarrett");
|
||||
}
|
||||
|
||||
@Test(expected = AccountExpiredException.class)
|
||||
public void attemptSwitchToUserWithAccountExpiredFails() throws Exception {
|
||||
public void attemptSwitchToUserWithAccountExpiredFails() {
|
||||
switchToUser("wofat");
|
||||
}
|
||||
|
||||
@Test(expected = CredentialsExpiredException.class)
|
||||
public void attemptSwitchToUserWithExpiredCredentialsFails() throws Exception {
|
||||
public void attemptSwitchToUserWithExpiredCredentialsFails() {
|
||||
switchToUser("steve");
|
||||
}
|
||||
|
||||
@Test(expected = UsernameNotFoundException.class)
|
||||
public void switchUserWithNullUsernameThrowsException() throws Exception {
|
||||
public void switchUserWithNullUsernameThrowsException() {
|
||||
switchToUser(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void attemptSwitchUserIsSuccessfulWithValidUser() throws Exception {
|
||||
public void attemptSwitchUserIsSuccessfulWithValidUser() {
|
||||
assertThat(switchToUser("jacklord")).isNotNull();
|
||||
}
|
||||
|
||||
@@ -245,7 +245,7 @@ public class SwitchUserFilterTests {
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void configMissingUserDetailsServiceFails() throws Exception {
|
||||
public void configMissingUserDetailsServiceFails() {
|
||||
SwitchUserFilter filter = new SwitchUserFilter();
|
||||
filter.setSwitchUserUrl("/login/impersonate");
|
||||
filter.setExitUserUrl("/logout/impersonate");
|
||||
@@ -254,7 +254,7 @@ public class SwitchUserFilterTests {
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testBadConfigMissingTargetUrl() throws Exception {
|
||||
public void testBadConfigMissingTargetUrl() {
|
||||
SwitchUserFilter filter = new SwitchUserFilter();
|
||||
filter.setUserDetailsService(new MockUserDetailsService());
|
||||
filter.setSwitchUserUrl("/login/impersonate");
|
||||
@@ -454,7 +454,7 @@ public class SwitchUserFilterTests {
|
||||
|
||||
// SEC-1763
|
||||
@Test
|
||||
public void nestedSwitchesAreNotAllowed() throws Exception {
|
||||
public void nestedSwitchesAreNotAllowed() {
|
||||
// original user
|
||||
UsernamePasswordAuthenticationToken source = new UsernamePasswordAuthenticationToken(
|
||||
"orig", "hawaii50", ROLES_12);
|
||||
@@ -477,7 +477,7 @@ public class SwitchUserFilterTests {
|
||||
|
||||
// gh-3697
|
||||
@Test
|
||||
public void switchAuthorityRoleCannotBeNull() throws Exception {
|
||||
public void switchAuthorityRoleCannotBeNull() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("switchAuthorityRole cannot be null");
|
||||
switchToUserWithAuthorityRole("dano", null);
|
||||
@@ -485,7 +485,7 @@ public class SwitchUserFilterTests {
|
||||
|
||||
// gh-3697
|
||||
@Test
|
||||
public void switchAuthorityRoleCanBeChanged() throws Exception {
|
||||
public void switchAuthorityRoleCanBeChanged() {
|
||||
String switchAuthorityRole = "PREVIOUS_ADMINISTRATOR";
|
||||
|
||||
// original user
|
||||
|
||||
@@ -28,20 +28,18 @@ import org.springframework.security.web.authentication.switchuser.SwitchUserGran
|
||||
public class SwitchUserGrantedAuthorityTests {
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void authorityWithNullRoleFailsAssertion() throws Exception {
|
||||
public void authorityWithNullRoleFailsAssertion() {
|
||||
assertThatThrownBy(() -> new SwitchUserGrantedAuthority(null, null))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("role cannot be null");
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void authorityWithNullSourceFailsAssertion() throws Exception {
|
||||
public void authorityWithNullSourceFailsAssertion() {
|
||||
assertThatThrownBy(() -> new SwitchUserGrantedAuthority("role", null))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("source cannot be null");
|
||||
|
||||
@@ -50,7 +50,7 @@ public class BasicAuthenticationConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNormalOperation() throws Exception {
|
||||
public void testNormalOperation() {
|
||||
String token = "rod:koala";
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.addHeader("Authorization", "Basic " + new String(Base64.encodeBase64(token.getBytes())));
|
||||
@@ -74,7 +74,7 @@ public class BasicAuthenticationConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhenUnsupportedAuthorizationHeaderThenIgnored() throws Exception {
|
||||
public void testWhenUnsupportedAuthorizationHeaderThenIgnored() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.addHeader("Authorization", "Bearer someOtherToken");
|
||||
UsernamePasswordAuthenticationToken authentication = converter.convert(request);
|
||||
@@ -84,7 +84,7 @@ public class BasicAuthenticationConverterTests {
|
||||
}
|
||||
|
||||
@Test(expected = BadCredentialsException.class)
|
||||
public void testWhenInvalidBasicAuthorizationTokenThenError() throws Exception {
|
||||
public void testWhenInvalidBasicAuthorizationTokenThenError() {
|
||||
String token = "NOT_A_VALID_TOKEN_AS_MISSING_COLON";
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.addHeader("Authorization", "Basic " + new String(Base64.encodeBase64(token.getBytes())));
|
||||
@@ -92,7 +92,7 @@ public class BasicAuthenticationConverterTests {
|
||||
}
|
||||
|
||||
@Test(expected = BadCredentialsException.class)
|
||||
public void testWhenInvalidBase64ThenError() throws Exception {
|
||||
public void testWhenInvalidBase64ThenError() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.addHeader("Authorization", "Basic NOT_VALID_BASE64");
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ import static org.assertj.core.api.Assertions.fail;
|
||||
public class BasicAuthenticationEntryPointTests {
|
||||
|
||||
@Test
|
||||
public void testDetectsMissingRealmName() throws Exception {
|
||||
public void testDetectsMissingRealmName() {
|
||||
BasicAuthenticationEntryPoint ep = new BasicAuthenticationEntryPoint();
|
||||
|
||||
try {
|
||||
|
||||
@@ -56,7 +56,7 @@ public class BasicAuthenticationFilterTests {
|
||||
// ========================================================================================================
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setUp() {
|
||||
SecurityContextHolder.clearContext();
|
||||
UsernamePasswordAuthenticationToken rodRequest = new UsernamePasswordAuthenticationToken(
|
||||
"rod", "koala");
|
||||
@@ -74,7 +74,7 @@ public class BasicAuthenticationFilterTests {
|
||||
}
|
||||
|
||||
@After
|
||||
public void clearContext() throws Exception {
|
||||
public void clearContext() {
|
||||
SecurityContextHolder.clearContext();
|
||||
}
|
||||
|
||||
@@ -208,12 +208,12 @@ public class BasicAuthenticationFilterTests {
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testStartupDetectsMissingAuthenticationEntryPoint() throws Exception {
|
||||
public void testStartupDetectsMissingAuthenticationEntryPoint() {
|
||||
new BasicAuthenticationFilter(manager, null);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testStartupDetectsMissingAuthenticationManager() throws Exception {
|
||||
public void testStartupDetectsMissingAuthenticationManager() {
|
||||
BasicAuthenticationFilter filter = new BasicAuthenticationFilter(null);
|
||||
}
|
||||
|
||||
|
||||
@@ -372,14 +372,14 @@ public class DigestAuthenticationFilterTests {
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void startupDetectsMissingAuthenticationEntryPoint() throws Exception {
|
||||
public void startupDetectsMissingAuthenticationEntryPoint() {
|
||||
DigestAuthenticationFilter filter = new DigestAuthenticationFilter();
|
||||
filter.setUserDetailsService(mock(UserDetailsService.class));
|
||||
filter.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void startupDetectsMissingUserDetailsService() throws Exception {
|
||||
public void startupDetectsMissingUserDetailsService() {
|
||||
DigestAuthenticationFilter filter = new DigestAuthenticationFilter();
|
||||
filter.setAuthenticationEntryPoint(new DigestAuthenticationEntryPoint());
|
||||
filter.afterPropertiesSet();
|
||||
|
||||
@@ -55,17 +55,17 @@ public class AuthenticationPrincipalArgumentResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsParameterNoAnnotation() throws Exception {
|
||||
public void supportsParameterNoAnnotation() {
|
||||
assertThat(resolver.supportsParameter(showUserNoAnnotation())).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsParameterAnnotation() throws Exception {
|
||||
public void supportsParameterAnnotation() {
|
||||
assertThat(resolver.supportsParameter(showUserAnnotationObject())).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsParameterCustomAnnotation() throws Exception {
|
||||
public void supportsParameterCustomAnnotation() {
|
||||
assertThat(resolver.supportsParameter(showUserCustomAnnotation())).isTrue();
|
||||
}
|
||||
|
||||
|
||||
@@ -59,12 +59,12 @@ public class CurrentSecurityContextArgumentResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsParameterNoAnnotation() throws Exception {
|
||||
public void supportsParameterNoAnnotation() {
|
||||
assertThat(resolver.supportsParameter(showSecurityContextNoAnnotation())).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsParameterAnnotation() throws Exception {
|
||||
public void supportsParameterAnnotation() {
|
||||
assertThat(resolver.supportsParameter(showSecurityContextAnnotation())).isTrue();
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ public class CurrentSecurityContextArgumentResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveArgumentWithNullAuthentication() throws Exception {
|
||||
public void resolveArgumentWithNullAuthentication() {
|
||||
SecurityContext context = SecurityContextHolder.getContext();
|
||||
Authentication authentication = context.getAuthentication();
|
||||
context.setAuthentication(null);
|
||||
@@ -159,7 +159,7 @@ public class CurrentSecurityContextArgumentResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveArgumentSecurityContextErrorOnInvalidTypeTrue() throws Exception {
|
||||
public void resolveArgumentSecurityContextErrorOnInvalidTypeTrue() {
|
||||
String principal = "invalid_type_true";
|
||||
setAuthenticationPrincipal(principal);
|
||||
assertThatExceptionOfType(ClassCastException.class).isThrownBy(() -> resolver.resolveArgument(showSecurityContextErrorOnInvalidTypeTrue(), null,
|
||||
@@ -187,7 +187,7 @@ public class CurrentSecurityContextArgumentResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void metaAnnotationWhenCurrentSecurityWithErrorOnInvalidTypeThenMisMatch() throws Exception {
|
||||
public void metaAnnotationWhenCurrentSecurityWithErrorOnInvalidTypeThenMisMatch() {
|
||||
assertThatExceptionOfType(ClassCastException.class).isThrownBy(() -> resolver.resolveArgument(showCurrentSecurityWithErrorOnInvalidTypeMisMatch(), null,
|
||||
null, null));
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ public class ConcurrentSessionFilterTests {
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void detectsMissingSessionRegistry() throws Exception {
|
||||
public void detectsMissingSessionRegistry() {
|
||||
new ConcurrentSessionFilter(null);
|
||||
}
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ public class HttpSessionSecurityContextRepositoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sessionIsntCreatedIfContextDoesntChange() throws Exception {
|
||||
public void sessionIsntCreatedIfContextDoesntChange() {
|
||||
HttpSessionSecurityContextRepository repo = new HttpSessionSecurityContextRepository();
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
@@ -115,7 +115,7 @@ public class HttpSessionSecurityContextRepositoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sessionIsntCreatedIfAllowSessionCreationIsFalse() throws Exception {
|
||||
public void sessionIsntCreatedIfAllowSessionCreationIsFalse() {
|
||||
HttpSessionSecurityContextRepository repo = new HttpSessionSecurityContextRepository();
|
||||
repo.setAllowSessionCreation(false);
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
@@ -130,8 +130,7 @@ public class HttpSessionSecurityContextRepositoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void existingContextIsSuccessFullyLoadedFromSessionAndSavedBack()
|
||||
throws Exception {
|
||||
public void existingContextIsSuccessFullyLoadedFromSessionAndSavedBack() {
|
||||
HttpSessionSecurityContextRepository repo = new HttpSessionSecurityContextRepository();
|
||||
repo.setSpringSecurityContextKey("imTheContext");
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
@@ -152,8 +151,7 @@ public class HttpSessionSecurityContextRepositoryTests {
|
||||
|
||||
// SEC-1528
|
||||
@Test
|
||||
public void saveContextCallsSetAttributeIfContextIsModifiedDirectlyDuringRequest()
|
||||
throws Exception {
|
||||
public void saveContextCallsSetAttributeIfContextIsModifiedDirectlyDuringRequest() {
|
||||
HttpSessionSecurityContextRepository repo = new HttpSessionSecurityContextRepository();
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
// Set up an existing authenticated context, mocking that it is in the session
|
||||
@@ -177,7 +175,7 @@ public class HttpSessionSecurityContextRepositoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonSecurityContextInSessionIsIgnored() throws Exception {
|
||||
public void nonSecurityContextInSessionIsIgnored() {
|
||||
HttpSessionSecurityContextRepository repo = new HttpSessionSecurityContextRepository();
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
SecurityContextHolder.getContext().setAuthentication(testToken);
|
||||
@@ -192,7 +190,7 @@ public class HttpSessionSecurityContextRepositoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sessionIsCreatedAndContextStoredWhenContextChanges() throws Exception {
|
||||
public void sessionIsCreatedAndContextStoredWhenContextChanges() {
|
||||
HttpSessionSecurityContextRepository repo = new HttpSessionSecurityContextRepository();
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
@@ -404,8 +402,7 @@ public class HttpSessionSecurityContextRepositoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noSessionIsCreatedIfSessionWasInvalidatedDuringTheRequest()
|
||||
throws Exception {
|
||||
public void noSessionIsCreatedIfSessionWasInvalidatedDuringTheRequest() {
|
||||
HttpSessionSecurityContextRepository repo = new HttpSessionSecurityContextRepository();
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.getSession();
|
||||
@@ -422,7 +419,7 @@ public class HttpSessionSecurityContextRepositoryTests {
|
||||
|
||||
// SEC-1315
|
||||
@Test
|
||||
public void noSessionIsCreatedIfAnonymousTokenIsUsed() throws Exception {
|
||||
public void noSessionIsCreatedIfAnonymousTokenIsUsed() {
|
||||
HttpSessionSecurityContextRepository repo = new HttpSessionSecurityContextRepository();
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
@@ -439,8 +436,7 @@ public class HttpSessionSecurityContextRepositoryTests {
|
||||
|
||||
// SEC-1587
|
||||
@Test
|
||||
public void contextIsRemovedFromSessionIfCurrentContextIsAnonymous()
|
||||
throws Exception {
|
||||
public void contextIsRemovedFromSessionIfCurrentContextIsAnonymous() {
|
||||
HttpSessionSecurityContextRepository repo = new HttpSessionSecurityContextRepository();
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
SecurityContext ctxInSession = SecurityContextHolder.createEmptyContext();
|
||||
@@ -458,7 +454,7 @@ public class HttpSessionSecurityContextRepositoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contextIsRemovedFromSessionIfCurrentContextIsEmpty() throws Exception {
|
||||
public void contextIsRemovedFromSessionIfCurrentContextIsEmpty() {
|
||||
HttpSessionSecurityContextRepository repo = new HttpSessionSecurityContextRepository();
|
||||
repo.setSpringSecurityContextKey("imTheContext");
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
@@ -476,8 +472,7 @@ public class HttpSessionSecurityContextRepositoryTests {
|
||||
|
||||
// SEC-1735
|
||||
@Test
|
||||
public void contextIsNotRemovedFromSessionIfContextBeforeExecutionDefault()
|
||||
throws Exception {
|
||||
public void contextIsNotRemovedFromSessionIfContextBeforeExecutionDefault() {
|
||||
HttpSessionSecurityContextRepository repo = new HttpSessionSecurityContextRepository();
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
HttpRequestResponseHolder holder = new HttpRequestResponseHolder(request,
|
||||
@@ -497,7 +492,7 @@ public class HttpSessionSecurityContextRepositoryTests {
|
||||
|
||||
// SEC-3070
|
||||
@Test
|
||||
public void logoutInvalidateSessionFalseFails() throws Exception {
|
||||
public void logoutInvalidateSessionFalseFails() {
|
||||
HttpSessionSecurityContextRepository repo = new HttpSessionSecurityContextRepository();
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
SecurityContext ctxInSession = SecurityContextHolder.createEmptyContext();
|
||||
@@ -517,8 +512,7 @@ public class HttpSessionSecurityContextRepositoryTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void sessionDisableUrlRewritingPreventsSessionIdBeingWrittenToUrl()
|
||||
throws Exception {
|
||||
public void sessionDisableUrlRewritingPreventsSessionIdBeingWrittenToUrl() {
|
||||
HttpSessionSecurityContextRepository repo = new HttpSessionSecurityContextRepository();
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
final String sessionId = ";jsessionid=id";
|
||||
|
||||
@@ -92,7 +92,7 @@ public class WebAsyncManagerIntegrationFilterTests {
|
||||
.registerCallableInterceptors(new CallableProcessingInterceptorAdapter() {
|
||||
@Override
|
||||
public <T> void postProcess(NativeWebRequest request,
|
||||
Callable<T> task, Object concurrentResult) throws Exception {
|
||||
Callable<T> task, Object concurrentResult) {
|
||||
assertThat(SecurityContextHolder.getContext()).isNotSameAs(
|
||||
securityContext);
|
||||
}
|
||||
@@ -113,7 +113,7 @@ public class WebAsyncManagerIntegrationFilterTests {
|
||||
.registerCallableInterceptors(new CallableProcessingInterceptorAdapter() {
|
||||
@Override
|
||||
public <T> void postProcess(NativeWebRequest request,
|
||||
Callable<T> task, Object concurrentResult) throws Exception {
|
||||
Callable<T> task, Object concurrentResult) {
|
||||
assertThat(SecurityContextHolder.getContext()).isNotSameAs(
|
||||
securityContext);
|
||||
}
|
||||
@@ -142,7 +142,7 @@ public class WebAsyncManagerIntegrationFilterTests {
|
||||
|
||||
private class VerifyingCallable implements Callable<SecurityContext> {
|
||||
|
||||
public SecurityContext call() throws Exception {
|
||||
public SecurityContext call() {
|
||||
return SecurityContextHolder.getContext();
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ public class DefaultHttpFirewallTests {
|
||||
"./path", ".//path", "." };
|
||||
|
||||
@Test
|
||||
public void unnormalizedPathsAreRejected() throws Exception {
|
||||
public void unnormalizedPathsAreRejected() {
|
||||
DefaultHttpFirewall fw = new DefaultHttpFirewall();
|
||||
|
||||
MockHttpServletRequest request;
|
||||
|
||||
@@ -67,14 +67,14 @@ public class FirewalledResponseTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addHeaderWhenValidThenDelegateInvoked() throws Exception {
|
||||
public void addHeaderWhenValidThenDelegateInvoked() {
|
||||
fwResponse.addHeader("foo", "bar");
|
||||
|
||||
verify(response).addHeader("foo", "bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addHeaderWhenNullValueThenDelegateInvoked() throws Exception {
|
||||
public void addHeaderWhenNullValueThenDelegateInvoked() {
|
||||
fwResponse.addHeader("foo", null);
|
||||
|
||||
verify(response).addHeader("foo", null);
|
||||
|
||||
@@ -90,7 +90,7 @@ public class StrictHttpFirewallTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFirewalledRequestWhenRequestURINotNormalizedThenThrowsRequestRejectedException() throws Exception {
|
||||
public void getFirewalledRequestWhenRequestURINotNormalizedThenThrowsRequestRejectedException() {
|
||||
for (String path : this.unnormalizedPaths) {
|
||||
this.request = new MockHttpServletRequest("GET", "");
|
||||
this.request.setRequestURI(path);
|
||||
@@ -103,7 +103,7 @@ public class StrictHttpFirewallTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFirewalledRequestWhenContextPathNotNormalizedThenThrowsRequestRejectedException() throws Exception {
|
||||
public void getFirewalledRequestWhenContextPathNotNormalizedThenThrowsRequestRejectedException() {
|
||||
for (String path : this.unnormalizedPaths) {
|
||||
this.request = new MockHttpServletRequest("GET", "");
|
||||
this.request.setContextPath(path);
|
||||
@@ -116,7 +116,7 @@ public class StrictHttpFirewallTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFirewalledRequestWhenServletPathNotNormalizedThenThrowsRequestRejectedException() throws Exception {
|
||||
public void getFirewalledRequestWhenServletPathNotNormalizedThenThrowsRequestRejectedException() {
|
||||
for (String path : this.unnormalizedPaths) {
|
||||
this.request = new MockHttpServletRequest("GET", "");
|
||||
this.request.setServletPath(path);
|
||||
@@ -129,7 +129,7 @@ public class StrictHttpFirewallTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFirewalledRequestWhenPathInfoNotNormalizedThenThrowsRequestRejectedException() throws Exception {
|
||||
public void getFirewalledRequestWhenPathInfoNotNormalizedThenThrowsRequestRejectedException() {
|
||||
for (String path : this.unnormalizedPaths) {
|
||||
this.request = new MockHttpServletRequest("GET", "");
|
||||
this.request.setPathInfo(path);
|
||||
@@ -431,7 +431,7 @@ public class StrictHttpFirewallTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFirewalledRequestWhenAllowUrlLowerCaseEncodedDoubleSlashThenNoException() throws Exception {
|
||||
public void getFirewalledRequestWhenAllowUrlLowerCaseEncodedDoubleSlashThenNoException() {
|
||||
this.firewall.setAllowUrlEncodedSlash(true);
|
||||
this.firewall.setAllowUrlEncodedDoubleSlash(true);
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "");
|
||||
@@ -443,7 +443,7 @@ public class StrictHttpFirewallTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFirewalledRequestWhenAllowUrlUpperCaseEncodedDoubleSlashThenNoException() throws Exception {
|
||||
public void getFirewalledRequestWhenAllowUrlUpperCaseEncodedDoubleSlashThenNoException() {
|
||||
this.firewall.setAllowUrlEncodedSlash(true);
|
||||
this.firewall.setAllowUrlEncodedDoubleSlash(true);
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "");
|
||||
@@ -455,8 +455,7 @@ public class StrictHttpFirewallTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFirewalledRequestWhenAllowUrlLowerCaseAndUpperCaseEncodedDoubleSlashThenNoException()
|
||||
throws Exception {
|
||||
public void getFirewalledRequestWhenAllowUrlLowerCaseAndUpperCaseEncodedDoubleSlashThenNoException() {
|
||||
this.firewall.setAllowUrlEncodedSlash(true);
|
||||
this.firewall.setAllowUrlEncodedDoubleSlash(true);
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "");
|
||||
@@ -468,8 +467,7 @@ public class StrictHttpFirewallTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFirewalledRequestWhenAllowUrlUpperCaseAndLowerCaseEncodedDoubleSlashThenNoException()
|
||||
throws Exception {
|
||||
public void getFirewalledRequestWhenAllowUrlUpperCaseAndLowerCaseEncodedDoubleSlashThenNoException() {
|
||||
this.firewall.setAllowUrlEncodedSlash(true);
|
||||
this.firewall.setAllowUrlEncodedDoubleSlash(true);
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "");
|
||||
@@ -481,7 +479,7 @@ public class StrictHttpFirewallTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFirewalledRequestWhenRemoveFromUpperCaseEncodedUrlBlacklistThenNoException() throws Exception {
|
||||
public void getFirewalledRequestWhenRemoveFromUpperCaseEncodedUrlBlacklistThenNoException() {
|
||||
this.firewall.setAllowUrlEncodedSlash(true);
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "");
|
||||
request.setRequestURI("/context-root/a/b%2F%2Fc");
|
||||
@@ -490,7 +488,7 @@ public class StrictHttpFirewallTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFirewalledRequestWhenRemoveFromLowerCaseEncodedUrlBlacklistThenNoException() throws Exception {
|
||||
public void getFirewalledRequestWhenRemoveFromLowerCaseEncodedUrlBlacklistThenNoException() {
|
||||
this.firewall.setAllowUrlEncodedSlash(true);
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "");
|
||||
request.setRequestURI("/context-root/a/b%2f%2fc");
|
||||
@@ -499,8 +497,7 @@ public class StrictHttpFirewallTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFirewalledRequestWhenRemoveFromLowerCaseAndUpperCaseEncodedUrlBlacklistThenNoException()
|
||||
throws Exception {
|
||||
public void getFirewalledRequestWhenRemoveFromLowerCaseAndUpperCaseEncodedUrlBlacklistThenNoException() {
|
||||
this.firewall.setAllowUrlEncodedSlash(true);
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "");
|
||||
request.setRequestURI("/context-root/a/b%2f%2Fc");
|
||||
@@ -509,8 +506,7 @@ public class StrictHttpFirewallTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFirewalledRequestWhenRemoveFromUpperCaseAndLowerCaseEncodedUrlBlacklistThenNoException()
|
||||
throws Exception {
|
||||
public void getFirewalledRequestWhenRemoveFromUpperCaseAndLowerCaseEncodedUrlBlacklistThenNoException() {
|
||||
this.firewall.setAllowUrlEncodedSlash(true);
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "");
|
||||
request.setRequestURI("/context-root/a/b%2F%2fc");
|
||||
@@ -519,7 +515,7 @@ public class StrictHttpFirewallTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFirewalledRequestWhenRemoveFromDecodedUrlBlacklistThenNoException() throws Exception {
|
||||
public void getFirewalledRequestWhenRemoveFromDecodedUrlBlacklistThenNoException() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "");
|
||||
request.setPathInfo("/a/b//c");
|
||||
this.firewall.getDecodedUrlBlacklist().removeAll(Arrays.asList("//"));
|
||||
|
||||
@@ -54,13 +54,13 @@ public class HeaderWriterFilterTests {
|
||||
private HeaderWriter writer2;
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void noHeadersConfigured() throws Exception {
|
||||
public void noHeadersConfigured() {
|
||||
List<HeaderWriter> headerWriters = new ArrayList<>();
|
||||
new HeaderWriterFilter(headerWriters);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void constructorNullWriters() throws Exception {
|
||||
public void constructorNullWriters() {
|
||||
new HeaderWriterFilter(null);
|
||||
}
|
||||
|
||||
|
||||
@@ -158,7 +158,7 @@ public class HpkpHeaderWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeHeadersTerminateConnectionWithURIAsString() throws URISyntaxException {
|
||||
public void writeHeadersTerminateConnectionWithURIAsString() {
|
||||
writer.setReportOnly(false);
|
||||
writer.setReportUri("https://example.com/pkp-report");
|
||||
|
||||
|
||||
@@ -171,7 +171,7 @@ public class JaasApiIntegrationFilterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void obtainSubject() throws Exception {
|
||||
public void obtainSubject() {
|
||||
SecurityContextHolder.getContext().setAuthentication(token);
|
||||
assertThat(filter.obtainSubject(request)).isEqualTo(authenticatedSubject);
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ public class SavedCookieMixinTests extends AbstractMixinTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void deserializeSavedCookieWithList() throws IOException, JSONException {
|
||||
public void deserializeSavedCookieWithList() throws IOException {
|
||||
List<SavedCookie> savedCookies = (List<SavedCookie>) mapper.readValue(COOKIES_JSON, Object.class);
|
||||
assertThat(savedCookies).isNotNull().hasSize(1);
|
||||
assertThat(savedCookies.get(0).getName()).isEqualTo("SESSION");
|
||||
|
||||
@@ -71,7 +71,7 @@ public class WebAuthenticationDetailsMixinTests extends AbstractMixinTests {
|
||||
|
||||
@Test
|
||||
public void webAuthenticationDetailsDeserializeTest()
|
||||
throws IOException, JSONException {
|
||||
throws IOException {
|
||||
WebAuthenticationDetails details = mapper.readValue(AUTHENTICATION_DETAILS_JSON,
|
||||
WebAuthenticationDetails.class);
|
||||
assertThat(details).isNotNull();
|
||||
|
||||
@@ -624,7 +624,7 @@ public class ResolvableMethod {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object invoke(org.aopalliance.intercept.MethodInvocation inv) throws Throwable {
|
||||
public Object invoke(org.aopalliance.intercept.MethodInvocation inv) {
|
||||
return intercept(inv.getThis(), inv.getMethod(), inv.getArguments(), null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,17 +54,17 @@ public class AuthenticationPrincipalArgumentResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsParameterNoAnnotation() throws Exception {
|
||||
public void supportsParameterNoAnnotation() {
|
||||
assertThat(resolver.supportsParameter(showUserNoAnnotation())).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsParameterAnnotation() throws Exception {
|
||||
public void supportsParameterAnnotation() {
|
||||
assertThat(resolver.supportsParameter(showUserAnnotationObject())).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsParameterCustomAnnotation() throws Exception {
|
||||
public void supportsParameterCustomAnnotation() {
|
||||
assertThat(resolver.supportsParameter(showUserCustomAnnotation())).isTrue();
|
||||
}
|
||||
|
||||
|
||||
@@ -69,17 +69,17 @@ public class AuthenticationPrincipalArgumentResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsParameterAuthenticationPrincipal() throws Exception {
|
||||
public void supportsParameterAuthenticationPrincipal() {
|
||||
assertThat(resolver.supportsParameter(this.authenticationPrincipal.arg(String.class))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsParameterCurrentUser() throws Exception {
|
||||
public void supportsParameterCurrentUser() {
|
||||
assertThat(resolver.supportsParameter(this.meta.arg(String.class))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveArgumentWhenIsAuthenticationThenObtainsPrincipal() throws Exception {
|
||||
public void resolveArgumentWhenIsAuthenticationThenObtainsPrincipal() {
|
||||
MethodParameter parameter = this.authenticationPrincipal.arg(String.class);
|
||||
when(authentication.getPrincipal()).thenReturn("user");
|
||||
when(exchange.getPrincipal()).thenReturn(Mono.just(authentication));
|
||||
@@ -90,7 +90,7 @@ public class AuthenticationPrincipalArgumentResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveArgumentWhenIsNotAuthenticationThenMonoEmpty() throws Exception {
|
||||
public void resolveArgumentWhenIsNotAuthenticationThenMonoEmpty() {
|
||||
MethodParameter parameter = this.authenticationPrincipal.arg(String.class);
|
||||
when(exchange.getPrincipal()).thenReturn(Mono.just(() -> ""));
|
||||
|
||||
@@ -101,7 +101,7 @@ public class AuthenticationPrincipalArgumentResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveArgumentWhenIsEmptyThenMonoEmpty() throws Exception {
|
||||
public void resolveArgumentWhenIsEmptyThenMonoEmpty() {
|
||||
MethodParameter parameter = this.authenticationPrincipal.arg(String.class);
|
||||
when(exchange.getPrincipal()).thenReturn(Mono.empty());
|
||||
|
||||
@@ -112,7 +112,7 @@ public class AuthenticationPrincipalArgumentResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveArgumentWhenMonoIsAuthenticationThenObtainsPrincipal() throws Exception {
|
||||
public void resolveArgumentWhenMonoIsAuthenticationThenObtainsPrincipal() {
|
||||
MethodParameter parameter = this.authenticationPrincipal.arg(Mono.class, String.class);
|
||||
when(authentication.getPrincipal()).thenReturn("user");
|
||||
when(exchange.getPrincipal()).thenReturn(Mono.just(authentication));
|
||||
@@ -123,7 +123,7 @@ public class AuthenticationPrincipalArgumentResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveArgumentWhenMonoIsAuthenticationAndNoGenericThenObtainsPrincipal() throws Exception {
|
||||
public void resolveArgumentWhenMonoIsAuthenticationAndNoGenericThenObtainsPrincipal() {
|
||||
MethodParameter parameter = ResolvableMethod.on(getClass()).named("authenticationPrincipalNoGeneric").build().arg(Mono.class);
|
||||
when(authentication.getPrincipal()).thenReturn("user");
|
||||
when(exchange.getPrincipal()).thenReturn(Mono.just(authentication));
|
||||
@@ -134,7 +134,7 @@ public class AuthenticationPrincipalArgumentResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveArgumentWhenSpelThenObtainsPrincipal() throws Exception {
|
||||
public void resolveArgumentWhenSpelThenObtainsPrincipal() {
|
||||
MyUser user = new MyUser(3L);
|
||||
MethodParameter parameter = this.spel.arg(Long.class);
|
||||
when(authentication.getPrincipal()).thenReturn(user);
|
||||
@@ -159,7 +159,7 @@ public class AuthenticationPrincipalArgumentResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveArgumentWhenMetaThenObtainsPrincipal() throws Exception {
|
||||
public void resolveArgumentWhenMetaThenObtainsPrincipal() {
|
||||
MethodParameter parameter = this.meta.arg(String.class);
|
||||
when(authentication.getPrincipal()).thenReturn("user");
|
||||
when(exchange.getPrincipal()).thenReturn(Mono.just(authentication));
|
||||
@@ -170,7 +170,7 @@ public class AuthenticationPrincipalArgumentResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveArgumentWhenErrorOnInvalidTypeImplicit() throws Exception {
|
||||
public void resolveArgumentWhenErrorOnInvalidTypeImplicit() {
|
||||
MethodParameter parameter = ResolvableMethod.on(getClass()).named("errorOnInvalidTypeWhenImplicit").build().arg(Integer.class);
|
||||
when(authentication.getPrincipal()).thenReturn("user");
|
||||
when(exchange.getPrincipal()).thenReturn(Mono.just(authentication));
|
||||
@@ -181,7 +181,7 @@ public class AuthenticationPrincipalArgumentResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveArgumentWhenErrorOnInvalidTypeExplicitFalse() throws Exception {
|
||||
public void resolveArgumentWhenErrorOnInvalidTypeExplicitFalse() {
|
||||
MethodParameter parameter = ResolvableMethod.on(getClass()).named("errorOnInvalidTypeWhenExplicitFalse").build().arg(Integer.class);
|
||||
when(authentication.getPrincipal()).thenReturn("user");
|
||||
when(exchange.getPrincipal()).thenReturn(Mono.just(authentication));
|
||||
@@ -192,7 +192,7 @@ public class AuthenticationPrincipalArgumentResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveArgumentWhenErrorOnInvalidTypeExplicitTrue() throws Exception {
|
||||
public void resolveArgumentWhenErrorOnInvalidTypeExplicitTrue() {
|
||||
MethodParameter parameter = ResolvableMethod.on(getClass()).named("errorOnInvalidTypeWhenExplicitTrue").build().arg(Integer.class);
|
||||
when(authentication.getPrincipal()).thenReturn("user");
|
||||
when(exchange.getPrincipal()).thenReturn(Mono.just(authentication));
|
||||
|
||||
@@ -76,17 +76,17 @@ public class CurrentSecurityContextArgumentResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsParameterCurrentSecurityContext() throws Exception {
|
||||
public void supportsParameterCurrentSecurityContext() {
|
||||
assertThat(resolver.supportsParameter(this.securityContextMethod.arg(Mono.class, SecurityContext.class))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsParameterWithAuthentication() throws Exception {
|
||||
public void supportsParameterWithAuthentication() {
|
||||
assertThat(resolver.supportsParameter(this.securityContextWithAuthentication.arg(Mono.class, Authentication.class))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveArgumentWithNullSecurityContext() throws Exception {
|
||||
public void resolveArgumentWithNullSecurityContext() {
|
||||
MethodParameter parameter = ResolvableMethod.on(getClass()).named("securityContext").build().arg(Mono.class, SecurityContext.class);
|
||||
Context context = ReactiveSecurityContextHolder.withSecurityContext(Mono.empty());
|
||||
Mono<Object> argument = resolver.resolveArgument(parameter, bindingContext, exchange);
|
||||
@@ -96,7 +96,7 @@ public class CurrentSecurityContextArgumentResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveArgumentWithSecurityContext() throws Exception {
|
||||
public void resolveArgumentWithSecurityContext() {
|
||||
MethodParameter parameter = ResolvableMethod.on(getClass()).named("securityContext").build().arg(Mono.class, SecurityContext.class);
|
||||
Authentication auth = buildAuthenticationWithPrincipal("hello");
|
||||
Context context = ReactiveSecurityContextHolder.withAuthentication(auth);
|
||||
@@ -107,7 +107,7 @@ public class CurrentSecurityContextArgumentResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveArgumentWithCustomSecurityContext() throws Exception {
|
||||
public void resolveArgumentWithCustomSecurityContext() {
|
||||
MethodParameter parameter = ResolvableMethod.on(getClass()).named("customSecurityContext").build().arg(Mono.class, SecurityContext.class);
|
||||
Authentication auth = buildAuthenticationWithPrincipal("hello");
|
||||
Context context = ReactiveSecurityContextHolder.withSecurityContext(Mono.just(new CustomSecurityContext(auth)));
|
||||
@@ -118,7 +118,7 @@ public class CurrentSecurityContextArgumentResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveArgumentWithNullAuthentication1() throws Exception {
|
||||
public void resolveArgumentWithNullAuthentication1() {
|
||||
MethodParameter parameter = ResolvableMethod.on(getClass()).named("securityContext").build().arg(Mono.class, SecurityContext.class);
|
||||
Authentication auth = null;
|
||||
Context context = ReactiveSecurityContextHolder.withAuthentication(auth);
|
||||
@@ -129,7 +129,7 @@ public class CurrentSecurityContextArgumentResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveArgumentWithNullAuthentication2() throws Exception {
|
||||
public void resolveArgumentWithNullAuthentication2() {
|
||||
MethodParameter parameter = ResolvableMethod.on(getClass()).named("securityContextWithAuthentication").build().arg(Mono.class, Authentication.class);
|
||||
Authentication auth = null;
|
||||
Context context = ReactiveSecurityContextHolder.withAuthentication(auth);
|
||||
@@ -140,7 +140,7 @@ public class CurrentSecurityContextArgumentResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveArgumentWithAuthentication1() throws Exception {
|
||||
public void resolveArgumentWithAuthentication1() {
|
||||
MethodParameter parameter = ResolvableMethod.on(getClass()).named("securityContextWithAuthentication").build().arg(Mono.class, Authentication.class);
|
||||
Authentication auth = buildAuthenticationWithPrincipal("authentication1");
|
||||
Context context = ReactiveSecurityContextHolder.withAuthentication(auth);
|
||||
@@ -151,7 +151,7 @@ public class CurrentSecurityContextArgumentResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveArgumentWithNullAuthenticationOptional1() throws Exception {
|
||||
public void resolveArgumentWithNullAuthenticationOptional1() {
|
||||
MethodParameter parameter = ResolvableMethod.on(getClass()).named("securityContextWithDepthPropOptional").build().arg(Mono.class, Object.class);
|
||||
Authentication auth = null;
|
||||
Context context = ReactiveSecurityContextHolder.withAuthentication(auth);
|
||||
@@ -162,7 +162,7 @@ public class CurrentSecurityContextArgumentResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveArgumentWithAuthenticationOptional1() throws Exception {
|
||||
public void resolveArgumentWithAuthenticationOptional1() {
|
||||
MethodParameter parameter = ResolvableMethod.on(getClass()).named("securityContextWithDepthPropOptional").build().arg(Mono.class, Object.class);
|
||||
Authentication auth = buildAuthenticationWithPrincipal("auth_optional");
|
||||
Context context = ReactiveSecurityContextHolder.withAuthentication(auth);
|
||||
@@ -173,7 +173,7 @@ public class CurrentSecurityContextArgumentResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveArgumentWithNullDepthProp1() throws Exception {
|
||||
public void resolveArgumentWithNullDepthProp1() {
|
||||
MethodParameter parameter = ResolvableMethod.on(getClass()).named("securityContextWithDepthProp").build().arg(Mono.class, Object.class);
|
||||
Authentication auth = null;
|
||||
Context context = ReactiveSecurityContextHolder.withAuthentication(auth);
|
||||
@@ -183,7 +183,7 @@ public class CurrentSecurityContextArgumentResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveArgumentWithStringDepthProp() throws Exception {
|
||||
public void resolveArgumentWithStringDepthProp() {
|
||||
MethodParameter parameter = ResolvableMethod.on(getClass()).named("securityContextWithDepthStringProp").build().arg(Mono.class, String.class);
|
||||
Authentication auth = buildAuthenticationWithPrincipal("auth_string");
|
||||
Context context = ReactiveSecurityContextHolder.withAuthentication(auth);
|
||||
@@ -194,7 +194,7 @@ public class CurrentSecurityContextArgumentResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveArgumentWhenErrorOnInvalidTypeImplicit() throws Exception {
|
||||
public void resolveArgumentWhenErrorOnInvalidTypeImplicit() {
|
||||
MethodParameter parameter = ResolvableMethod.on(getClass()).named("errorOnInvalidTypeWhenImplicit").build().arg(Mono.class, String.class);
|
||||
Authentication auth = buildAuthenticationWithPrincipal("invalid_type_implicit");
|
||||
Context context = ReactiveSecurityContextHolder.withAuthentication(auth);
|
||||
@@ -205,7 +205,7 @@ public class CurrentSecurityContextArgumentResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveArgumentErrorOnInvalidTypeWhenExplicitFalse() throws Exception {
|
||||
public void resolveArgumentErrorOnInvalidTypeWhenExplicitFalse() {
|
||||
MethodParameter parameter = ResolvableMethod.on(getClass()).named("errorOnInvalidTypeWhenExplicitFalse").build().arg(Mono.class, String.class);
|
||||
Authentication auth = buildAuthenticationWithPrincipal("error_on_invalid_type_explicit_false");
|
||||
Context context = ReactiveSecurityContextHolder.withAuthentication(auth);
|
||||
@@ -216,7 +216,7 @@ public class CurrentSecurityContextArgumentResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveArgumentErrorOnInvalidTypeWhenExplicitTrue() throws Exception {
|
||||
public void resolveArgumentErrorOnInvalidTypeWhenExplicitTrue() {
|
||||
MethodParameter parameter = ResolvableMethod.on(getClass()).named("errorOnInvalidTypeWhenExplicitTrue").build().arg(Mono.class, String.class);
|
||||
Authentication auth = buildAuthenticationWithPrincipal("error_on_invalid_type_explicit_true");
|
||||
Context context = ReactiveSecurityContextHolder.withAuthentication(auth);
|
||||
@@ -226,7 +226,7 @@ public class CurrentSecurityContextArgumentResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void metaAnnotationWhenDefaultSecurityContextThenInjectSecurityContext() throws Exception {
|
||||
public void metaAnnotationWhenDefaultSecurityContextThenInjectSecurityContext() {
|
||||
MethodParameter parameter = ResolvableMethod.on(getClass()).named("currentCustomSecurityContext").build().arg(Mono.class, SecurityContext.class);
|
||||
Authentication auth = buildAuthenticationWithPrincipal("current_custom_security_context");
|
||||
Context context = ReactiveSecurityContextHolder.withAuthentication(auth);
|
||||
@@ -237,7 +237,7 @@ public class CurrentSecurityContextArgumentResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void metaAnnotationWhenCurrentAuthenticationThenInjectAuthentication() throws Exception {
|
||||
public void metaAnnotationWhenCurrentAuthenticationThenInjectAuthentication() {
|
||||
MethodParameter parameter = ResolvableMethod.on(getClass()).named("currentAuthentication").build().arg(Mono.class, Authentication.class);
|
||||
Authentication auth = buildAuthenticationWithPrincipal("current_authentication");
|
||||
Context context = ReactiveSecurityContextHolder.withAuthentication(auth);
|
||||
@@ -248,7 +248,7 @@ public class CurrentSecurityContextArgumentResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void metaAnnotationWhenCurrentSecurityWithErrorOnInvalidTypeThenInjectSecurityContext() throws Exception {
|
||||
public void metaAnnotationWhenCurrentSecurityWithErrorOnInvalidTypeThenInjectSecurityContext() {
|
||||
MethodParameter parameter = ResolvableMethod.on(getClass()).named("currentSecurityWithErrorOnInvalidType").build().arg(Mono.class, SecurityContext.class);
|
||||
Authentication auth = buildAuthenticationWithPrincipal("current_security_with_error_on_invalid_type");
|
||||
Context context = ReactiveSecurityContextHolder.withAuthentication(auth);
|
||||
@@ -259,7 +259,7 @@ public class CurrentSecurityContextArgumentResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void metaAnnotationWhenCurrentSecurityWithErrorOnInvalidTypeThenMisMatch() throws Exception {
|
||||
public void metaAnnotationWhenCurrentSecurityWithErrorOnInvalidTypeThenMisMatch() {
|
||||
MethodParameter parameter = ResolvableMethod.on(getClass()).named("currentSecurityWithErrorOnInvalidTypeMisMatch").build().arg(Mono.class, String.class);
|
||||
Authentication auth = buildAuthenticationWithPrincipal("current_security_with_error_on_invalid_type_mismatch");
|
||||
Context context = ReactiveSecurityContextHolder.withAuthentication(auth);
|
||||
|
||||
@@ -29,7 +29,7 @@ public class DefaultSavedRequestTests {
|
||||
|
||||
// SEC-308, SEC-315
|
||||
@Test
|
||||
public void headersAreCaseInsensitive() throws Exception {
|
||||
public void headersAreCaseInsensitive() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.addHeader("USER-aGenT", "Mozilla");
|
||||
DefaultSavedRequest saved = new DefaultSavedRequest(request,
|
||||
@@ -39,7 +39,7 @@ public class DefaultSavedRequestTests {
|
||||
|
||||
// SEC-1412
|
||||
@Test
|
||||
public void discardsIfNoneMatchHeader() throws Exception {
|
||||
public void discardsIfNoneMatchHeader() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.addHeader("If-None-Match", "somehashvalue");
|
||||
DefaultSavedRequest saved = new DefaultSavedRequest(request,
|
||||
@@ -49,7 +49,7 @@ public class DefaultSavedRequestTests {
|
||||
|
||||
// SEC-3082
|
||||
@Test
|
||||
public void parametersAreCaseSensitive() throws Exception {
|
||||
public void parametersAreCaseSensitive() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.addParameter("AnotHerTest", "Hi dad");
|
||||
request.addParameter("thisisatest", "Hi mom");
|
||||
|
||||
@@ -59,7 +59,7 @@ public class HttpSessionRequestCacheTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestMatcherDefinesCorrectSubsetOfCachedRequests() throws Exception {
|
||||
public void requestMatcherDefinesCorrectSubsetOfCachedRequests() {
|
||||
HttpSessionRequestCache cache = new HttpSessionRequestCache();
|
||||
cache.setRequestMatcher(request -> request.getMethod().equals("GET"));
|
||||
|
||||
@@ -75,7 +75,7 @@ public class HttpSessionRequestCacheTests {
|
||||
|
||||
// SEC-2246
|
||||
@Test
|
||||
public void getRequestCustomNoClassCastException() throws Exception {
|
||||
public void getRequestCustomNoClassCastException() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("POST",
|
||||
"/destination");
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
|
||||
@@ -31,7 +31,7 @@ public class SavedCookieTests {
|
||||
SavedCookie savedCookie;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setUp() {
|
||||
cookie = new Cookie("name", "value");
|
||||
cookie.setComment("comment");
|
||||
cookie.setDomain("domain");
|
||||
@@ -43,42 +43,42 @@ public class SavedCookieTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetName() throws Exception {
|
||||
public void testGetName() {
|
||||
assertThat(savedCookie.getName()).isEqualTo(cookie.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetValue() throws Exception {
|
||||
public void testGetValue() {
|
||||
assertThat(savedCookie.getValue()).isEqualTo(cookie.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetComment() throws Exception {
|
||||
public void testGetComment() {
|
||||
assertThat(savedCookie.getComment()).isEqualTo(cookie.getComment());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDomain() throws Exception {
|
||||
public void testGetDomain() {
|
||||
assertThat(savedCookie.getDomain()).isEqualTo(cookie.getDomain());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMaxAge() throws Exception {
|
||||
public void testGetMaxAge() {
|
||||
assertThat(savedCookie.getMaxAge()).isEqualTo(cookie.getMaxAge());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPath() throws Exception {
|
||||
public void testGetPath() {
|
||||
assertThat(savedCookie.getPath()).isEqualTo(cookie.getPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetVersion() throws Exception {
|
||||
public void testGetVersion() {
|
||||
assertThat(savedCookie.getVersion()).isEqualTo(cookie.getVersion());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCookie() throws Exception {
|
||||
public void testGetCookie() {
|
||||
Cookie other = savedCookie.getCookie();
|
||||
assertThat(other.getComment()).isEqualTo(cookie.getComment());
|
||||
assertThat(other.getDomain()).isEqualTo(cookie.getDomain());
|
||||
@@ -91,7 +91,7 @@ public class SavedCookieTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerializable() throws Exception {
|
||||
public void testSerializable() {
|
||||
assertThat(savedCookie instanceof Serializable).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class SavedRequestAwareWrapperTests {
|
||||
|
||||
// SEC-2569
|
||||
@Test
|
||||
public void savedRequestCookiesAreIgnored() throws Exception {
|
||||
public void savedRequestCookiesAreIgnored() {
|
||||
MockHttpServletRequest newRequest = new MockHttpServletRequest();
|
||||
newRequest.setCookies(new Cookie[] { new Cookie("cookie", "fromnew") });
|
||||
MockHttpServletRequest savedRequest = new MockHttpServletRequest();
|
||||
@@ -54,7 +54,7 @@ public class SavedRequestAwareWrapperTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void savedRequesthHeaderIsReturnedIfSavedRequestIsSet() throws Exception {
|
||||
public void savedRequesthHeaderIsReturnedIfSavedRequestIsSet() {
|
||||
MockHttpServletRequest savedRequest = new MockHttpServletRequest();
|
||||
savedRequest.addHeader("header", "savedheader");
|
||||
SavedRequestAwareWrapper wrapper = createWrapper(savedRequest,
|
||||
@@ -155,7 +155,7 @@ public class SavedRequestAwareWrapperTests {
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void invalidDateHeaderIsRejected() throws Exception {
|
||||
public void invalidDateHeaderIsRejected() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.addHeader("header", "notadate");
|
||||
SavedRequestAwareWrapper wrapper = createWrapper(request,
|
||||
@@ -164,7 +164,7 @@ public class SavedRequestAwareWrapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void correctHttpMethodIsReturned() throws Exception {
|
||||
public void correctHttpMethodIsReturned() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("PUT", "/notused");
|
||||
SavedRequestAwareWrapper wrapper = createWrapper(request,
|
||||
new MockHttpServletRequest("GET", "/notused"));
|
||||
@@ -172,7 +172,7 @@ public class SavedRequestAwareWrapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void correctIntHeaderIsReturned() throws Exception {
|
||||
public void correctIntHeaderIsReturned() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.addHeader("header", "999");
|
||||
request.addHeader("header", "1000");
|
||||
|
||||
@@ -47,12 +47,12 @@ public class AndServerWebExchangeMatcherTests {
|
||||
AndServerWebExchangeMatcher matcher;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setUp() {
|
||||
matcher = new AndServerWebExchangeMatcher(matcher1, matcher2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesWhenTrueTrueThenTrue() throws Exception {
|
||||
public void matchesWhenTrueTrueThenTrue() {
|
||||
Map<String, Object> params1 = Collections.singletonMap("foo", "bar");
|
||||
Map<String, Object> params2 = Collections.singletonMap("x", "y");
|
||||
when(matcher1.matches(exchange)).thenReturn(ServerWebExchangeMatcher.MatchResult.match(params1));
|
||||
@@ -70,7 +70,7 @@ public class AndServerWebExchangeMatcherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesWhenFalseFalseThenFalseAndMatcher2NotInvoked() throws Exception {
|
||||
public void matchesWhenFalseFalseThenFalseAndMatcher2NotInvoked() {
|
||||
when(matcher1.matches(exchange)).thenReturn(ServerWebExchangeMatcher.MatchResult.notMatch());
|
||||
|
||||
ServerWebExchangeMatcher.MatchResult matches = matcher.matches(exchange).block();
|
||||
@@ -83,7 +83,7 @@ public class AndServerWebExchangeMatcherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesWhenTrueFalseThenFalse() throws Exception {
|
||||
public void matchesWhenTrueFalseThenFalse() {
|
||||
Map<String, Object> params = Collections.singletonMap("foo", "bar");
|
||||
when(matcher1.matches(exchange)).thenReturn(ServerWebExchangeMatcher.MatchResult.match(params));
|
||||
when(matcher2.matches(exchange)).thenReturn(ServerWebExchangeMatcher.MatchResult.notMatch());
|
||||
@@ -98,7 +98,7 @@ public class AndServerWebExchangeMatcherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesWhenFalseTrueThenFalse() throws Exception {
|
||||
public void matchesWhenFalseTrueThenFalse() {
|
||||
when(matcher1.matches(exchange)).thenReturn(ServerWebExchangeMatcher.MatchResult.notMatch());
|
||||
|
||||
ServerWebExchangeMatcher.MatchResult matches = matcher.matches(exchange).block();
|
||||
|
||||
@@ -41,12 +41,12 @@ public class NegatedServerWebExchangeMatcherTests {
|
||||
NegatedServerWebExchangeMatcher matcher;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setUp() {
|
||||
matcher = new NegatedServerWebExchangeMatcher(matcher1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesWhenFalseThenTrue() throws Exception {
|
||||
public void matchesWhenFalseThenTrue() {
|
||||
when(matcher1.matches(exchange)).thenReturn(ServerWebExchangeMatcher.MatchResult.notMatch());
|
||||
|
||||
ServerWebExchangeMatcher.MatchResult matches = matcher.matches(exchange).block();
|
||||
@@ -58,7 +58,7 @@ public class NegatedServerWebExchangeMatcherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesWhenTrueThenFalse() throws Exception {
|
||||
public void matchesWhenTrueThenFalse() {
|
||||
when(matcher1.matches(exchange)).thenReturn(ServerWebExchangeMatcher.MatchResult.match());
|
||||
|
||||
ServerWebExchangeMatcher.MatchResult matches = matcher.matches(exchange).block();
|
||||
|
||||
@@ -48,12 +48,12 @@ public class OrServerWebExchangeMatcherTests {
|
||||
OrServerWebExchangeMatcher matcher;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setUp() {
|
||||
matcher = new OrServerWebExchangeMatcher(matcher1, matcher2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesWhenFalseFalseThenFalse() throws Exception {
|
||||
public void matchesWhenFalseFalseThenFalse() {
|
||||
when(matcher1.matches(exchange)).thenReturn(ServerWebExchangeMatcher.MatchResult.notMatch());
|
||||
when(matcher2.matches(exchange)).thenReturn(ServerWebExchangeMatcher.MatchResult.notMatch());
|
||||
|
||||
@@ -67,7 +67,7 @@ public class OrServerWebExchangeMatcherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesWhenTrueFalseThenTrueAndMatcher2NotInvoked() throws Exception {
|
||||
public void matchesWhenTrueFalseThenTrueAndMatcher2NotInvoked() {
|
||||
Map<String, Object> params = Collections.singletonMap("foo", "bar");
|
||||
when(matcher1.matches(exchange)).thenReturn(ServerWebExchangeMatcher.MatchResult.match(params));
|
||||
|
||||
@@ -81,7 +81,7 @@ public class OrServerWebExchangeMatcherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesWhenFalseTrueThenTrue() throws Exception {
|
||||
public void matchesWhenFalseTrueThenTrue() {
|
||||
Map<String, Object> params = Collections.singletonMap("foo", "bar");
|
||||
when(matcher1.matches(exchange)).thenReturn(ServerWebExchangeMatcher.MatchResult.notMatch());
|
||||
when(matcher2.matches(exchange)).thenReturn(ServerWebExchangeMatcher.MatchResult.match(params));
|
||||
|
||||
@@ -37,27 +37,27 @@ public class ServerWebExchangeMatchersTests {
|
||||
.from(MockServerHttpRequest.get("/").build());
|
||||
|
||||
@Test
|
||||
public void pathMatchersWhenSingleAndSamePatternThenMatches() throws Exception {
|
||||
public void pathMatchersWhenSingleAndSamePatternThenMatches() {
|
||||
assertThat(pathMatchers("/").matches(exchange).block().isMatch()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pathMatchersWhenSingleAndSamePatternAndMethodThenMatches() throws Exception {
|
||||
public void pathMatchersWhenSingleAndSamePatternAndMethodThenMatches() {
|
||||
assertThat(ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, "/").matches(exchange).block().isMatch()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pathMatchersWhenSingleAndSamePatternAndDiffMethodThenDoesNotMatch() throws Exception {
|
||||
public void pathMatchersWhenSingleAndSamePatternAndDiffMethodThenDoesNotMatch() {
|
||||
assertThat(ServerWebExchangeMatchers.pathMatchers(HttpMethod.POST, "/").matches(exchange).block().isMatch()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pathMatchersWhenSingleAndDifferentPatternThenDoesNotMatch() throws Exception {
|
||||
public void pathMatchersWhenSingleAndDifferentPatternThenDoesNotMatch() {
|
||||
assertThat(pathMatchers("/foobar").matches(exchange).block().isMatch()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pathMatchersWhenMultiThenMatches() throws Exception {
|
||||
public void pathMatchersWhenMultiThenMatches() {
|
||||
assertThat(pathMatchers("/foobar", "/").matches(exchange).block().isMatch()).isTrue();
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ public class MvcRequestMatcherTests {
|
||||
MvcRequestMatcher matcher;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
public void setup() {
|
||||
this.request = new MockHttpServletRequest();
|
||||
this.request.setMethod("GET");
|
||||
this.request.setServletPath("/path");
|
||||
@@ -125,7 +125,7 @@ public class MvcRequestMatcherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesServletPathFalse() throws Exception {
|
||||
public void matchesServletPathFalse() {
|
||||
this.matcher.setServletPath("/spring");
|
||||
this.request.setServletPath("/");
|
||||
|
||||
@@ -179,7 +179,7 @@ public class MvcRequestMatcherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesMethodAndPathFalseMethod() throws Exception {
|
||||
public void matchesMethodAndPathFalseMethod() {
|
||||
this.matcher.setMethod(HttpMethod.POST);
|
||||
|
||||
assertThat(this.matcher.matches(this.request)).isFalse();
|
||||
@@ -191,10 +191,9 @@ public class MvcRequestMatcherTests {
|
||||
* Malicious users can specify any HTTP Method to create a stacktrace and try to
|
||||
* expose useful information about the system. We should ensure we ignore invalid HTTP
|
||||
* methods.
|
||||
* @throws Exception if an error occurs
|
||||
*/
|
||||
@Test
|
||||
public void matchesInvalidMethodOnRequest() throws Exception {
|
||||
public void matchesInvalidMethodOnRequest() {
|
||||
this.matcher.setMethod(HttpMethod.GET);
|
||||
this.request.setMethod("invalid");
|
||||
|
||||
@@ -213,7 +212,7 @@ public class MvcRequestMatcherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesGetMatchableHandlerMappingNull() throws Exception {
|
||||
public void matchesGetMatchableHandlerMappingNull() {
|
||||
assertThat(this.matcher.matches(this.request)).isTrue();
|
||||
}
|
||||
|
||||
|
||||
@@ -36,12 +36,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
public class SecurityContextHolderAwareRequestWrapperTests {
|
||||
|
||||
@Before
|
||||
public void tearDown() throws Exception {
|
||||
public void tearDown() {
|
||||
SecurityContextHolder.clearContext();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCorrectOperationWithStringBasedPrincipal() throws Exception {
|
||||
public void testCorrectOperationWithStringBasedPrincipal() {
|
||||
Authentication auth = new TestingAuthenticationToken("rod", "koala", "ROLE_FOO");
|
||||
SecurityContextHolder.getContext().setAuthentication(auth);
|
||||
|
||||
@@ -72,7 +72,7 @@ public class SecurityContextHolderAwareRequestWrapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCorrectOperationWithUserDetailsBasedPrincipal() throws Exception {
|
||||
public void testCorrectOperationWithUserDetailsBasedPrincipal() {
|
||||
Authentication auth = new TestingAuthenticationToken(
|
||||
new User("rodAsUserDetails", "koala", true, true, true, true,
|
||||
AuthorityUtils.NO_AUTHORITIES),
|
||||
@@ -94,7 +94,7 @@ public class SecurityContextHolderAwareRequestWrapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRoleIsntHeldIfAuthenticationIsNull() throws Exception {
|
||||
public void testRoleIsntHeldIfAuthenticationIsNull() {
|
||||
SecurityContextHolder.getContext().setAuthentication(null);
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
@@ -108,7 +108,7 @@ public class SecurityContextHolderAwareRequestWrapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRolesArentHeldIfAuthenticationPrincipalIsNull() throws Exception {
|
||||
public void testRolesArentHeldIfAuthenticationPrincipalIsNull() {
|
||||
Authentication auth = new TestingAuthenticationToken(null, "koala", "ROLE_HELLO",
|
||||
"ROLE_FOOBAR");
|
||||
SecurityContextHolder.getContext().setAuthentication(auth);
|
||||
|
||||
@@ -39,8 +39,7 @@ import org.springframework.security.web.authentication.session.SessionFixationPr
|
||||
public class DefaultSessionAuthenticationStrategyTests {
|
||||
|
||||
@Test
|
||||
public void newSessionShouldNotBeCreatedIfNoSessionExistsAndAlwaysCreateIsFalse()
|
||||
throws Exception {
|
||||
public void newSessionShouldNotBeCreatedIfNoSessionExistsAndAlwaysCreateIsFalse() {
|
||||
SessionFixationProtectionStrategy strategy = new SessionFixationProtectionStrategy();
|
||||
HttpServletRequest request = new MockHttpServletRequest();
|
||||
|
||||
@@ -51,7 +50,7 @@ public class DefaultSessionAuthenticationStrategyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void newSessionIsCreatedIfSessionAlreadyExists() throws Exception {
|
||||
public void newSessionIsCreatedIfSessionAlreadyExists() {
|
||||
SessionFixationProtectionStrategy strategy = new SessionFixationProtectionStrategy();
|
||||
HttpServletRequest request = new MockHttpServletRequest();
|
||||
String sessionId = request.getSession().getId();
|
||||
@@ -64,8 +63,7 @@ public class DefaultSessionAuthenticationStrategyTests {
|
||||
|
||||
// SEC-2002
|
||||
@Test
|
||||
public void newSessionIsCreatedIfSessionAlreadyExistsWithEventPublisher()
|
||||
throws Exception {
|
||||
public void newSessionIsCreatedIfSessionAlreadyExistsWithEventPublisher() {
|
||||
SessionFixationProtectionStrategy strategy = new SessionFixationProtectionStrategy();
|
||||
HttpServletRequest request = new MockHttpServletRequest();
|
||||
HttpSession session = request.getSession();
|
||||
@@ -101,8 +99,7 @@ public class DefaultSessionAuthenticationStrategyTests {
|
||||
|
||||
// See SEC-1077
|
||||
@Test
|
||||
public void onlySavedRequestAttributeIsMigratedIfMigrateAttributesIsFalse()
|
||||
throws Exception {
|
||||
public void onlySavedRequestAttributeIsMigratedIfMigrateAttributesIsFalse() {
|
||||
SessionFixationProtectionStrategy strategy = new SessionFixationProtectionStrategy();
|
||||
strategy.setMigrateSessionAttributes(false);
|
||||
HttpServletRequest request = new MockHttpServletRequest();
|
||||
@@ -120,8 +117,7 @@ public class DefaultSessionAuthenticationStrategyTests {
|
||||
|
||||
// SEC-2002
|
||||
@Test
|
||||
public void onlySavedRequestAttributeIsMigratedIfMigrateAttributesIsFalseWithEventPublisher()
|
||||
throws Exception {
|
||||
public void onlySavedRequestAttributeIsMigratedIfMigrateAttributesIsFalseWithEventPublisher() {
|
||||
SessionFixationProtectionStrategy strategy = new SessionFixationProtectionStrategy();
|
||||
strategy.setMigrateSessionAttributes(false);
|
||||
HttpServletRequest request = new MockHttpServletRequest();
|
||||
@@ -156,7 +152,7 @@ public class DefaultSessionAuthenticationStrategyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sessionIsCreatedIfAlwaysCreateTrue() throws Exception {
|
||||
public void sessionIsCreatedIfAlwaysCreateTrue() {
|
||||
SessionFixationProtectionStrategy strategy = new SessionFixationProtectionStrategy();
|
||||
strategy.setAlwaysCreateSession(true);
|
||||
HttpServletRequest request = new MockHttpServletRequest();
|
||||
|
||||
@@ -1083,7 +1083,7 @@ public class OnCommittedResponseWrapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contentLengthDoesNotCommit() throws IOException {
|
||||
public void contentLengthDoesNotCommit() {
|
||||
String body = "something";
|
||||
|
||||
response.setContentLength(body.length());
|
||||
|
||||
@@ -32,23 +32,23 @@ public class TextEscapeUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullOrEmptyStringIsHandled() throws Exception {
|
||||
public void nullOrEmptyStringIsHandled() {
|
||||
assertThat(TextEscapeUtils.escapeEntities("")).isEqualTo("");
|
||||
assertThat(TextEscapeUtils.escapeEntities(null)).isNull();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void invalidLowSurrogateIsDetected() throws Exception {
|
||||
public void invalidLowSurrogateIsDetected() {
|
||||
TextEscapeUtils.escapeEntities("abc\uDCCCdef");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void missingLowSurrogateIsDetected() throws Exception {
|
||||
public void missingLowSurrogateIsDetected() {
|
||||
TextEscapeUtils.escapeEntities("abc\uD888a");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void highSurrogateAtEndOfStringIsRejected() throws Exception {
|
||||
public void highSurrogateAtEndOfStringIsRejected() {
|
||||
TextEscapeUtils.escapeEntities("abc\uD888");
|
||||
}
|
||||
|
||||
@@ -56,12 +56,12 @@ public class TextEscapeUtilsTests {
|
||||
* Delta char: 𐐀
|
||||
*/
|
||||
@Test
|
||||
public void validSurrogatePairIsAccepted() throws Exception {
|
||||
public void validSurrogatePairIsAccepted() {
|
||||
assertThat(TextEscapeUtils.escapeEntities("abc\uD801\uDC00a")).isEqualTo("abc𐐀a");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void undefinedSurrogatePairIsIgnored() throws Exception {
|
||||
public void undefinedSurrogatePairIsIgnored() {
|
||||
assertThat(TextEscapeUtils.escapeEntities("abc\uD888\uDC00a")).isEqualTo("abca");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ public class ThrowableAnalyzerTests {
|
||||
private ThrowableAnalyzer nonstandardAnalyzer;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setUp() {
|
||||
|
||||
// Set up test trace
|
||||
this.testTrace = new Throwable[7];
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.junit.Test;
|
||||
public class UrlUtilsTests {
|
||||
|
||||
@Test
|
||||
public void absoluteUrlsAreMatchedAsAbsolute() throws Exception {
|
||||
public void absoluteUrlsAreMatchedAsAbsolute() {
|
||||
assertThat(UrlUtils.isAbsoluteUrl("https://something/")).isTrue();
|
||||
assertThat(UrlUtils.isAbsoluteUrl("http1://something/")).isTrue();
|
||||
assertThat(UrlUtils.isAbsoluteUrl("HTTP://something/")).isTrue();
|
||||
|
||||
@@ -139,7 +139,7 @@ public class AntPathRequestMatcherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exactMatchOnlyMatchesIdenticalPath() throws Exception {
|
||||
public void exactMatchOnlyMatchesIdenticalPath() {
|
||||
AntPathRequestMatcher matcher = new AntPathRequestMatcher("/login.html");
|
||||
assertThat(matcher.matches(createRequest("/login.html"))).isTrue();
|
||||
assertThat(matcher.matches(createRequest("/login.html/"))).isFalse();
|
||||
@@ -147,8 +147,7 @@ public class AntPathRequestMatcherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void httpMethodSpecificMatchOnlyMatchesRequestsWithCorrectMethod()
|
||||
throws Exception {
|
||||
public void httpMethodSpecificMatchOnlyMatchesRequestsWithCorrectMethod() {
|
||||
AntPathRequestMatcher matcher = new AntPathRequestMatcher("/blah", "GET");
|
||||
MockHttpServletRequest request = createRequest("/blah");
|
||||
request.setMethod("GET");
|
||||
@@ -158,7 +157,7 @@ public class AntPathRequestMatcherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void caseSensitive() throws Exception {
|
||||
public void caseSensitive() {
|
||||
MockHttpServletRequest request = createRequest("/UPPER");
|
||||
assertThat(new AntPathRequestMatcher("/upper", null, true).matches(request))
|
||||
.isFalse();
|
||||
@@ -185,7 +184,7 @@ public class AntPathRequestMatcherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalsBehavesCorrectly() throws Exception {
|
||||
public void equalsBehavesCorrectly() {
|
||||
// Both universal wildcard options should be equal
|
||||
assertThat(new AntPathRequestMatcher("**"))
|
||||
.isEqualTo(new AntPathRequestMatcher("/**"));
|
||||
@@ -204,7 +203,7 @@ public class AntPathRequestMatcherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toStringIsOk() throws Exception {
|
||||
public void toStringIsOk() {
|
||||
new AntPathRequestMatcher("/blah").toString();
|
||||
new AntPathRequestMatcher("/blah", "GET").toString();
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.springframework.security.web.util.matcher.ELRequestMatcher;
|
||||
public class ELRequestMatcherTests {
|
||||
|
||||
@Test
|
||||
public void testHasIpAddressTrue() throws Exception {
|
||||
public void testHasIpAddressTrue() {
|
||||
ELRequestMatcher requestMatcher = new ELRequestMatcher("hasIpAddress('1.1.1.1')");
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.setRemoteAddr("1.1.1.1");
|
||||
@@ -37,7 +37,7 @@ public class ELRequestMatcherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasIpAddressFalse() throws Exception {
|
||||
public void testHasIpAddressFalse() {
|
||||
ELRequestMatcher requestMatcher = new ELRequestMatcher("hasIpAddress('1.1.1.1')");
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.setRemoteAddr("1.1.1.2");
|
||||
@@ -46,7 +46,7 @@ public class ELRequestMatcherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasHeaderTrue() throws Exception {
|
||||
public void testHasHeaderTrue() {
|
||||
ELRequestMatcher requestMatcher = new ELRequestMatcher(
|
||||
"hasHeader('User-Agent','MSIE')");
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
@@ -56,7 +56,7 @@ public class ELRequestMatcherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasHeaderTwoEntries() throws Exception {
|
||||
public void testHasHeaderTwoEntries() {
|
||||
ELRequestMatcher requestMatcher = new ELRequestMatcher(
|
||||
"hasHeader('User-Agent','MSIE') or hasHeader('User-Agent','Mozilla')");
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
@@ -72,7 +72,7 @@ public class ELRequestMatcherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasHeaderFalse() throws Exception {
|
||||
public void testHasHeaderFalse() {
|
||||
ELRequestMatcher requestMatcher = new ELRequestMatcher(
|
||||
"hasHeader('User-Agent','MSIE')");
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
@@ -82,7 +82,7 @@ public class ELRequestMatcherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasHeaderNull() throws Exception {
|
||||
public void testHasHeaderNull() {
|
||||
ELRequestMatcher requestMatcher = new ELRequestMatcher(
|
||||
"hasHeader('User-Agent','MSIE')");
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
|
||||
@@ -53,7 +53,7 @@ public class IpAddressMatcherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ipv4SubnetMatchesCorrectly() throws Exception {
|
||||
public void ipv4SubnetMatchesCorrectly() {
|
||||
IpAddressMatcher matcher = new IpAddressMatcher("192.168.1.0/24");
|
||||
assertThat(matcher.matches(ipv4Request)).isTrue();
|
||||
matcher = new IpAddressMatcher("192.168.1.128/25");
|
||||
@@ -63,7 +63,7 @@ public class IpAddressMatcherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ipv6RangeMatches() throws Exception {
|
||||
public void ipv6RangeMatches() {
|
||||
IpAddressMatcher matcher = new IpAddressMatcher("2001:DB8::/48");
|
||||
|
||||
assertThat(matcher.matches("2001:DB8:0:0:0:0:0:0")).isTrue();
|
||||
@@ -74,7 +74,7 @@ public class IpAddressMatcherTests {
|
||||
|
||||
// SEC-1733
|
||||
@Test
|
||||
public void zeroMaskMatchesAnything() throws Exception {
|
||||
public void zeroMaskMatchesAnything() {
|
||||
IpAddressMatcher matcher = new IpAddressMatcher("0.0.0.0/0");
|
||||
|
||||
assertThat(matcher.matches("123.4.5.6")).isTrue();
|
||||
|
||||
@@ -115,35 +115,35 @@ public class MediaTypeRequestMatcherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchWhenAcceptHeaderAsteriskThenAll() throws Exception {
|
||||
public void matchWhenAcceptHeaderAsteriskThenAll() {
|
||||
request.addHeader("Accept", "*/*");
|
||||
matcher = new MediaTypeRequestMatcher(MediaType.ALL);
|
||||
assertThat(matcher.matches(request)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchWhenAcceptHeaderAsteriskThenAnyone() throws Exception {
|
||||
public void matchWhenAcceptHeaderAsteriskThenAnyone() {
|
||||
request.addHeader("Accept", "*/*");
|
||||
matcher = new MediaTypeRequestMatcher(MediaType.TEXT_HTML);
|
||||
assertThat(matcher.matches(request)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchWhenAcceptHeaderAsteriskThenAllInCollection() throws Exception {
|
||||
public void matchWhenAcceptHeaderAsteriskThenAllInCollection() {
|
||||
request.addHeader("Accept", "*/*");
|
||||
matcher = new MediaTypeRequestMatcher(Collections.singleton(MediaType.ALL));
|
||||
assertThat(matcher.matches(request)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchWhenAcceptHeaderAsteriskThenAnyoneInCollection() throws Exception {
|
||||
public void matchWhenAcceptHeaderAsteriskThenAnyoneInCollection() {
|
||||
request.addHeader("Accept", "*/*");
|
||||
matcher = new MediaTypeRequestMatcher(Collections.singleton(MediaType.TEXT_HTML));
|
||||
assertThat(matcher.matches(request)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchWhenNoAcceptHeaderThenAll() throws Exception {
|
||||
public void matchWhenNoAcceptHeaderThenAll() {
|
||||
request.removeHeader("Accept");
|
||||
// if not set Accept, it is match all
|
||||
matcher = new MediaTypeRequestMatcher(MediaType.ALL);
|
||||
@@ -151,35 +151,35 @@ public class MediaTypeRequestMatcherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchWhenNoAcceptHeaderThenAnyone() throws Exception {
|
||||
public void matchWhenNoAcceptHeaderThenAnyone() {
|
||||
request.removeHeader("Accept");
|
||||
matcher = new MediaTypeRequestMatcher(MediaType.TEXT_HTML);
|
||||
assertThat(matcher.matches(request)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchWhenSingleAcceptHeaderThenOne() throws Exception {
|
||||
public void matchWhenSingleAcceptHeaderThenOne() {
|
||||
request.addHeader("Accept", "text/html");
|
||||
matcher = new MediaTypeRequestMatcher(MediaType.TEXT_HTML);
|
||||
assertThat(matcher.matches(request)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchWhenSingleAcceptHeaderThenOneWithCollection() throws Exception {
|
||||
public void matchWhenSingleAcceptHeaderThenOneWithCollection() {
|
||||
request.addHeader("Accept", "text/html");
|
||||
matcher = new MediaTypeRequestMatcher(Collections.singleton(MediaType.TEXT_HTML));
|
||||
assertThat(matcher.matches(request)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchWhenMultipleAcceptHeaderThenMatchMultiple() throws Exception {
|
||||
public void matchWhenMultipleAcceptHeaderThenMatchMultiple() {
|
||||
request.addHeader("Accept", "text/html, application/xhtml+xml, application/xml;q=0.9");
|
||||
matcher = new MediaTypeRequestMatcher(MediaType.TEXT_HTML, MediaType.APPLICATION_XHTML_XML, MediaType.APPLICATION_XML);
|
||||
assertThat(matcher.matches(request)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchWhenMultipleAcceptHeaderThenAnyoneInCollection() throws Exception {
|
||||
public void matchWhenMultipleAcceptHeaderThenAnyoneInCollection() {
|
||||
request.addHeader("Accept", "text/html, application/xhtml+xml, application/xml;q=0.9");
|
||||
matcher = new MediaTypeRequestMatcher(Arrays.asList(MediaType.APPLICATION_XHTML_XML));
|
||||
assertThat(matcher.matches(request)).isTrue();
|
||||
|
||||
@@ -38,7 +38,7 @@ public class RegexRequestMatcherTests {
|
||||
private HttpServletRequest request;
|
||||
|
||||
@Test
|
||||
public void doesntMatchIfHttpMethodIsDifferent() throws Exception {
|
||||
public void doesntMatchIfHttpMethodIsDifferent() {
|
||||
RegexRequestMatcher matcher = new RegexRequestMatcher(".*", "GET");
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("POST", "/anything");
|
||||
@@ -47,7 +47,7 @@ public class RegexRequestMatcherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesIfHttpMethodAndPathMatch() throws Exception {
|
||||
public void matchesIfHttpMethodAndPathMatch() {
|
||||
RegexRequestMatcher matcher = new RegexRequestMatcher(".*", "GET");
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/anything");
|
||||
@@ -57,7 +57,7 @@ public class RegexRequestMatcherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryStringIsMatcherCorrectly() throws Exception {
|
||||
public void queryStringIsMatcherCorrectly() {
|
||||
RegexRequestMatcher matcher = new RegexRequestMatcher(".*\\?x=y", "GET");
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET",
|
||||
|
||||
Reference in New Issue
Block a user