SEC-1648: Implemented Rob's suggestion to use a null value for the targetUrlParameter rather than a boolean property. It should thus only be used if this value is set.

This commit is contained in:
Luke Taylor
2011-01-12 13:26:05 +00:00
parent 6de2197c0f
commit eeb466b613
2 changed files with 24 additions and 20 deletions

View File

@@ -42,20 +42,34 @@ public class SimpleUrlAuthenticationSuccessHandlerTests {
* SEC-213
*/
@Test
public void targetUrlParameterIsUsedIfPresent() throws Exception {
public void targetUrlParameterIsUsedIfPresentAndParameterNameIsSet() throws Exception {
SimpleUrlAuthenticationSuccessHandler ash = new SimpleUrlAuthenticationSuccessHandler("/defaultTarget");
ash.setUseTargetUrlparameter(true);
ash.setTargetUrlParameter("targetUrl");
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
request.setParameter("targetUrl", "/target");
ash.onAuthenticationSuccess(request, response, mock(Authentication.class));
assertEquals("/defaultTarget", response.getRedirectedUrl());
// Try with parameter set
ash.setTargetUrlParameter("targetUrl");
response = new MockHttpServletResponse();
ash.onAuthenticationSuccess(request, response, mock(Authentication.class));
assertEquals("/target", response.getRedirectedUrl());
}
@Test
public void refererIsUsedIfUseRefererIsSet() throws Exception {
SimpleUrlAuthenticationSuccessHandler ash = new SimpleUrlAuthenticationSuccessHandler("/defaultTarget");
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
ash.setUseReferer(true);
request.addHeader("Referer", "http://www.springsource.com/");
ash.onAuthenticationSuccess(request, response, mock(Authentication.class));
assertEquals("http://www.springsource.com/", response.getRedirectedUrl());
}
/**
* SEC-297 fix.
*/