Search in sources :

Example 1 with DefaultSavedRequest

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

the class DefaultSavedRequestMixinTests method deserializeDefaultSavedRequest.

@Test
public void deserializeDefaultSavedRequest() throws IOException {
    DefaultSavedRequest request = (DefaultSavedRequest) mapper.readValue(REQUEST_JSON, Object.class);
    assertThat(request).isNotNull();
    assertThat(request.getCookies()).hasSize(1);
    assertThat(request.getLocales()).hasSize(1).contains(new Locale("en"));
    assertThat(request.getHeaderNames()).hasSize(1).contains("x-auth-token");
    assertThat(request.getHeaderValues("x-auth-token")).hasSize(1).contains("12");
}
Also used : Locale(java.util.Locale) DefaultSavedRequest(org.springframework.security.web.savedrequest.DefaultSavedRequest) Test(org.junit.Test)

Example 2 with DefaultSavedRequest

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

the class DefaultSavedRequestMixinTests method matchRequestBuildWithConstructorAndBuilder.

// @formatter:on
@Test
public void matchRequestBuildWithConstructorAndBuilder() {
    DefaultSavedRequest request = new DefaultSavedRequest.Builder().setCookies(Collections.singletonList(new SavedCookie(new Cookie("SESSION", "123456789")))).setHeaders(Collections.singletonMap("x-auth-token", Collections.singletonList("12"))).setScheme("http").setRequestURL("http://localhost").setServerName("localhost").setRequestURI("").setLocales(Collections.singletonList(new Locale("en"))).setContextPath("").setMethod("").setServletPath("").build();
    MockHttpServletRequest mockRequest = new MockHttpServletRequest();
    mockRequest.setCookies(new Cookie("SESSION", "123456789"));
    mockRequest.addHeader("x-auth-token", "12");
    assert request.doesRequestMatch(mockRequest, new PortResolverImpl());
}
Also used : SavedCookie(org.springframework.security.web.savedrequest.SavedCookie) Cookie(javax.servlet.http.Cookie) Locale(java.util.Locale) PortResolverImpl(org.springframework.security.web.PortResolverImpl) SavedCookie(org.springframework.security.web.savedrequest.SavedCookie) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) DefaultSavedRequest(org.springframework.security.web.savedrequest.DefaultSavedRequest) Test(org.junit.Test)

Example 3 with DefaultSavedRequest

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

the class DefaultSavedRequestTests method discardsIfNoneMatchHeader.

// SEC-1412
@Test
public void discardsIfNoneMatchHeader() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addHeader("If-None-Match", "somehashvalue");
    DefaultSavedRequest saved = new DefaultSavedRequest(request, new MockPortResolver(8080, 8443));
    assertThat(saved.getHeaderValues("if-none-match").isEmpty()).isTrue();
}
Also used : MockPortResolver(org.springframework.security.MockPortResolver) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) DefaultSavedRequest(org.springframework.security.web.savedrequest.DefaultSavedRequest) Test(org.junit.Test)

Example 4 with DefaultSavedRequest

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

the class DefaultSavedRequestTests method headersAreCaseInsensitive.

// SEC-308, SEC-315
@Test
public void headersAreCaseInsensitive() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addHeader("USER-aGenT", "Mozilla");
    DefaultSavedRequest saved = new DefaultSavedRequest(request, new MockPortResolver(8080, 8443));
    assertThat(saved.getHeaderValues("user-agent").get(0)).isEqualTo("Mozilla");
}
Also used : MockPortResolver(org.springframework.security.MockPortResolver) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) DefaultSavedRequest(org.springframework.security.web.savedrequest.DefaultSavedRequest) Test(org.junit.Test)

Example 5 with DefaultSavedRequest

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

the class DefaultSavedRequestTests method parametersAreCaseSensitive.

// SEC-3082
@Test
public void parametersAreCaseSensitive() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("AnotHerTest", "Hi dad");
    request.addParameter("thisisatest", "Hi mom");
    DefaultSavedRequest saved = new DefaultSavedRequest(request, new MockPortResolver(8080, 8443));
    assertThat(saved.getParameterValues("thisisatest")[0]).isEqualTo("Hi mom");
    assertThat(saved.getParameterValues("anothertest")).isNull();
}
Also used : MockPortResolver(org.springframework.security.MockPortResolver) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) DefaultSavedRequest(org.springframework.security.web.savedrequest.DefaultSavedRequest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 DefaultSavedRequest (org.springframework.security.web.savedrequest.DefaultSavedRequest)7 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)5 Locale (java.util.Locale)3 Cookie (javax.servlet.http.Cookie)3 MockPortResolver (org.springframework.security.MockPortResolver)3 SavedCookie (org.springframework.security.web.savedrequest.SavedCookie)3 PortResolverImpl (org.springframework.security.web.PortResolverImpl)2