Search in sources :

Example 6 with MockPortResolver

use of org.springframework.security.MockPortResolver in project spring-security by spring-projects.

the class RetryWithHttpsEntryPointTests method testOperationWhenTargetPortIsUnknown.

@Test
public void testOperationWhenTargetPortIsUnknown() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/bigWebApp");
    request.setQueryString("open=true");
    request.setScheme("http");
    request.setServerName("www.example.com");
    request.setServerPort(8768);
    MockHttpServletResponse response = new MockHttpServletResponse();
    RetryWithHttpsEntryPoint ep = new RetryWithHttpsEntryPoint();
    ep.setPortMapper(new PortMapperImpl());
    ep.setPortResolver(new MockPortResolver(8768, 1234));
    ep.commence(request, response);
    assertThat(response.getRedirectedUrl()).isEqualTo("/bigWebApp?open=true");
}
Also used : MockPortResolver(org.springframework.security.MockPortResolver) PortMapperImpl(org.springframework.security.web.PortMapperImpl) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) RetryWithHttpsEntryPoint(org.springframework.security.web.access.channel.RetryWithHttpsEntryPoint) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 7 with MockPortResolver

use of org.springframework.security.MockPortResolver in project spring-security by spring-projects.

the class RetryWithHttpEntryPointTests method testNormalOperationWithNullQueryString.

@Test
public void testNormalOperationWithNullQueryString() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/bigWebApp/hello");
    request.setScheme("https");
    request.setServerName("www.example.com");
    request.setServerPort(443);
    MockHttpServletResponse response = new MockHttpServletResponse();
    RetryWithHttpEntryPoint ep = new RetryWithHttpEntryPoint();
    ep.setPortMapper(new PortMapperImpl());
    ep.setPortResolver(new MockPortResolver(80, 443));
    ep.commence(request, response);
    assertThat(response.getRedirectedUrl()).isEqualTo("http://www.example.com/bigWebApp/hello");
}
Also used : MockPortResolver(org.springframework.security.MockPortResolver) PortMapperImpl(org.springframework.security.web.PortMapperImpl) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 8 with MockPortResolver

use of org.springframework.security.MockPortResolver 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 9 with MockPortResolver

use of org.springframework.security.MockPortResolver in project spring-security by spring-projects.

the class RetryWithHttpEntryPointTests method testOperationWhenTargetPortIsUnknown.

@Test
public void testOperationWhenTargetPortIsUnknown() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/bigWebApp");
    request.setQueryString("open=true");
    request.setScheme("https");
    request.setServerName("www.example.com");
    request.setServerPort(8768);
    MockHttpServletResponse response = new MockHttpServletResponse();
    RetryWithHttpEntryPoint ep = new RetryWithHttpEntryPoint();
    ep.setPortMapper(new PortMapperImpl());
    ep.setPortResolver(new MockPortResolver(8768, 1234));
    ep.commence(request, response);
    assertThat(response.getRedirectedUrl()).isEqualTo("/bigWebApp?open=true");
}
Also used : MockPortResolver(org.springframework.security.MockPortResolver) PortMapperImpl(org.springframework.security.web.PortMapperImpl) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 10 with MockPortResolver

use of org.springframework.security.MockPortResolver in project spring-security by spring-projects.

the class LoginUrlAuthenticationEntryPointTests method testNormalOperation.

@Test
public void testNormalOperation() throws Exception {
    LoginUrlAuthenticationEntryPoint ep = new LoginUrlAuthenticationEntryPoint("/hello");
    ep.setPortMapper(new PortMapperImpl());
    ep.setPortResolver(new MockPortResolver(80, 443));
    ep.afterPropertiesSet();
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("/some_path");
    request.setContextPath("/bigWebApp");
    request.setScheme("http");
    request.setServerName("www.example.com");
    request.setContextPath("/bigWebApp");
    request.setServerPort(80);
    MockHttpServletResponse response = new MockHttpServletResponse();
    ep.commence(request, response, null);
    assertThat(response.getRedirectedUrl()).isEqualTo("http://www.example.com/bigWebApp/hello");
}
Also used : MockPortResolver(org.springframework.security.MockPortResolver) PortMapperImpl(org.springframework.security.web.PortMapperImpl) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)18 MockPortResolver (org.springframework.security.MockPortResolver)18 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)16 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)13 PortMapperImpl (org.springframework.security.web.PortMapperImpl)13 RetryWithHttpsEntryPoint (org.springframework.security.web.access.channel.RetryWithHttpsEntryPoint)5 DefaultSavedRequest (org.springframework.security.web.savedrequest.DefaultSavedRequest)3 HashMap (java.util.HashMap)2 FilterChain (javax.servlet.FilterChain)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)1 HttpSessionRequestCache (org.springframework.security.web.savedrequest.HttpSessionRequestCache)1