Search in sources :

Example 1 with MockHttpServletResponse

use of com.thoughtworks.go.http.mocks.MockHttpServletResponse in project gocd by gocd.

the class ReAuthenticationWithRedirectToLoginFilterTest method shouldInvokeHandler.

@Test
void shouldInvokeHandler() throws IOException {
    final ReAuthenticationWithRedirectToLoginFilter filter = new ReAuthenticationWithRedirectToLoginFilter(null, null, null, null, null, null);
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final String message = "foo";
    SavedRequest savedRequest = mock(SavedRequest.class);
    SessionUtils.saveRequest(request, savedRequest);
    HttpSession originalSession = request.getSession(true);
    filter.onAuthenticationFailure(request, response, message);
    assertThat(SessionUtils.getAuthenticationError(request)).isEqualTo("foo");
    assertThat(request.getSession(false)).isNotSameAs(originalSession);
    assertThat(SessionUtils.savedRequest(request)).isSameAs(savedRequest);
    assertThat(SessionUtils.hasAuthenticationToken(request)).isFalse();
    MockHttpServletResponseAssert.assertThat(response).redirectsTo("/go/auth/login");
}
Also used : MockHttpServletRequest(com.thoughtworks.go.http.mocks.MockHttpServletRequest) HttpSession(javax.servlet.http.HttpSession) MockHttpServletResponse(com.thoughtworks.go.http.mocks.MockHttpServletResponse) SavedRequest(org.springframework.security.web.savedrequest.SavedRequest) Test(org.junit.jupiter.api.Test)

Example 2 with MockHttpServletResponse

use of com.thoughtworks.go.http.mocks.MockHttpServletResponse in project gocd by gocd.

the class UserEnabledCheckFilterForApiRequestTest method setUp.

@BeforeEach
void setUp() {
    filter = new UserEnabledCheckFilterForApiRequest(null, null);
    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();
}
Also used : MockHttpServletRequest(com.thoughtworks.go.http.mocks.MockHttpServletRequest) MockHttpServletResponse(com.thoughtworks.go.http.mocks.MockHttpServletResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with MockHttpServletResponse

use of com.thoughtworks.go.http.mocks.MockHttpServletResponse in project gocd by gocd.

the class VerifyAuthorityFilterTest method setUp.

@BeforeEach
void setUp() {
    request = HttpRequestBuilder.GET("/foo").build();
    response = new MockHttpServletResponse();
    filterChain = mock(FilterChain.class);
    responseHandler = mock(ResponseHandler.class);
}
Also used : ResponseHandler(com.thoughtworks.go.server.newsecurity.handlers.ResponseHandler) FilterChain(javax.servlet.FilterChain) MockHttpServletResponse(com.thoughtworks.go.http.mocks.MockHttpServletResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with MockHttpServletResponse

use of com.thoughtworks.go.http.mocks.MockHttpServletResponse in project gocd by gocd.

the class DashBoardControllerTest method shouldErrorWhenStandbyNotAddedAsOAuthClient.

@Test
void shouldErrorWhenStandbyNotAddedAsOAuthClient() {
    when(authToken.isValid()).thenReturn(true);
    when(authToken.toUsernamePassword()).thenReturn(new UsernamePassword(USERNAME, PASSWORD));
    when(authToken.forHttp()).thenReturn(CREDENTIALS);
    when(addOnConfiguration.isServerInStandby()).thenReturn(true);
    HttpServletRequest request = HttpRequestBuilder.GET("").withBasicAuth(USERNAME, PASSWORD).build();
    MockHttpServletResponse response = new MockHttpServletResponse();
    String dashboardData = controller.dashboardData(request, response);
    MockHttpServletResponseAssert.assertThat(response).hasStatus(200);
    JsonFluentAssert.assertThatJson(dashboardData).isEqualTo("{\"syncErrors\":[\"Unable to connect to primary, please check that the business-continuity-token file is identical on primary and secondary, and that this server can connect to the primary server.\"],\"setupStatus\":\"incomplete\", \"userName\": \"bob\"}");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletResponse(com.thoughtworks.go.http.mocks.MockHttpServletResponse) UsernamePassword(com.thoughtworks.go.server.newsecurity.models.UsernamePassword) Test(org.junit.jupiter.api.Test)

Example 5 with MockHttpServletResponse

use of com.thoughtworks.go.http.mocks.MockHttpServletResponse 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());
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) AgentSessionReduceIdleTimeoutFilter(com.thoughtworks.go.server.newsecurity.filters.AgentSessionReduceIdleTimeoutFilter) MockHttpServletRequest(com.thoughtworks.go.http.mocks.MockHttpServletRequest) ApiSessionReduceIdleTimeoutFilter(com.thoughtworks.go.server.newsecurity.filters.ApiSessionReduceIdleTimeoutFilter) AlwaysCreateSessionFilter(com.thoughtworks.go.server.newsecurity.filters.AlwaysCreateSessionFilter) MockHttpServletResponse(com.thoughtworks.go.http.mocks.MockHttpServletResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

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