Path Variables fail with different case

Fixes gh-3329
This commit is contained in:
Rob Winch
2016-03-21 10:09:50 -05:00
parent cf66487d3a
commit 7bf014f678
10 changed files with 312 additions and 276 deletions

View File

@@ -15,20 +15,28 @@
*/
package org.springframework.security.web.access.expression;
import java.util.Collections;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.junit.Before;
import org.junit.Test;
import org.springframework.expression.spel.support.StandardEvaluationContext;
import org.springframework.mock.web.MockFilterChain;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.security.web.FilterInvocation;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Rob Winch
*
*/
public class PathVariableSecurityEvaluationContextPostProcessorTests {
PathVariableSecurityEvaluationContextPostProcessor processor;
public class AbstractVariableEvaluationContextPostProcessorTests {
AbstractVariableEvaluationContextPostProcessor processor;
FilterInvocation invocation;
@@ -38,19 +46,34 @@ public class PathVariableSecurityEvaluationContextPostProcessorTests {
@Before
public void setup() {
processor = new PathVariableSecurityEvaluationContextPostProcessor("/");
this.processor = new VariableEvaluationContextPostProcessor();
request = new MockHttpServletRequest();
request.setServletPath("/");
response = new MockHttpServletResponse();
invocation = new FilterInvocation(request,response, new MockFilterChain());
context = new StandardEvaluationContext();
this.request = new MockHttpServletRequest();
this.request.setServletPath("/");
this.response = new MockHttpServletResponse();
this.invocation = new FilterInvocation(this.request, this.response,
new MockFilterChain());
this.context = new StandardEvaluationContext();
}
@Test
public void queryIgnored() {
request.setQueryString("logout");
processor.postProcess(context, invocation);
public void postProcess() {
this.processor.postProcess(this.context, this.invocation);
for (String key : VariableEvaluationContextPostProcessor.RESULTS.keySet()) {
assertThat(this.context.lookupVariable(key))
.isEqualTo(VariableEvaluationContextPostProcessor.RESULTS.get(key));
}
}
static class VariableEvaluationContextPostProcessor
extends AbstractVariableEvaluationContextPostProcessor {
static final Map<String, String> RESULTS = Collections.singletonMap("a", "b");
@Override
protected Map<String, String> extractVariables(HttpServletRequest request) {
return RESULTS;
}
}
}

View File

@@ -51,7 +51,7 @@ public class WebExpressionVoterTests {
public void supportsWebConfigAttributeAndFilterInvocation() throws Exception {
WebExpressionVoter voter = new WebExpressionVoter();
assertThat(voter.supports(new WebExpressionConfigAttribute(mock(Expression.class),
mock(SecurityEvaluationContextPostProcessor.class)))).isTrue();
mock(EvaluationContextPostProcessor.class)))).isTrue();
assertThat(voter.supports(FilterInvocation.class)).isTrue();
assertThat(voter.supports(MethodInvocation.class)).isFalse();
@@ -69,8 +69,8 @@ public class WebExpressionVoterTests {
public void grantsAccessIfExpressionIsTrueDeniesIfFalse() {
WebExpressionVoter voter = new WebExpressionVoter();
Expression ex = mock(Expression.class);
SecurityEvaluationContextPostProcessor postProcessor = mock(
SecurityEvaluationContextPostProcessor.class);
EvaluationContextPostProcessor postProcessor = mock(
EvaluationContextPostProcessor.class);
when(postProcessor.postProcess(any(EvaluationContext.class),
any(FilterInvocation.class))).thenAnswer(new Answer<EvaluationContext>() {