use of com.thoughtworks.go.http.mocks.MockHttpServletResponse in project gocd by gocd.
the class AgentRemoteInvokerServiceExporterTest method setup.
@BeforeEach
void setup() throws Exception {
when(env.get(AGENT_EXTRA_PROPERTIES)).thenReturn("gocd.agent.remoting.legacy=true");
req = new MockHttpServletRequest();
req.addHeader("X-Agent-GUID", AGENT_UUID);
res = new MockHttpServletResponse();
}
use of com.thoughtworks.go.http.mocks.MockHttpServletResponse in project gocd by gocd.
the class GenericAccessDeniedHandlerTest method shouldRedirectToLoginPageWhenSecurityIsEnabledAndUserIsNotAuthenticated.
@Test
void shouldRedirectToLoginPageWhenSecurityIsEnabledAndUserIsNotAuthenticated() throws IOException {
final MockHttpServletRequest request = HttpRequestBuilder.GET("/foo").build();
final MockHttpServletResponse response = new MockHttpServletResponse();
SecurityService securityService = mock(SecurityService.class);
SessionUtilsHelper.loginAsAnonymous(request);
when(securityService.isSecurityEnabled()).thenReturn(true);
new GenericAccessDeniedHandler(securityService).handle(request, response, SC_FORBIDDEN, "Some error");
MockHttpServletResponseAssert.assertThat(response).redirectsTo("/go/auth/login");
}
use of com.thoughtworks.go.http.mocks.MockHttpServletResponse in project gocd by gocd.
the class GenericAccessDeniedHandlerTest method shouldAccessDeniedWhenUserIsAuthenticated.
@Test
void shouldAccessDeniedWhenUserIsAuthenticated() throws IOException {
final MockHttpServletRequest request = HttpRequestBuilder.GET("/admin/").build();
final MockHttpServletResponse response = new MockHttpServletResponse();
SecurityService securityService = mock(SecurityService.class);
SessionUtilsHelper.loginAsRandomUser(request, GoAuthority.ROLE_USER.asAuthority());
when(securityService.isSecurityEnabled()).thenReturn(true);
new GenericAccessDeniedHandler(securityService).handle(request, response, SC_FORBIDDEN, "Some error");
MockHttpServletResponseAssert.assertThat(response).isForbidden();
}
use of com.thoughtworks.go.http.mocks.MockHttpServletResponse in project gocd by gocd.
the class BasicAuthenticationWithRedirectToLoginFilterTest method shouldInvokeHandler.
@Test
void shouldInvokeHandler() throws IOException {
final BasicAuthenticationWithRedirectToLoginFilter filter = new BasicAuthenticationWithRedirectToLoginFilter(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 DenyIfRefererIsNotFilesFilterTest method setUp.
@BeforeEach
void setUp() throws Exception {
response = new MockHttpServletResponse();
chain = mock(FilterChain.class);
}
Aggregations