Refactor to use Spring's MockHttpServletRequest rather than Acegi Security's equivalent.
This commit is contained in:
parent
b26183dc66
commit
35cdd24abf
|
@ -17,11 +17,11 @@ package net.sf.acegisecurity.adapters.cas;
|
|||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import net.sf.acegisecurity.MockHttpServletRequest;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
|
||||
|
@ -70,7 +70,7 @@ public class CasPasswordHandlerProxyTests extends TestCase {
|
|||
"net/sf/acegisecurity/adapters/cas/applicationContext-invalid.xml");
|
||||
|
||||
try {
|
||||
proxy.authenticate(new MockHttpServletRequest("/"), "x", "y");
|
||||
proxy.authenticate(new MockHttpServletRequest(), "x", "y");
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertEquals("Bean context must contain at least one bean of type CasPasswordHandler",
|
||||
|
@ -81,11 +81,11 @@ public class CasPasswordHandlerProxyTests extends TestCase {
|
|||
public void testNormalOperation() {
|
||||
CasPasswordHandlerProxy proxy = new MockCasPasswordHandlerProxy(
|
||||
"net/sf/acegisecurity/adapters/cas/applicationContext-valid.xml");
|
||||
assertTrue(proxy.authenticate(new MockHttpServletRequest("/"),
|
||||
"marissa", "koala"));
|
||||
assertFalse(proxy.authenticate(new MockHttpServletRequest("/"),
|
||||
"marissa", "WRONG_PASSWORD"));
|
||||
assertFalse(proxy.authenticate(new MockHttpServletRequest("/"),
|
||||
assertTrue(proxy.authenticate(new MockHttpServletRequest(), "marissa",
|
||||
"koala"));
|
||||
assertFalse(proxy.authenticate(new MockHttpServletRequest(), "marissa",
|
||||
"WRONG_PASSWORD"));
|
||||
assertFalse(proxy.authenticate(new MockHttpServletRequest(),
|
||||
"INVALID_USER_NAME", "WRONG_PASSWORD"));
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,8 @@ package net.sf.acegisecurity.adapters.cas;
|
|||
import junit.framework.TestCase;
|
||||
|
||||
import net.sf.acegisecurity.MockAuthenticationManager;
|
||||
import net.sf.acegisecurity.MockHttpServletRequest;
|
||||
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -54,7 +55,7 @@ public class CasPasswordHandlerTests extends TestCase {
|
|||
handler.setAuthenticationManager(new MockAuthenticationManager(false));
|
||||
handler.afterPropertiesSet();
|
||||
|
||||
assertFalse(handler.authenticate(new MockHttpServletRequest("/"),
|
||||
assertFalse(handler.authenticate(new MockHttpServletRequest(),
|
||||
"username", "password"));
|
||||
}
|
||||
|
||||
|
@ -84,16 +85,15 @@ public class CasPasswordHandlerTests extends TestCase {
|
|||
handler.afterPropertiesSet();
|
||||
|
||||
// If empty or null username we return false
|
||||
assertFalse(handler.authenticate(new MockHttpServletRequest("/"), "",
|
||||
assertFalse(handler.authenticate(new MockHttpServletRequest(), "",
|
||||
"password"));
|
||||
assertFalse(handler.authenticate(new MockHttpServletRequest("/"), null,
|
||||
assertFalse(handler.authenticate(new MockHttpServletRequest(), null,
|
||||
"password"));
|
||||
|
||||
// We authenticate with null passwords (they might not have one)
|
||||
assertTrue(handler.authenticate(new MockHttpServletRequest("/"),
|
||||
"user", null));
|
||||
assertTrue(handler.authenticate(new MockHttpServletRequest("/"),
|
||||
"user", ""));
|
||||
assertTrue(handler.authenticate(new MockHttpServletRequest(), "user",
|
||||
null));
|
||||
assertTrue(handler.authenticate(new MockHttpServletRequest(), "user", ""));
|
||||
}
|
||||
|
||||
public void testNormalOperation() throws Exception {
|
||||
|
@ -101,7 +101,7 @@ public class CasPasswordHandlerTests extends TestCase {
|
|||
handler.setAuthenticationManager(new MockAuthenticationManager(true));
|
||||
handler.afterPropertiesSet();
|
||||
|
||||
assertTrue(handler.authenticate(new MockHttpServletRequest("/"),
|
||||
assertTrue(handler.authenticate(new MockHttpServletRequest(),
|
||||
"username", "password"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,10 +19,11 @@ import junit.framework.TestCase;
|
|||
|
||||
import net.sf.acegisecurity.GrantedAuthority;
|
||||
import net.sf.acegisecurity.GrantedAuthorityImpl;
|
||||
import net.sf.acegisecurity.MockHttpServletRequest;
|
||||
import net.sf.acegisecurity.adapters.MockPrincipal;
|
||||
import net.sf.acegisecurity.adapters.PrincipalAcegiUserToken;
|
||||
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
|
||||
import java.security.Principal;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
@ -68,8 +69,7 @@ public class JbossIntegrationFilterTests extends TestCase {
|
|||
JbossIntegrationFilter filter = new MockJbossIntegrationFilter(new MockInitialContext(
|
||||
makeIntoSubject(principal)));
|
||||
|
||||
Object result = filter.extractFromContainer(new MockHttpServletRequest(
|
||||
null, null));
|
||||
Object result = filter.extractFromContainer(new MockHttpServletRequest());
|
||||
|
||||
if (!(result instanceof PrincipalAcegiUserToken)) {
|
||||
fail("Should have returned PrincipalAcegiUserToken");
|
||||
|
@ -78,8 +78,10 @@ public class JbossIntegrationFilterTests extends TestCase {
|
|||
PrincipalAcegiUserToken castResult = (PrincipalAcegiUserToken) result;
|
||||
assertEquals(principal, result);
|
||||
|
||||
filter.commitToContainer(new MockHttpServletRequest(principal, null),
|
||||
principal);
|
||||
MockHttpServletRequest mockRequest = new MockHttpServletRequest();
|
||||
mockRequest.setUserPrincipal(principal);
|
||||
|
||||
filter.commitToContainer(mockRequest, principal);
|
||||
}
|
||||
|
||||
public void testReturnsNullIfContextReturnsSomethingOtherThanASubject() {
|
||||
|
|
Loading…
Reference in New Issue