use of com.thoughtworks.go.http.mocks.MockHttpServletRequest in project gocd by gocd.
the class CreateSessionFilterChainTest method setUp.
@BeforeEach
void setUp() throws Exception {
response = new MockHttpServletResponse();
request = new MockHttpServletRequest();
apiSessionReduceIdleTimeoutFilter = spy(new ApiSessionReduceIdleTimeoutFilter(new SystemEnvironment()));
agentSessionReduceIdleTimeoutFilter = spy(new AgentSessionReduceIdleTimeoutFilter(new SystemEnvironment()));
alwaysCreateSessionFilter = spy(new AlwaysCreateSessionFilter());
}
use of com.thoughtworks.go.http.mocks.MockHttpServletRequest in project gocd by gocd.
the class AgentSessionReduceIdleTimeoutFilterTest method shouldNotReduceSessionMaxInactiveIntervalWhenSessionAlreadyExist.
@Test
public void shouldNotReduceSessionMaxInactiveIntervalWhenSessionAlreadyExist() throws IOException, ServletException {
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockHttpServletResponse response = new MockHttpServletResponse();
final SystemEnvironment systemEnvironment = mock(SystemEnvironment.class);
assertThat(request.getSession()).isNotNull();
when(systemEnvironment.get(SystemEnvironment.AGENT_REQUEST_IDLE_TIMEOUT_IN_SECONDS)).thenReturn(30);
new AgentSessionReduceIdleTimeoutFilter(systemEnvironment).doFilter(request, response, filterChain);
verify(filterChain).doFilter(request, response);
assertThat(request.getSession(false).getMaxInactiveInterval()).isEqualTo(0);
}
use of com.thoughtworks.go.http.mocks.MockHttpServletRequest in project gocd by gocd.
the class ApiSessionReduceIdleTimeoutFilterTest method shouldNotReduceSessionMaxInactiveIntervalWhenSessionAlreadyExist.
@Test
public void shouldNotReduceSessionMaxInactiveIntervalWhenSessionAlreadyExist() throws IOException, ServletException {
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockHttpServletResponse response = new MockHttpServletResponse();
final SystemEnvironment systemEnvironment = mock(SystemEnvironment.class);
assertThat(request.getSession()).isNotNull();
when(systemEnvironment.get(SystemEnvironment.API_REQUEST_IDLE_TIMEOUT_IN_SECONDS)).thenReturn(10);
new ApiSessionReduceIdleTimeoutFilter(systemEnvironment).doFilter(request, response, filterChain);
verify(filterChain).doFilter(request, response);
assertThat(request.getSession(false).getMaxInactiveInterval()).isEqualTo(0);
}
use of com.thoughtworks.go.http.mocks.MockHttpServletRequest in project gocd by gocd.
the class ApiSessionReduceIdleTimeoutFilterTest method shouldReduceSessionTimeoutWhenAppliedAndNewSessionIsCreatedAfterApplyingFilter.
@Test
public void shouldReduceSessionTimeoutWhenAppliedAndNewSessionIsCreatedAfterApplyingFilter() throws IOException, ServletException {
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockHttpServletResponse response = new MockHttpServletResponse();
final SystemEnvironment systemEnvironment = mock(SystemEnvironment.class);
when(systemEnvironment.get(SystemEnvironment.API_REQUEST_IDLE_TIMEOUT_IN_SECONDS)).thenReturn(10);
assertThat(request.getSession(false)).isNull();
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
request.getSession(true);
return null;
}
}).when(filterChain).doFilter(request, response);
new ApiSessionReduceIdleTimeoutFilter(systemEnvironment).doFilter(request, response, filterChain);
verify(filterChain).doFilter(request, response);
assertThat(request.getSession(false).getMaxInactiveInterval()).isEqualTo(10);
assertThat(request.getSession(false)).isNotNull();
}
use of com.thoughtworks.go.http.mocks.MockHttpServletRequest in project gocd by gocd.
the class DenyAllAccessFilterTest method denyAllAccessWhenFilterIsCalled.
@Test
void denyAllAccessWhenFilterIsCalled() throws ServletException, IOException {
final MockHttpServletResponse response = new MockHttpServletResponse();
final MockHttpServletRequest request = new MockHttpServletRequest();
new DenyAllAccessFilter().doFilter(request, response, mock(FilterChain.class));
MockHttpServletResponseAssert.assertThat(response).isForbidden();
}
Aggregations