use of com.thoughtworks.go.http.mocks.MockHttpServletResponse in project gocd by gocd.
the class RememberLastRequestUrlFilterChainTest method setUp.
@BeforeEach
void setUp() {
response = new MockHttpServletResponse();
filter = new RememberLastRequestUrlFilterChain();
filterChain = mock(FilterChain.class);
}
use of com.thoughtworks.go.http.mocks.MockHttpServletResponse in project gocd by gocd.
the class AccessTokenAuthenticationFilterTest method setUp.
@BeforeEach
void setUp() throws Exception {
clock = new TestingClock();
securityService = mock(SecurityService.class);
accessTokenService = mock(AccessTokenService.class);
authenticationProvider = mock(AccessTokenBasedPluginAuthenticationProvider.class);
securityAuthConfigService = mock(SecurityAuthConfigService.class);
response = new MockHttpServletResponse();
filterChain = mock(FilterChain.class);
filter = new AccessTokenAuthenticationFilter(securityService, accessTokenService, securityAuthConfigService, authenticationProvider);
accessToken = randomAccessTokenForUser(BOB);
when(accessTokenService.findByAccessToken(TOKEN)).thenReturn(accessToken);
authConfig = new SecurityAuthConfig(accessToken.getAuthConfigId(), PLUGIN_ID);
when(securityAuthConfigService.findProfile(accessToken.getAuthConfigId())).thenReturn(authConfig);
}
use of com.thoughtworks.go.http.mocks.MockHttpServletResponse 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.MockHttpServletResponse 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.MockHttpServletResponse 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();
}
Aggregations