Search in sources :

Example 21 with MockFilterChain

use of org.springframework.mock.web.MockFilterChain in project spring-security by spring-projects.

the class WebAsyncManagerIntegrationFilterTests method setUp.

@Before
public void setUp() {
    when(asyncWebRequest.getNativeRequest(HttpServletRequest.class)).thenReturn(request);
    when(request.getRequestURI()).thenReturn("/");
    filterChain = new MockFilterChain();
    threadFactory = new JoinableThreadFactory();
    SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor();
    executor.setThreadFactory(threadFactory);
    asyncManager = WebAsyncUtils.getAsyncManager(request);
    asyncManager.setAsyncWebRequest(asyncWebRequest);
    asyncManager.setTaskExecutor(executor);
    when(request.getAttribute(WebAsyncUtils.WEB_ASYNC_MANAGER_ATTRIBUTE)).thenReturn(asyncManager);
    filter = new WebAsyncManagerIntegrationFilter();
}
Also used : SimpleAsyncTaskExecutor(org.springframework.core.task.SimpleAsyncTaskExecutor) MockFilterChain(org.springframework.mock.web.MockFilterChain) Before(org.junit.Before)

Example 22 with MockFilterChain

use of org.springframework.mock.web.MockFilterChain in project spring-security by spring-projects.

the class HeaderWriterFilterTests method additionalHeadersShouldBeAddedToTheResponse.

@Test
public void additionalHeadersShouldBeAddedToTheResponse() throws Exception {
    List<HeaderWriter> headerWriters = new ArrayList<HeaderWriter>();
    headerWriters.add(writer1);
    headerWriters.add(writer2);
    HeaderWriterFilter filter = new HeaderWriterFilter(headerWriters);
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    MockFilterChain filterChain = new MockFilterChain();
    filter.doFilter(request, response, filterChain);
    verify(writer1).writeHeaders(request, response);
    verify(writer2).writeHeaders(request, response);
    // verify the filterChain
    assertThat(filterChain.getRequest()).isEqualTo(request);
// continued
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ArrayList(java.util.ArrayList) HeaderWriter(org.springframework.security.web.header.HeaderWriter) HeaderWriterFilter(org.springframework.security.web.header.HeaderWriterFilter) MockFilterChain(org.springframework.mock.web.MockFilterChain) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 23 with MockFilterChain

use of org.springframework.mock.web.MockFilterChain in project spring-security by spring-projects.

the class FilterSecurityMetadataSourceBeanDefinitionParserTests method createFilterInvocation.

private FilterInvocation createFilterInvocation(String path, String method) {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI(null);
    request.setMethod(method);
    request.setServletPath(path);
    return new FilterInvocation(request, new MockHttpServletResponse(), new MockFilterChain());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) FilterInvocation(org.springframework.security.web.FilterInvocation) MockFilterChain(org.springframework.mock.web.MockFilterChain) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Example 24 with MockFilterChain

use of org.springframework.mock.web.MockFilterChain in project spring-security by spring-projects.

the class SessionManagementConfigServlet31Tests method setup.

@Before
public void setup() {
    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();
    chain = new MockFilterChain();
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockFilterChain(org.springframework.mock.web.MockFilterChain) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Before(org.junit.Before)

Example 25 with MockFilterChain

use of org.springframework.mock.web.MockFilterChain in project spring-security by spring-projects.

the class CustomHttpSecurityConfigurerTests method setup.

@Before
public void setup() {
    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();
    chain = new MockFilterChain();
    request.setMethod("GET");
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockFilterChain(org.springframework.mock.web.MockFilterChain) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Before(org.junit.Before)

Aggregations

MockFilterChain (org.springframework.mock.web.MockFilterChain)103 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)102 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)102 Test (org.junit.Test)72 ServletRequest (javax.servlet.ServletRequest)28 ServletResponse (javax.servlet.ServletResponse)28 IOException (java.io.IOException)24 ServletException (javax.servlet.ServletException)24 HttpServletResponse (javax.servlet.http.HttpServletResponse)22 NestedServletException (org.springframework.web.util.NestedServletException)19 Before (org.junit.Before)17 ErrorPage (org.springframework.boot.web.server.ErrorPage)15 HttpServletResponseWrapper (javax.servlet.http.HttpServletResponseWrapper)14 MockFilterConfig (org.springframework.mock.web.MockFilterConfig)11 AuthenticationManager (org.springframework.security.authentication.AuthenticationManager)11 HttpServletRequest (javax.servlet.http.HttpServletRequest)10 MockHttpSession (org.springframework.mock.web.MockHttpSession)9 MockServletContext (org.springframework.mock.web.MockServletContext)9 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)9 WebStatFilter (com.alibaba.druid.support.http.WebStatFilter)8