mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-07-25 03:33:30 +00:00
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 ========================================================================================================
|
//~ Methods ========================================================================================================
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void initCacheManaer() {
|
public static void initCacheManaer() {
|
||||||
cacheManager = new CacheManager();
|
cacheManager = CacheManager.create();
|
||||||
cacheManager.addCache(new Cache("basiclookuptestcache", 500, false, false, 30, 30));
|
cacheManager.addCache(new Cache("basiclookuptestcache", 500, false, false, 30, 30));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ public class EhCacheBasedAclCacheTests {
|
|||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void initCacheManaer() {
|
public static void initCacheManaer() {
|
||||||
cacheManager = new CacheManager();
|
cacheManager = CacheManager.create();
|
||||||
// Use disk caching immediately (to test for serialization issue reported in SEC-527)
|
// Use disk caching immediately (to test for serialization issue reported in SEC-527)
|
||||||
cacheManager.addCache(new Cache("ehcachebasedacltests", 0, true, false, 600, 300));
|
cacheManager.addCache(new Cache("ehcachebasedacltests", 0, true, false, 600, 300));
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ public class EhCacheBasedTicketCacheTests extends AbstractStatelessTicketCacheTe
|
|||||||
//~ Methods ========================================================================================================
|
//~ Methods ========================================================================================================
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void initCacheManaer() {
|
public static void initCacheManaer() {
|
||||||
cacheManager = new CacheManager();
|
cacheManager = CacheManager.create();
|
||||||
cacheManager.addCache(new Cache("castickets", 500, false, false, 30, 30));
|
cacheManager.addCache(new Cache("castickets", 500, false, false, 30, 30));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ public class EhCacheBasedUserCacheTests {
|
|||||||
//~ Methods ========================================================================================================
|
//~ Methods ========================================================================================================
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void initCacheManaer() {
|
public static void initCacheManaer() {
|
||||||
cacheManager = new CacheManager();
|
cacheManager = CacheManager.create();
|
||||||
cacheManager.addCache(new Cache("ehcacheusercachetests", 500, false, false, 30, 30));
|
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 REDIRECT_URL = "http://www.example.com/redirect";
|
||||||
private static final String CLAIMED_IDENTITY_URL = "http://www.example.com/identity";
|
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 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;
|
private static final String DEFAULT_TARGET_URL = FILTER_PROCESS_URL;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@ -46,6 +46,7 @@ public class OpenIDAuthenticationFilterTests {
|
|||||||
@Test
|
@Test
|
||||||
public void testFilterOperation() throws Exception {
|
public void testFilterOperation() throws Exception {
|
||||||
MockHttpServletRequest req = new MockHttpServletRequest("GET", REQUEST_PATH);
|
MockHttpServletRequest req = new MockHttpServletRequest("GET", REQUEST_PATH);
|
||||||
|
req.setServerPort(8080);
|
||||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||||
|
|
||||||
req.setParameter("openid_identifier", " " + CLAIMED_IDENTITY_URL);
|
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 {
|
public String beginConsumption(HttpServletRequest req, String claimedIdentity, String returnToUrl, String realm) throws OpenIDConsumerException {
|
||||||
assertEquals(CLAIMED_IDENTITY_URL, claimedIdentity);
|
assertEquals(CLAIMED_IDENTITY_URL, claimedIdentity);
|
||||||
assertEquals(DEFAULT_TARGET_URL, returnToUrl);
|
assertEquals(DEFAULT_TARGET_URL, returnToUrl);
|
||||||
assertEquals("http://localhost:80/", realm);
|
assertEquals("http://localhost:8080/", realm);
|
||||||
return REDIRECT_URL;
|
return REDIRECT_URL;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -16,15 +16,24 @@ import static org.fest.assertions.Assertions.assertThat;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.runners.MockitoJUnitRunner;
|
||||||
import org.springframework.mock.web.MockHttpServletRequest;
|
import org.springframework.mock.web.MockHttpServletRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Luke Taylor
|
* @author Luke Taylor
|
||||||
* @author Rob Winch
|
* @author Rob Winch
|
||||||
*/
|
*/
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class AntPathRequestMatcherTests {
|
public class AntPathRequestMatcherTests {
|
||||||
|
@Mock
|
||||||
|
private HttpServletRequest request;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void singleWildcardMatchesAnyPath() {
|
public void singleWildcardMatchesAnyPath() {
|
||||||
@ -65,8 +74,7 @@ public class AntPathRequestMatcherTests {
|
|||||||
@Test
|
@Test
|
||||||
public void requestHasNullMethodMatches() {
|
public void requestHasNullMethodMatches() {
|
||||||
AntPathRequestMatcher matcher = new AntPathRequestMatcher("/something/*", "GET");
|
AntPathRequestMatcher matcher = new AntPathRequestMatcher("/something/*", "GET");
|
||||||
MockHttpServletRequest request = createRequest("/something/here");
|
HttpServletRequest request = createRequestWithNullMethod("/something/here");
|
||||||
request.setMethod(null);
|
|
||||||
assertTrue(matcher.matches(request));
|
assertTrue(matcher.matches(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,8 +82,7 @@ public class AntPathRequestMatcherTests {
|
|||||||
@Test
|
@Test
|
||||||
public void requestHasNullMethodNoMatch() {
|
public void requestHasNullMethodNoMatch() {
|
||||||
AntPathRequestMatcher matcher = new AntPathRequestMatcher("/something/*", "GET");
|
AntPathRequestMatcher matcher = new AntPathRequestMatcher("/something/*", "GET");
|
||||||
MockHttpServletRequest request = createRequest("/nomatch");
|
HttpServletRequest request = createRequestWithNullMethod("/nomatch");
|
||||||
request.setMethod(null);
|
|
||||||
assertFalse(matcher.matches(request));
|
assertFalse(matcher.matches(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,6 +149,12 @@ public class AntPathRequestMatcherTests {
|
|||||||
new AntPathRequestMatcher("/blah", "GET").toString();
|
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) {
|
private MockHttpServletRequest createRequest(String path) {
|
||||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||||
request.setQueryString("doesntMatter");
|
request.setQueryString("doesntMatter");
|
||||||
|
@ -12,16 +12,26 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.security.web.util;
|
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;
|
import org.springframework.mock.web.MockHttpServletRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Luke Taylor
|
* @author Luke Taylor
|
||||||
* @author Rob Winch
|
* @author Rob Winch
|
||||||
*/
|
*/
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class RegexRequestMatcherTests {
|
public class RegexRequestMatcherTests {
|
||||||
|
@Mock
|
||||||
|
private HttpServletRequest request;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void doesntMatchIfHttpMethodIsDifferent() throws Exception {
|
public void doesntMatchIfHttpMethodIsDifferent() throws Exception {
|
||||||
@ -57,8 +67,7 @@ public class RegexRequestMatcherTests {
|
|||||||
@Test
|
@Test
|
||||||
public void requestHasNullMethodMatches() {
|
public void requestHasNullMethodMatches() {
|
||||||
RegexRequestMatcher matcher = new RegexRequestMatcher("/something/.*", "GET");
|
RegexRequestMatcher matcher = new RegexRequestMatcher("/something/.*", "GET");
|
||||||
MockHttpServletRequest request = createRequest("/something/here");
|
HttpServletRequest request = createRequestWithNullMethod("/something/here");
|
||||||
request.setMethod(null);
|
|
||||||
assertTrue(matcher.matches(request));
|
assertTrue(matcher.matches(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,33 +75,27 @@ public class RegexRequestMatcherTests {
|
|||||||
@Test
|
@Test
|
||||||
public void requestHasNullMethodNoMatch() {
|
public void requestHasNullMethodNoMatch() {
|
||||||
RegexRequestMatcher matcher = new RegexRequestMatcher("/something/.*", "GET");
|
RegexRequestMatcher matcher = new RegexRequestMatcher("/something/.*", "GET");
|
||||||
MockHttpServletRequest request = createRequest("/nomatch");
|
HttpServletRequest request = createRequestWithNullMethod("/nomatch");
|
||||||
request.setMethod(null);
|
|
||||||
assertFalse(matcher.matches(request));
|
assertFalse(matcher.matches(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void requestHasNullMethodAndNullMatcherMatches() {
|
public void requestHasNullMethodAndNullMatcherMatches() {
|
||||||
RegexRequestMatcher matcher = new RegexRequestMatcher("/something/.*", null);
|
RegexRequestMatcher matcher = new RegexRequestMatcher("/something/.*", null);
|
||||||
MockHttpServletRequest request = createRequest("/something/here");
|
HttpServletRequest request = createRequestWithNullMethod("/something/here");
|
||||||
request.setMethod(null);
|
|
||||||
assertTrue(matcher.matches(request));
|
assertTrue(matcher.matches(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void requestHasNullMethodAndNullMatcherNoMatch() {
|
public void requestHasNullMethodAndNullMatcherNoMatch() {
|
||||||
RegexRequestMatcher matcher = new RegexRequestMatcher("/something/.*", null);
|
RegexRequestMatcher matcher = new RegexRequestMatcher("/something/.*", null);
|
||||||
MockHttpServletRequest request = createRequest("/nomatch");
|
HttpServletRequest request = createRequestWithNullMethod("/nomatch");
|
||||||
request.setMethod(null);
|
|
||||||
assertFalse(matcher.matches(request));
|
assertFalse(matcher.matches(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
private MockHttpServletRequest createRequest(String path) {
|
private HttpServletRequest createRequestWithNullMethod(String path) {
|
||||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
when(request.getQueryString()).thenReturn("doesntMatter");
|
||||||
request.setQueryString("doesntMatter");
|
when(request.getServletPath()).thenReturn(path);
|
||||||
request.setServletPath(path);
|
|
||||||
request.setMethod("POST");
|
|
||||||
|
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user