From 183333d189056fd0aebe6cf6ffa08dc2bf3aa5bc Mon Sep 17 00:00:00 2001 From: Luke Taylor Date: Mon, 9 Aug 2010 16:55:30 +0100 Subject: [PATCH] SEC-1430: Forgot to commit changes to new ExceptionMappingAuthenticationFailureHandlerTests. --- ...pingAuthenticationFailureHandlerTests.java | 41 ++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/web/src/test/java/org/springframework/security/web/authentication/ExceptionMappingAuthenticationFailureHandlerTests.java b/web/src/test/java/org/springframework/security/web/authentication/ExceptionMappingAuthenticationFailureHandlerTests.java index 14419ebb98..8d00758960 100644 --- a/web/src/test/java/org/springframework/security/web/authentication/ExceptionMappingAuthenticationFailureHandlerTests.java +++ b/web/src/test/java/org/springframework/security/web/authentication/ExceptionMappingAuthenticationFailureHandlerTests.java @@ -1,11 +1,42 @@ package org.springframework.security.web.authentication; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.security.authentication.BadCredentialsException; + +import javax.servlet.ServletException; +import java.io.IOException; +import java.util.HashMap; + /** - * Created by IntelliJ IDEA. - * User: luke - * Date: Aug 8, 2010 - * Time: 5:13:18 PM - * To change this template use File | Settings | File Templates. + * @author Luke Taylor */ public class ExceptionMappingAuthenticationFailureHandlerTests { + + @Test + public void defaultTargetUrlIsUsedIfNoMappingExists() throws Exception { + ExceptionMappingAuthenticationFailureHandler fh = new ExceptionMappingAuthenticationFailureHandler(); + fh.setDefaultFailureUrl("/failed"); + MockHttpServletResponse response = new MockHttpServletResponse(); + fh.onAuthenticationFailure(new MockHttpServletRequest(), response, new BadCredentialsException("")); + + assertEquals("/failed", response.getRedirectedUrl()); + } + + @Test + public void exceptionMapIsUsedIfMappingExists() throws Exception { + ExceptionMappingAuthenticationFailureHandler fh = new ExceptionMappingAuthenticationFailureHandler(); + HashMap mapping = new HashMap(); + mapping.put("org.springframework.security.authentication.BadCredentialsException", "/badcreds"); + fh.setExceptionMappings(mapping); + fh.setDefaultFailureUrl("/failed"); + MockHttpServletResponse response = new MockHttpServletResponse(); + fh.onAuthenticationFailure(new MockHttpServletRequest(), response, new BadCredentialsException("")); + + assertEquals("/badcreds", response.getRedirectedUrl()); + } + }