SEC-2289: Make compatible with Spring 4 as well
There are a few subtle changes in Spring 4 that this commit addresses
This commit is contained in:
@@ -16,15 +16,24 @@ import static org.fest.assertions.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author Luke Taylor
|
||||
* @author Rob Winch
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class AntPathRequestMatcherTests {
|
||||
@Mock
|
||||
private HttpServletRequest request;
|
||||
|
||||
@Test
|
||||
public void singleWildcardMatchesAnyPath() {
|
||||
@@ -65,8 +74,7 @@ public class AntPathRequestMatcherTests {
|
||||
@Test
|
||||
public void requestHasNullMethodMatches() {
|
||||
AntPathRequestMatcher matcher = new AntPathRequestMatcher("/something/*", "GET");
|
||||
MockHttpServletRequest request = createRequest("/something/here");
|
||||
request.setMethod(null);
|
||||
HttpServletRequest request = createRequestWithNullMethod("/something/here");
|
||||
assertTrue(matcher.matches(request));
|
||||
}
|
||||
|
||||
@@ -74,8 +82,7 @@ public class AntPathRequestMatcherTests {
|
||||
@Test
|
||||
public void requestHasNullMethodNoMatch() {
|
||||
AntPathRequestMatcher matcher = new AntPathRequestMatcher("/something/*", "GET");
|
||||
MockHttpServletRequest request = createRequest("/nomatch");
|
||||
request.setMethod(null);
|
||||
HttpServletRequest request = createRequestWithNullMethod("/nomatch");
|
||||
assertFalse(matcher.matches(request));
|
||||
}
|
||||
|
||||
@@ -142,6 +149,12 @@ public class AntPathRequestMatcherTests {
|
||||
new AntPathRequestMatcher("/blah", "GET").toString();
|
||||
}
|
||||
|
||||
private HttpServletRequest createRequestWithNullMethod(String path) {
|
||||
when(request.getQueryString()).thenReturn("doesntMatter");
|
||||
when(request.getServletPath()).thenReturn(path);
|
||||
return request;
|
||||
}
|
||||
|
||||
private MockHttpServletRequest createRequest(String path) {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.setQueryString("doesntMatter");
|
||||
|
||||
@@ -12,16 +12,26 @@
|
||||
*/
|
||||
package org.springframework.security.web.util;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.junit.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author Luke Taylor
|
||||
* @author Rob Winch
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class RegexRequestMatcherTests {
|
||||
@Mock
|
||||
private HttpServletRequest request;
|
||||
|
||||
@Test
|
||||
public void doesntMatchIfHttpMethodIsDifferent() throws Exception {
|
||||
@@ -57,8 +67,7 @@ public class RegexRequestMatcherTests {
|
||||
@Test
|
||||
public void requestHasNullMethodMatches() {
|
||||
RegexRequestMatcher matcher = new RegexRequestMatcher("/something/.*", "GET");
|
||||
MockHttpServletRequest request = createRequest("/something/here");
|
||||
request.setMethod(null);
|
||||
HttpServletRequest request = createRequestWithNullMethod("/something/here");
|
||||
assertTrue(matcher.matches(request));
|
||||
}
|
||||
|
||||
@@ -66,33 +75,27 @@ public class RegexRequestMatcherTests {
|
||||
@Test
|
||||
public void requestHasNullMethodNoMatch() {
|
||||
RegexRequestMatcher matcher = new RegexRequestMatcher("/something/.*", "GET");
|
||||
MockHttpServletRequest request = createRequest("/nomatch");
|
||||
request.setMethod(null);
|
||||
HttpServletRequest request = createRequestWithNullMethod("/nomatch");
|
||||
assertFalse(matcher.matches(request));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestHasNullMethodAndNullMatcherMatches() {
|
||||
RegexRequestMatcher matcher = new RegexRequestMatcher("/something/.*", null);
|
||||
MockHttpServletRequest request = createRequest("/something/here");
|
||||
request.setMethod(null);
|
||||
HttpServletRequest request = createRequestWithNullMethod("/something/here");
|
||||
assertTrue(matcher.matches(request));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestHasNullMethodAndNullMatcherNoMatch() {
|
||||
RegexRequestMatcher matcher = new RegexRequestMatcher("/something/.*", null);
|
||||
MockHttpServletRequest request = createRequest("/nomatch");
|
||||
request.setMethod(null);
|
||||
HttpServletRequest request = createRequestWithNullMethod("/nomatch");
|
||||
assertFalse(matcher.matches(request));
|
||||
}
|
||||
|
||||
private MockHttpServletRequest createRequest(String path) {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.setQueryString("doesntMatter");
|
||||
request.setServletPath(path);
|
||||
request.setMethod("POST");
|
||||
|
||||
private HttpServletRequest createRequestWithNullMethod(String path) {
|
||||
when(request.getQueryString()).thenReturn("doesntMatter");
|
||||
when(request.getServletPath()).thenReturn(path);
|
||||
return request;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user