mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-30 15:52:15 +00:00
Refactored CAS test to remove dependency on core tests jar.
This commit is contained in:
parent
3469a8d4a3
commit
a5ed2e579e
@ -20,13 +20,6 @@
|
|||||||
<artifactId>spring-security-web</artifactId>
|
<artifactId>spring-security-web</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.security</groupId>
|
|
||||||
<artifactId>spring-security-core</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
<classifier>tests</classifier>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.servlet</groupId>
|
<groupId>javax.servlet</groupId>
|
||||||
<artifactId>servlet-api</artifactId>
|
<artifactId>servlet-api</artifactId>
|
||||||
|
@ -15,15 +15,15 @@
|
|||||||
|
|
||||||
package org.springframework.security.cas.web;
|
package org.springframework.security.cas.web;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import org.springframework.security.MockAuthenticationManager;
|
|
||||||
import org.springframework.security.cas.web.CasAuthenticationFilter;
|
|
||||||
import org.springframework.security.core.Authentication;
|
|
||||||
import org.springframework.security.core.AuthenticationException;
|
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
import org.springframework.mock.web.MockHttpServletRequest;
|
import org.springframework.mock.web.MockHttpServletRequest;
|
||||||
import org.springframework.mock.web.MockHttpServletResponse;
|
import org.springframework.mock.web.MockHttpServletResponse;
|
||||||
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
|
import org.springframework.security.authentication.BadCredentialsException;
|
||||||
|
import org.springframework.security.core.Authentication;
|
||||||
|
import org.springframework.security.core.AuthenticationException;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,41 +32,40 @@ import org.springframework.mock.web.MockHttpServletResponse;
|
|||||||
* @author Ben Alex
|
* @author Ben Alex
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class CasAuthenticationFilterTests extends TestCase {
|
public class CasAuthenticationFilterTests {
|
||||||
//~ Methods ========================================================================================================
|
//~ Methods ========================================================================================================
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testGetters() {
|
public void testGetters() {
|
||||||
CasAuthenticationFilter filter = new CasAuthenticationFilter();
|
CasAuthenticationFilter filter = new CasAuthenticationFilter();
|
||||||
assertEquals("/j_spring_cas_security_check", filter.getFilterProcessesUrl());
|
assertEquals("/j_spring_cas_security_check", filter.getFilterProcessesUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testNormalOperation() throws Exception {
|
public void testNormalOperation() throws Exception {
|
||||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||||
request.addParameter("ticket", "ST-0-ER94xMJmn6pha35CQRoZ");
|
request.addParameter("ticket", "ST-0-ER94xMJmn6pha35CQRoZ");
|
||||||
|
|
||||||
MockAuthenticationManager authMgr = new MockAuthenticationManager(true);
|
|
||||||
|
|
||||||
CasAuthenticationFilter filter = new CasAuthenticationFilter();
|
CasAuthenticationFilter filter = new CasAuthenticationFilter();
|
||||||
filter.setAuthenticationManager(authMgr);
|
filter.setAuthenticationManager(new AuthenticationManager() {
|
||||||
|
public Authentication authenticate(Authentication a) {
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
Authentication result = filter.attemptAuthentication(request, new MockHttpServletResponse());
|
Authentication result = filter.attemptAuthentication(request, new MockHttpServletResponse());
|
||||||
assertTrue(result != null);
|
assertTrue(result != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNullServiceTicketHandledGracefully()
|
@Test(expected=AuthenticationException.class)
|
||||||
throws Exception {
|
public void testNullServiceTicketHandledGracefully() throws Exception {
|
||||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
|
||||||
|
|
||||||
MockAuthenticationManager authMgr = new MockAuthenticationManager(false);
|
|
||||||
|
|
||||||
CasAuthenticationFilter filter = new CasAuthenticationFilter();
|
CasAuthenticationFilter filter = new CasAuthenticationFilter();
|
||||||
filter.setAuthenticationManager(authMgr);
|
filter.setAuthenticationManager(new AuthenticationManager() {
|
||||||
|
public Authentication authenticate(Authentication a) {
|
||||||
try {
|
throw new BadCredentialsException("Rejected");
|
||||||
filter.attemptAuthentication(request, new MockHttpServletResponse());
|
|
||||||
fail("Should have thrown AuthenticationException");
|
|
||||||
} catch (AuthenticationException expected) {
|
|
||||||
assertTrue(true);
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
filter.attemptAuthentication(new MockHttpServletRequest(), new MockHttpServletResponse());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user