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");
}
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();
}
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);
}
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\"}");
}
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());
}
Aggregations