2
0
Эх сурвалжийг харах

Refactored CAS test to remove dependency on core tests jar.

Luke Taylor 15 жил өмнө
parent
commit
a5ed2e579e

+ 0 - 7
cas/pom.xml

@@ -20,13 +20,6 @@
             <artifactId>spring-security-web</artifactId>
             <version>${project.version}</version>
         </dependency>
-        <dependency>
-            <groupId>org.springframework.security</groupId>
-            <artifactId>spring-security-core</artifactId>
-            <version>${project.version}</version>
-            <classifier>tests</classifier>
-            <scope>test</scope>
-        </dependency>
         <dependency>
             <groupId>javax.servlet</groupId>
             <artifactId>servlet-api</artifactId>

+ 22 - 23
cas/src/test/java/org/springframework/security/cas/web/CasAuthenticationFilterTests.java

@@ -15,15 +15,15 @@
 
 package org.springframework.security.cas.web;
 
-import junit.framework.TestCase;
-
-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 static org.junit.Assert.*;
 
+import org.junit.Test;
 import org.springframework.mock.web.MockHttpServletRequest;
 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
  * @version $Id$
  */
-public class CasAuthenticationFilterTests extends TestCase {
+public class CasAuthenticationFilterTests {
     //~ Methods ========================================================================================================
 
+    @Test
     public void testGetters() {
         CasAuthenticationFilter filter = new CasAuthenticationFilter();
         assertEquals("/j_spring_cas_security_check", filter.getFilterProcessesUrl());
     }
 
+    @Test
     public void testNormalOperation() throws Exception {
         MockHttpServletRequest request = new MockHttpServletRequest();
         request.addParameter("ticket", "ST-0-ER94xMJmn6pha35CQRoZ");
 
-        MockAuthenticationManager authMgr = new MockAuthenticationManager(true);
-
         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());
         assertTrue(result != null);
     }
 
-    public void testNullServiceTicketHandledGracefully()
-        throws Exception {
-        MockHttpServletRequest request = new MockHttpServletRequest();
-
-        MockAuthenticationManager authMgr = new MockAuthenticationManager(false);
-
+    @Test(expected=AuthenticationException.class)
+    public void testNullServiceTicketHandledGracefully() throws Exception {
         CasAuthenticationFilter filter = new CasAuthenticationFilter();
-        filter.setAuthenticationManager(authMgr);
+        filter.setAuthenticationManager(new AuthenticationManager() {
+            public Authentication authenticate(Authentication a) {
+                throw new BadCredentialsException("Rejected");
+            }
+        });
 
-        try {
-            filter.attemptAuthentication(request, new MockHttpServletResponse());
-            fail("Should have thrown AuthenticationException");
-        } catch (AuthenticationException expected) {
-            assertTrue(true);
-        }
+        filter.attemptAuthentication(new MockHttpServletRequest(), new MockHttpServletResponse());
     }
 }