Search in sources :

Example 6 with MockHttpServletResponse

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);
}
Also used : FilterChain(javax.servlet.FilterChain) MockHttpServletResponse(com.thoughtworks.go.http.mocks.MockHttpServletResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with MockHttpServletResponse

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);
}
Also used : SecurityAuthConfigService(com.thoughtworks.go.server.service.SecurityAuthConfigService) AccessTokenBasedPluginAuthenticationProvider(com.thoughtworks.go.server.newsecurity.providers.AccessTokenBasedPluginAuthenticationProvider) SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) AccessTokenService(com.thoughtworks.go.server.service.AccessTokenService) SecurityService(com.thoughtworks.go.server.service.SecurityService) FilterChain(javax.servlet.FilterChain) TestingClock(com.thoughtworks.go.util.TestingClock) MockHttpServletResponse(com.thoughtworks.go.http.mocks.MockHttpServletResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with MockHttpServletResponse

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);
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) MockHttpServletRequest(com.thoughtworks.go.http.mocks.MockHttpServletRequest) MockHttpServletResponse(com.thoughtworks.go.http.mocks.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 9 with MockHttpServletResponse

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);
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) MockHttpServletRequest(com.thoughtworks.go.http.mocks.MockHttpServletRequest) MockHttpServletResponse(com.thoughtworks.go.http.mocks.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 10 with MockHttpServletResponse

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();
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) Answer(org.mockito.stubbing.Answer) MockHttpServletRequest(com.thoughtworks.go.http.mocks.MockHttpServletRequest) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MockHttpServletResponse(com.thoughtworks.go.http.mocks.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Aggregations

MockHttpServletResponse (com.thoughtworks.go.http.mocks.MockHttpServletResponse)30 MockHttpServletRequest (com.thoughtworks.go.http.mocks.MockHttpServletRequest)20 BeforeEach (org.junit.jupiter.api.BeforeEach)16 Test (org.junit.jupiter.api.Test)13 FilterChain (javax.servlet.FilterChain)11 SecurityService (com.thoughtworks.go.server.service.SecurityService)7 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)7 TestingClock (com.thoughtworks.go.util.TestingClock)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 UsernamePassword (com.thoughtworks.go.server.newsecurity.models.UsernamePassword)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 AnonymousAuthenticationProvider (com.thoughtworks.go.server.newsecurity.providers.AnonymousAuthenticationProvider)2 AuthorityGranter (com.thoughtworks.go.server.security.AuthorityGranter)2 HttpSession (javax.servlet.http.HttpSession)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Answer (org.mockito.stubbing.Answer)2 SavedRequest (org.springframework.security.web.savedrequest.SavedRequest)2 GsonBuilder (com.google.gson.GsonBuilder)1 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)1