use of com.thoughtworks.go.http.mocks.MockHttpServletRequest in project gocd by gocd.
the class ContentTypeNegotiationMessageRendererTest method shouldGenerateXMLResponseMessageForContentType.
@ParameterizedTest
@ValueSource(strings = { MediaType.TEXT_XML_VALUE, MediaType.APPLICATION_XML_VALUE })
void shouldGenerateXMLResponseMessageForContentType(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("<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 ContentTypeNegotiationMessageRendererTest method shouldJsonResponseMessageWhenRequestIsMadeWithoutContentTypeAndItIsNotForXMLFile.
@Test
void shouldJsonResponseMessageWhenRequestIsMadeWithoutContentTypeAndItIsNotForXMLFile() {
final MockHttpServletRequest request = HttpRequestBuilder.GET("/random").build();
final ContentTypeAwareResponse response = new ContentTypeNegotiationMessageRenderer().getResponse(request);
assertThat(response.getContentType().toString()).isEqualTo("application/json");
assertThat(response.getFormattedMessage("foo")).isEqualTo("{\n \"message\": \"foo\"\n}");
}
use of com.thoughtworks.go.http.mocks.MockHttpServletRequest 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.MockHttpServletRequest in project gocd by gocd.
the class ArtifactSizeEnforcementFilterChainTest method shouldDoNothingWhenNoArtifactSizeHeaderPresent.
@ParameterizedTest
@ValueSource(strings = { "/files/bar/foo.zip", "/remoting/files/bar/foo.zip" })
void shouldDoNothingWhenNoArtifactSizeHeaderPresent(String path) throws IOException, ServletException {
MockHttpServletRequest request = HttpRequestBuilder.POST(path).build();
filter.doFilter(request, response, filterChain);
assertThat(response).isOk();
verify(filterChain).doFilter(wrap(request), wrap(response));
}
use of com.thoughtworks.go.http.mocks.MockHttpServletRequest in project gocd by gocd.
the class ArtifactSizeEnforcementFilterChainTest method shouldAllowIfEnoughDiskSpaceIsAvailable.
@ParameterizedTest
@ValueSource(strings = { "/files/bar/foo.zip", "/remoting/files/bar/foo.zip" })
void shouldAllowIfEnoughDiskSpaceIsAvailable(String path) throws IOException, ServletException {
MockHttpServletRequest request = HttpRequestBuilder.POST(path).withHeader("X-GO-ARTIFACT-SIZE", FileSize.valueOf("100MB").getSize()).build();
filter.doFilter(request, response, filterChain);
assertThat(response).isOk();
verify(filterChain).doFilter(wrap(request), wrap(response));
}
Aggregations