use of org.springframework.security.web.savedrequest.SavedRequestAwareWrapper in project spring-security by spring-projects.
the class SavedRequestAwareWrapperTests method savedRequesthHeaderIsReturnedIfSavedRequestIsSet.
@Test
@SuppressWarnings("unchecked")
public void savedRequesthHeaderIsReturnedIfSavedRequestIsSet() throws Exception {
MockHttpServletRequest savedRequest = new MockHttpServletRequest();
savedRequest.addHeader("header", "savedheader");
SavedRequestAwareWrapper wrapper = createWrapper(savedRequest, new MockHttpServletRequest());
assertThat(wrapper.getHeader("nonexistent")).isNull();
Enumeration headers = wrapper.getHeaders("nonexistent");
assertThat(headers.hasMoreElements()).isFalse();
assertThat(wrapper.getHeader("Header")).isEqualTo("savedheader");
headers = wrapper.getHeaders("heaDer");
assertThat(headers.hasMoreElements()).isTrue();
assertThat(headers.nextElement()).isEqualTo("savedheader");
assertThat(headers.hasMoreElements()).isFalse();
assertThat(wrapper.getHeaderNames().hasMoreElements()).isTrue();
assertThat(wrapper.getHeaderNames().nextElement()).isEqualTo("header");
}
use of org.springframework.security.web.savedrequest.SavedRequestAwareWrapper in project spring-security by spring-projects.
the class SavedRequestAwareWrapperTests method expecteDateHeaderIsReturnedFromSavedRequest.
@Test
public void expecteDateHeaderIsReturnedFromSavedRequest() throws Exception {
SimpleDateFormat formatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
String nowString = FastHttpDateFormat.getCurrentDate();
Date now = formatter.parse(nowString);
MockHttpServletRequest request = new MockHttpServletRequest();
request.addHeader("header", nowString);
SavedRequestAwareWrapper wrapper = createWrapper(request, new MockHttpServletRequest());
assertThat(wrapper.getDateHeader("header")).isEqualTo(now.getTime());
assertThat(wrapper.getDateHeader("nonexistent")).isEqualTo(-1L);
}
use of org.springframework.security.web.savedrequest.SavedRequestAwareWrapper in project spring-security by spring-projects.
the class SavedRequestAwareWrapperTests method invalidDateHeaderIsRejected.
@Test(expected = IllegalArgumentException.class)
public void invalidDateHeaderIsRejected() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addHeader("header", "notadate");
SavedRequestAwareWrapper wrapper = createWrapper(request, new MockHttpServletRequest());
wrapper.getDateHeader("header");
}
use of org.springframework.security.web.savedrequest.SavedRequestAwareWrapper in project spring-security by spring-projects.
the class SavedRequestAwareWrapperTests method wrappedRequestParameterTakesPrecedenceOverSavedRequest.
@Test
public /*
* SEC-830. Assume we have a request to /someUrl?action=foo (the saved request) and
* then RequestDispatcher.forward() it to /someUrl?action=bar. What should action
* parameter be before and during the forward?
*/
void wrappedRequestParameterTakesPrecedenceOverSavedRequest() {
MockHttpServletRequest savedRequest = new MockHttpServletRequest();
savedRequest.setParameter("action", "foo");
MockHttpServletRequest wrappedRequest = new MockHttpServletRequest();
SavedRequestAwareWrapper wrapper = createWrapper(savedRequest, wrappedRequest);
assertThat(wrapper.getParameter("action")).isEqualTo("foo");
// The request after forward
wrappedRequest.setParameter("action", "bar");
assertThat(wrapper.getParameter("action")).isEqualTo("bar");
// Both values should be set, but "bar" should be first
assertThat(wrapper.getParameterValues("action").length).isEqualTo(2);
assertThat(wrapper.getParameterValues("action")[0]).isEqualTo("bar");
}
use of org.springframework.security.web.savedrequest.SavedRequestAwareWrapper in project spring-security by spring-projects.
the class SavedRequestAwareWrapperTests method getParameterValuesReturnsNullIfParameterIsntSet.
@Test
public void getParameterValuesReturnsNullIfParameterIsntSet() {
SavedRequestAwareWrapper wrapper = createWrapper(new MockHttpServletRequest(), new MockHttpServletRequest());
assertThat(wrapper.getParameterValues("action")).isNull();
assertThat(wrapper.getParameterMap().get("action")).isNull();
}
Aggregations