1 package com.atlassian.seraph.auth; 2 3 import junit.framework.TestCase; 4 import com.atlassian.seraph.config.SecurityConfigImpl; 5 import com.atlassian.seraph.config.ConfigurationException; 6 import com.atlassian.seraph.interceptor.LogoutInterceptor; 7 import com.atlassian.seraph.interceptor.Interceptor; 8 import com.mockobjects.dynamic.Mock; 9 import com.mockobjects.dynamic.C; 10 11 import javax.servlet.http.HttpServletRequest ; 12 import javax.servlet.http.HttpSession ; 13 import javax.servlet.http.HttpServletResponse ; 14 15 public class TestDefaultAuthenticator extends TestCase 16 { 17 public TestDefaultAuthenticator(String string) 18 { 19 super(string); 20 } 21 22 public void testLogout() throws ConfigurationException, AuthenticatorException 23 { 24 Mock logoutInterceptor = new Mock(LogoutInterceptor.class); 26 Mock request = new Mock(HttpServletRequest .class); 27 Mock response = new Mock(HttpServletResponse .class); 28 Mock session = new Mock(HttpSession .class); 29 30 SecurityConfigImpl config = SecurityConfigImpl.getInstance("test-seraph-config.xml"); 31 32 HttpServletRequest requestProxy = (HttpServletRequest )request.proxy(); 34 HttpServletResponse responseProxy = (HttpServletResponse )response.proxy(); 35 request.expectAndReturn("getSession", session.proxy()); 36 request.expectAndReturn("getSession", session.proxy()); 37 request.expectAndReturn("getContextPath", ""); 38 39 session.expect("setAttribute", C.args(C.eq(DefaultAuthenticator.LOGGED_IN_KEY), C.IS_NULL)); 40 session.expect("setAttribute", C.args(C.eq(DefaultAuthenticator.LOGGED_OUT_KEY), C.eq(Boolean.TRUE))); 41 42 logoutInterceptor.expect("beforeLogout", C.ANY_ARGS); 43 logoutInterceptor.expect("afterLogout", C.ANY_ARGS); 44 config.addInterceptor((Interceptor)logoutInterceptor.proxy()); 45 46 Authenticator auth = config.getAuthenticator(); 48 auth.logout(requestProxy, null); 49 50 request.verify(); 52 response.verify(); 53 session.verify(); 54 logoutInterceptor.verify(); 55 } 56 } 57 | Popular Tags |