use of com.thoughtworks.go.http.mocks.MockHttpServletRequest 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.MockHttpServletRequest 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.MockHttpServletRequest in project gocd by gocd.
the class ContentTypeNegotiationMessageRendererTest method shouldGenerateJSONResponseMessageForContentType.
@ParameterizedTest
@ValueSource(strings = { MediaType.APPLICATION_JSON_VALUE, "application/vnd.go.cd.v1+json", "application/vnd.go.cd.v2+json", "application/vnd.go.cd.v3+json", "application/vnd.go.cd.v4+json", "application/vnd.go.cd.v5+json", "application/vnd.go.cd.v6+json", "application/vnd.go.cd.v7+json", "application/vnd.go.cd.v8+json", "application/vnd.go.cd.v9+json", "application/vnd.go.cd.v50+json", "application/vnd.go.cd.v99+json" })
void shouldGenerateJSONResponseMessageForContentType(String contentType) {
final MockHttpServletRequest request = HttpRequestBuilder.GET("/").withHeader("Accept", contentType).build();
final ContentTypeAwareResponse response = new ContentTypeNegotiationMessageRenderer().getResponse(request);
assertThat(response.getContentType().toString()).isEqualTo(contentType);
assertThat(response.getFormattedMessage("foo")).isEqualTo("{\n \"message\": \"foo\"\n}");
}
use of com.thoughtworks.go.http.mocks.MockHttpServletRequest in project gocd by gocd.
the class ContentTypeNegotiationMessageRendererTest method shouldGenerateXMLResponseMessageWhenRequestIsForXMLFile.
@Test
void shouldGenerateXMLResponseMessageWhenRequestIsForXMLFile() {
final MockHttpServletRequest request = HttpRequestBuilder.GET("/foo.xml").build();
final ContentTypeAwareResponse response = new ContentTypeNegotiationMessageRenderer().getResponse(request);
assertThat(response.getContentType().toString()).isEqualTo("application/xml");
assertThat(response.getFormattedMessage("foo")).isEqualTo("<access-denied>\n <message>foo</message>\n</access-denied>\n");
}
use of com.thoughtworks.go.http.mocks.MockHttpServletRequest in project gocd by gocd.
the class ArtifactSizeEnforcementFilterChainTest method shouldDisallowIfNotEnoughDiskSpaceIsAvailable.
@ParameterizedTest
@ValueSource(strings = { "/files/bar/foo.zip", "/remoting/files/bar/foo.zip" })
void shouldDisallowIfNotEnoughDiskSpaceIsAvailable(String path) throws IOException, ServletException {
MockHttpServletRequest request = HttpRequestBuilder.POST(path).withHeader("X-GO-ARTIFACT-SIZE", FileSize.valueOf("600MB").getSize()).build();
filter.doFilter(request, response, filterChain);
assertThat(response).isEntityTooLarge();
verify(filterChain, never()).doFilter(request, response);
}
Aggregations