Search in sources :

Example 6 with SavedRequestAwareWrapper

use of org.springframework.security.web.savedrequest.SavedRequestAwareWrapper in project spring-security by spring-projects.

the class SavedRequestAwareWrapperTests method getParameterValuesReturnsCombinedSavedAndWrappedRequestValues.

@Test
public void getParameterValuesReturnsCombinedSavedAndWrappedRequestValues() {
    MockHttpServletRequest savedRequest = new MockHttpServletRequest();
    savedRequest.setParameter("action", "foo");
    MockHttpServletRequest wrappedRequest = new MockHttpServletRequest();
    SavedRequestAwareWrapper wrapper = createWrapper(savedRequest, wrappedRequest);
    assertThat(wrapper.getParameterValues("action")).isEqualTo(new Object[] { "foo" });
    wrappedRequest.setParameter("action", "bar");
    assertThat(wrapper.getParameterValues("action")).isEqualTo(new Object[] { "bar", "foo" });
    // Check map is consistent
    String[] valuesFromMap = (String[]) wrapper.getParameterMap().get("action");
    assertThat(valuesFromMap.length).isEqualTo(2);
    assertThat(valuesFromMap[0]).isEqualTo("bar");
}
Also used : SavedRequestAwareWrapper(org.springframework.security.web.savedrequest.SavedRequestAwareWrapper) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.Test)

Example 7 with SavedRequestAwareWrapper

use of org.springframework.security.web.savedrequest.SavedRequestAwareWrapper in project spring-security by spring-projects.

the class SavedRequestAwareWrapperTests method correctHttpMethodIsReturned.

@Test
public void correctHttpMethodIsReturned() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("PUT", "/notused");
    SavedRequestAwareWrapper wrapper = createWrapper(request, new MockHttpServletRequest("GET", "/notused"));
    assertThat(wrapper.getMethod()).isEqualTo("PUT");
}
Also used : SavedRequestAwareWrapper(org.springframework.security.web.savedrequest.SavedRequestAwareWrapper) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.Test)

Example 8 with SavedRequestAwareWrapper

use of org.springframework.security.web.savedrequest.SavedRequestAwareWrapper in project spring-security by spring-projects.

the class SavedRequestAwareWrapperTests method savedRequestCookiesAreIgnored.

// SEC-2569
@Test
public void savedRequestCookiesAreIgnored() throws Exception {
    MockHttpServletRequest newRequest = new MockHttpServletRequest();
    newRequest.setCookies(new Cookie[] { new Cookie("cookie", "fromnew") });
    MockHttpServletRequest savedRequest = new MockHttpServletRequest();
    savedRequest.setCookies(new Cookie[] { new Cookie("cookie", "fromsaved") });
    SavedRequestAwareWrapper wrapper = createWrapper(savedRequest, newRequest);
    assertThat(wrapper.getCookies().length).isEqualTo(1);
    assertThat(wrapper.getCookies()[0].getValue()).isEqualTo("fromnew");
}
Also used : Cookie(javax.servlet.http.Cookie) SavedRequestAwareWrapper(org.springframework.security.web.savedrequest.SavedRequestAwareWrapper) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.Test)

Example 9 with SavedRequestAwareWrapper

use of org.springframework.security.web.savedrequest.SavedRequestAwareWrapper in project spring-security by spring-projects.

the class SavedRequestAwareWrapperTests method savedRequestHeadersTakePrecedence.

@Test
public void savedRequestHeadersTakePrecedence() {
    MockHttpServletRequest savedRequest = new MockHttpServletRequest();
    savedRequest.addHeader("Authorization", "foo");
    MockHttpServletRequest wrappedRequest = new MockHttpServletRequest();
    wrappedRequest.addHeader("Authorization", "bar");
    SavedRequestAwareWrapper wrapper = createWrapper(savedRequest, wrappedRequest);
    assertThat(wrapper.getHeader("Authorization")).isEqualTo("foo");
}
Also used : SavedRequestAwareWrapper(org.springframework.security.web.savedrequest.SavedRequestAwareWrapper) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.Test)

Example 10 with SavedRequestAwareWrapper

use of org.springframework.security.web.savedrequest.SavedRequestAwareWrapper in project spring-security by spring-projects.

the class SavedRequestAwareWrapperTests method savedRequestDoesntCreateDuplicateParams.

@Test
public void savedRequestDoesntCreateDuplicateParams() {
    MockHttpServletRequest savedRequest = new MockHttpServletRequest();
    savedRequest.setParameter("action", "foo");
    MockHttpServletRequest wrappedRequest = new MockHttpServletRequest();
    wrappedRequest.setParameter("action", "foo");
    SavedRequestAwareWrapper wrapper = createWrapper(savedRequest, wrappedRequest);
    assertThat(wrapper.getParameterValues("action").length).isEqualTo(1);
    assertThat(wrapper.getParameterMap()).hasSize(1);
    assertThat(((String[]) wrapper.getParameterMap().get("action")).length).isEqualTo(1);
}
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