From 1cf59b249ac96f4a645a543710fac1dd480da722 Mon Sep 17 00:00:00 2001 From: Luke Taylor Date: Sun, 16 Nov 2008 05:07:33 +0000 Subject: [PATCH] Added test class for DefaultLoginPageGeneratingFilter. --- ...DefaultLoginPageGeneratingFilterTests.java | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 core/src/test/java/org/springframework/security/ui/webapp/DefaultLoginPageGeneratingFilterTests.java diff --git a/core/src/test/java/org/springframework/security/ui/webapp/DefaultLoginPageGeneratingFilterTests.java b/core/src/test/java/org/springframework/security/ui/webapp/DefaultLoginPageGeneratingFilterTests.java new file mode 100644 index 0000000000..43ac0ff8d9 --- /dev/null +++ b/core/src/test/java/org/springframework/security/ui/webapp/DefaultLoginPageGeneratingFilterTests.java @@ -0,0 +1,60 @@ +package org.springframework.security.ui.webapp; + +import static org.junit.Assert.*; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.Test; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.security.Authentication; +import org.springframework.security.AuthenticationException; +import org.springframework.security.util.MockFilterChain; +import org.springframework.security.ui.AbstractProcessingFilter; +import org.springframework.security.ui.FilterChainOrder; + +/** + * + * @author Luke Taylor + * @version $Id$ + * @since 2.5 + */ +public class DefaultLoginPageGeneratingFilterTests { + + @Test + public void generatingPageWithAuthenticationProcessingFilterOnlyIsSuccessFul() throws Exception { + DefaultLoginPageGeneratingFilter filter = new DefaultLoginPageGeneratingFilter(new AuthenticationProcessingFilter()); + filter.doFilter(new MockHttpServletRequest("GET", "/spring_security_login"), new MockHttpServletResponse(), new MockFilterChain(false)); + filter.doFilter(new MockHttpServletRequest("GET", "/spring_security_login;pathparam=unused"), new MockHttpServletResponse(), new MockFilterChain(false)); + } + + + @Test + public void generatingPageWithOpenIdFilterOnlyIsSuccessFul() throws Exception { + DefaultLoginPageGeneratingFilter filter = new DefaultLoginPageGeneratingFilter(new MockProcessingFilter()); + filter.doFilter(new MockHttpServletRequest("GET", "/spring_security_login"), new MockHttpServletResponse(), new MockFilterChain(false)); + } + + private static class MockProcessingFilter extends AbstractProcessingFilter { + + @Override + public Authentication attemptAuthentication(HttpServletRequest request) throws AuthenticationException { + return null; + } + + @Override + public String getDefaultFilterProcessesUrl() { + return null; + } + + public int getOrder() { + return FilterChainOrder.AUTHENTICATION_PROCESSING_FILTER; + } + + public String getClaimedIdentityFieldName() { + return "unused"; + } + + } + +}