Search in sources :

Example 1 with SavedRequestAwareWrapper

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");
}
Also used : Enumeration(java.util.Enumeration) SavedRequestAwareWrapper(org.springframework.security.web.savedrequest.SavedRequestAwareWrapper) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.Test)

Example 2 with SavedRequestAwareWrapper

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);
}
Also used : SavedRequestAwareWrapper(org.springframework.security.web.savedrequest.SavedRequestAwareWrapper) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test)

Example 3 with SavedRequestAwareWrapper

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");
}
Also used : SavedRequestAwareWrapper(org.springframework.security.web.savedrequest.SavedRequestAwareWrapper) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.Test)

Example 4 with SavedRequestAwareWrapper

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");
}
Also used : SavedRequestAwareWrapper(org.springframework.security.web.savedrequest.SavedRequestAwareWrapper) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.Test)

Example 5 with SavedRequestAwareWrapper

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();
}
Also used : SavedRequestAwareWrapper(org.springframework.security.web.savedrequest.SavedRequestAwareWrapper) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)11 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)11 SavedRequestAwareWrapper (org.springframework.security.web.savedrequest.SavedRequestAwareWrapper)11 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Enumeration (java.util.Enumeration)1 Cookie (javax.servlet.http.Cookie)1