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:
parent
26166ef6e8
commit
086056f191
|
@ -50,7 +50,7 @@ public class BasicLookupStrategyTests {
|
|||
//~ Methods ========================================================================================================
|
||||
@BeforeClass
|
||||
public static void initCacheManaer() {
|
||||
cacheManager = new CacheManager();
|
||||
cacheManager = CacheManager.create();
|
||||
cacheManager.addCache(new Cache("basiclookuptestcache", 500, false, false, 30, 30));
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ public class EhCacheBasedAclCacheTests {
|
|||
|
||||
@BeforeClass
|
||||
public static void initCacheManaer() {
|
||||
cacheManager = new CacheManager();
|
||||
cacheManager = CacheManager.create();
|
||||
// Use disk caching immediately (to test for serialization issue reported in SEC-527)
|
||||
cacheManager.addCache(new Cache("ehcachebasedacltests", 0, true, false, 600, 300));
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ public class EhCacheBasedTicketCacheTests extends AbstractStatelessTicketCacheTe
|
|||
//~ Methods ========================================================================================================
|
||||
@BeforeClass
|
||||
public static void initCacheManaer() {
|
||||
cacheManager = new CacheManager();
|
||||
cacheManager = CacheManager.create();
|
||||
cacheManager.addCache(new Cache("castickets", 500, false, false, 30, 30));
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ public class EhCacheBasedUserCacheTests {
|
|||
//~ Methods ========================================================================================================
|
||||
@BeforeClass
|
||||
public static void initCacheManaer() {
|
||||
cacheManager = new CacheManager();
|
||||
cacheManager = CacheManager.create();
|
||||
cacheManager.addCache(new Cache("ehcacheusercachetests", 500, false, false, 30, 30));
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ public class OpenIDAuthenticationFilterTests {
|
|||
private static final String REDIRECT_URL = "http://www.example.com/redirect";
|
||||
private static final String CLAIMED_IDENTITY_URL = "http://www.example.com/identity";
|
||||
private static final String REQUEST_PATH = "/j_spring_openid_security_check";
|
||||
private static final String FILTER_PROCESS_URL = "http://localhost:80" + REQUEST_PATH;
|
||||
private static final String FILTER_PROCESS_URL = "http://localhost:8080" + REQUEST_PATH;
|
||||
private static final String DEFAULT_TARGET_URL = FILTER_PROCESS_URL;
|
||||
|
||||
@Before
|
||||
|
@ -46,6 +46,7 @@ public class OpenIDAuthenticationFilterTests {
|
|||
@Test
|
||||
public void testFilterOperation() throws Exception {
|
||||
MockHttpServletRequest req = new MockHttpServletRequest("GET", REQUEST_PATH);
|
||||
req.setServerPort(8080);
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
|
||||
req.setParameter("openid_identifier", " " + CLAIMED_IDENTITY_URL);
|
||||
|
@ -55,7 +56,7 @@ public class OpenIDAuthenticationFilterTests {
|
|||
public String beginConsumption(HttpServletRequest req, String claimedIdentity, String returnToUrl, String realm) throws OpenIDConsumerException {
|
||||
assertEquals(CLAIMED_IDENTITY_URL, claimedIdentity);
|
||||
assertEquals(DEFAULT_TARGET_URL, returnToUrl);
|
||||
assertEquals("http://localhost:80/", realm);
|
||||
assertEquals("http://localhost:8080/", realm);
|
||||
return REDIRECT_URL;
|
||||
}
|
||||
});
|
||||
|
@ -66,7 +67,7 @@ public class OpenIDAuthenticationFilterTests {
|
|||
// Filter chain shouldn't proceed
|
||||
verify(fc, never()).doFilter(any(HttpServletRequest.class), any(HttpServletResponse.class));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests that the filter encodes any query parameters on the return_to URL.
|
||||
*/
|
||||
|
@ -78,13 +79,13 @@ public class OpenIDAuthenticationFilterTests {
|
|||
MockHttpServletRequest req = new MockHttpServletRequest("GET", REQUEST_PATH);
|
||||
req.addParameter(paramName, paramValue);
|
||||
filter.setReturnToUrlParameters(Collections.singleton(paramName));
|
||||
|
||||
|
||||
URI returnTo = new URI(filter.buildReturnToUrl(req));
|
||||
String query = returnTo.getRawQuery();
|
||||
assertEquals(1, count(query, '='));
|
||||
assertEquals(0, count(query, '&'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Counts the number of occurrences of {@code c} in {@code s}.
|
||||
*/
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue