Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgraded Jetty to 9.4.31.v20200723 #118

Merged
merged 1 commit into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public static void beforeClass() throws Exception {
ANSITerminal.muteConsole(true);

final URL url = AdminPortalTest.class.getResource("/yaml/stubs.yaml");
final InputStream stubsDatanputStream = url.openStream();
stubsData = StringUtils.inputStreamToString(stubsDatanputStream);
stubsDatanputStream.close();
final InputStream stubsDataInputStream = url.openStream();
stubsData = StringUtils.inputStreamToString(stubsDataInputStream);
stubsDataInputStream.close();

STUBBY_CLIENT.startJetty(STUBS_PORT, STUBS_SSL_PORT, ADMIN_PORT, url.getFile());
}
Expand Down Expand Up @@ -155,12 +155,7 @@ public void should_ReturnExpectedError_WhenSuccessfulGetMade_ToAdminPortalRootWi
final HttpRequest httpGetRequest = HttpUtils.constructHttpRequest(HttpMethods.GET, requestUrl);

final HttpResponse httpResponse = httpGetRequest.execute();
final String statusMessage = httpResponse.getStatusMessage().trim();

final String expectedMessage = String.format("Stub request index#%s does not exist, cannot display", invalidIndex);

assertThat(httpResponse.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST_400);
assertThat(statusMessage).isEqualTo(expectedMessage);
}

@Test
Expand All @@ -171,12 +166,7 @@ public void should_ReturnExpectedError_WhenSuccessfulGetMade_ToAdminPortalRootWi
final HttpRequest httpGetRequest = HttpUtils.constructHttpRequest(HttpMethods.GET, requestUrl);

final HttpResponse httpResponse = httpGetRequest.execute();
final String statusMessage = httpResponse.getStatusMessage().trim();

final String expectedMessage = String.format("Stub request uuid#%s does not exist, cannot display", nonExistentUuid);

assertThat(httpResponse.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST_400);
assertThat(statusMessage).isEqualTo(expectedMessage);
}

@Test
Expand All @@ -201,10 +191,7 @@ public void should_ReturnExpectedError_WhenSuccessfulEmptyPutMade_ToAdminPortalR
final HttpRequest httpPuttRequest = HttpUtils.constructHttpRequest(HttpMethods.PUT, requestUrl);

final HttpResponse httpResponse = httpPuttRequest.execute();
final String statusMessage = httpResponse.getStatusMessage().trim();

assertThat(httpResponse.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST_400);
assertThat(statusMessage).isEqualTo("PUT request on URI /1 was empty");
}

@Test
Expand All @@ -216,10 +203,7 @@ public void should_ReturnExpectedError_WhenSuccessfulEmptyPutMade_ToAdminPortalR
final HttpRequest httpPuttRequest = HttpUtils.constructHttpRequest(HttpMethods.PUT, requestUrl);

final HttpResponse httpResponse = httpPuttRequest.execute();
final String statusMessage = httpResponse.getStatusMessage().trim();

assertThat(httpResponse.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST_400);
assertThat(statusMessage).isEqualTo("PUT request on URI /" + uuid + " was empty");
}

@Test
Expand All @@ -230,12 +214,7 @@ public void should_ReturnExpectedError_WhenSuccessfulPutMade_ToAdminPortalRootWi
final HttpRequest httpPuttRequest = HttpUtils.constructHttpRequest(HttpMethods.PUT, requestUrl);

final HttpResponse httpResponse = httpPuttRequest.execute();
final String statusMessage = httpResponse.getStatusMessage().trim();

final String expectedMessage = String.format("Stub request index#%s does not exist, cannot update", invalidIndex);

assertThat(httpResponse.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST_400);
assertThat(statusMessage).isEqualTo(expectedMessage);
}

@Test
Expand All @@ -246,12 +225,8 @@ public void should_ReturnExpectedError_WhenSuccessfulPutMade_ToAdminPortalRootWi
final HttpRequest httpPuttRequest = HttpUtils.constructHttpRequest(HttpMethods.PUT, requestUrl);

final HttpResponse httpResponse = httpPuttRequest.execute();
final String statusMessage = httpResponse.getStatusMessage().trim();

final String expectedMessage = String.format("Stub request uuid#%s does not exist, cannot update", nonExistentUuid);

assertThat(httpResponse.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST_400);
assertThat(statusMessage).isEqualTo(expectedMessage);
}

@Test
Expand Down Expand Up @@ -544,12 +519,7 @@ public void should_ReturnExpectedError_WhenSuccessfulDeleteMade_ToAdminPortalRoo
final HttpRequest httpPuttRequest = HttpUtils.constructHttpRequest(HttpMethods.DELETE, requestUrl);

final HttpResponse httpResponse = httpPuttRequest.execute();
final String statusMessage = httpResponse.getStatusMessage().trim();

final String expectedMessage = String.format("Stub request index#%s does not exist, cannot delete", invalidIndex);

assertThat(httpResponse.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST_400);
assertThat(statusMessage).isEqualTo(expectedMessage);
}

@Test
Expand Down Expand Up @@ -603,12 +573,7 @@ public void should_ReturnExpectedError_WhenSuccessfulDeleteMade_ToAdminPortalRoo
final HttpRequest httpDeleteRequest = HttpUtils.constructHttpRequest(HttpMethods.DELETE, requestUrl);

final HttpResponse httpDeleteResponse = httpDeleteRequest.execute();
final String statusMessage = httpDeleteResponse.getStatusMessage().trim();

final String expectedMessage = "Stub request uuid#this-uuid-does-not-exist does not exist, cannot delete";

assertThat(httpDeleteResponse.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST_400);
assertThat(statusMessage).isEqualTo(expectedMessage);
}

@Test
Expand Down Expand Up @@ -667,10 +632,7 @@ public void should_ReturnExpectedError_WhenSuccessfulEmptyPostMade_ToAdminPortal
final HttpRequest httpPuttRequest = HttpUtils.constructHttpRequest(HttpMethods.POST, requestUrl);

final HttpResponse httpResponse = httpPuttRequest.execute();
final String statusMessage = httpResponse.getStatusMessage().trim();

assertThat(httpResponse.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT_204);
assertThat(statusMessage).isEqualTo("POST request on URI / was empty");
}

@Test
Expand All @@ -680,14 +642,7 @@ public void should_ReturnExpectedError_WhenSuccessfulInvalidPostMade_ToAdminPort
final HttpRequest httpPuttRequest = HttpUtils.constructHttpRequest(HttpMethods.POST, requestUrl, "unparseable rubbish post content");

final HttpResponse httpResponse = httpPuttRequest.execute();
final String statusMessage = httpResponse.getStatusMessage().trim();
final String responseMessage = httpResponse.parseAsString().trim();

final String expectedMessage = "Problem handling request in Admin handler: java.io.IOException: Loaded YAML root node must be an instance of ArrayList, otherwise something went wrong. Check provided YAML";

assertThat(httpResponse.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
assertThat(statusMessage).isEqualTo(expectedMessage);
assertThat(responseMessage).contains(expectedMessage);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,7 @@ public void shouldNotMatchRequest_WhenStubbedUrlRegexified_ButBadAssertionSent()
String requestUrl = String.format("%s%s", STUBS_URL, assertingRequest);
HttpRequest request = HttpUtils.constructHttpRequest(HttpMethods.GET, requestUrl);
HttpResponse response = request.execute();
String responseContent = response.parseAsString().trim();

final String errorMessage = String.format("(404) Nothing found for GET request at URI %s", assertingRequest);
assertThat(responseContent).contains(errorMessage);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND_404);
}
}
Expand Down Expand Up @@ -420,10 +417,8 @@ public void should_FailToReturnAllProducts_WhenGetRequestMadeWithoutRequiredQuer

final String requestUrl = String.format("%s%s", STUBS_URL, "/invoice?status=active");
final HttpResponse response = HttpUtils.constructHttpRequest(HttpMethods.GET, requestUrl).execute();
final String responseContentAsString = response.parseAsString().trim();

assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND_404);
assertThat(responseContentAsString).contains("(404) Nothing found for GET request at URI /invoice?status=active");
}

@Test
Expand All @@ -448,11 +443,8 @@ public void should_FailToReturnAllProducts_WhenGetRequestMadeWithoutRequiredQuer

final String requestUrl = String.format("%s%s", STUBS_SSL_URL, "/invoice?status=active");
final HttpResponse response = HttpUtils.constructHttpRequest(HttpMethods.GET, requestUrl).execute();
final String responseContentAsString = response.parseAsString().trim();

assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND_404);
assertThat(responseContentAsString).contains("(404) Nothing found for GET request at URI /invoice?status=active");

}

@Test
Expand Down Expand Up @@ -508,10 +500,7 @@ public void should_UpdateProduct_WhenPutRequestMadeWithWrongPost() throws Except
request.setHeaders(httpHeaders);

final HttpResponse response = request.execute();
final String responseContentAsString = response.parseAsString().trim();

assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND_404);
assertThat(responseContentAsString).contains("(404) Nothing found for PUT request at URI /invoice/123");
}

@Test
Expand All @@ -527,10 +516,7 @@ public void should_UpdateProduct_WhenPutRequestMadeWithWrongPostOverSsl() throws
request.setHeaders(httpHeaders);

final HttpResponse response = request.execute();
final String responseContentAsString = response.parseAsString().trim();

assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND_404);
assertThat(responseContentAsString).contains("(404) Nothing found for PUT request at URI /invoice/123");
}

@Test
Expand Down Expand Up @@ -588,10 +574,7 @@ public void should_FailedToCreateNewProduct_WhenPostRequestMadeWhenWrongHeaderSe
request.setHeaders(httpHeaders);

final HttpResponse response = request.execute();
final String responseContentAsString = response.parseAsString().trim();

assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND_404);
assertThat(responseContentAsString).contains("(404) Nothing found for POST request at URI /invoice/new");
}

@Test
Expand All @@ -607,10 +590,7 @@ public void should_FailedToCreateNewProduct_WhenPostRequestMadeWhenWrongHeaderSe
request.setHeaders(httpHeaders);

final HttpResponse response = request.execute();
final String responseContentAsString = response.parseAsString().trim();

assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND_404);
assertThat(responseContentAsString).contains("(404) Nothing found for POST request at URI /invoice/new");
}

@Test
Expand Down Expand Up @@ -1022,12 +1002,7 @@ public void should_NotReturnExpectedRecordedResponse_FromValidUrl_WhenQueryValue

final HttpHeaders headers = response.getHeaders();
assertThat(headers.getContentType().contains(HEADER_APPLICATION_XML)).isTrue();

String responseContent = response.parseAsString().trim();
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK_200);
assertThat(responseContent).contains("(404) Nothing found for GET request at URI /recordable/feed/2");
assertThat(responseContent).contains("language=russian");
assertThat(responseContent).contains("greeting=nihao");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ public void doGet_ShouldMakeSuccessfulGetWithBasicAuth_WhenWrongAuthCredentialsI
final StubbyResponse stubbyResponse = STUBBY_CLIENT.doGet(host, uri, port, new Authorization(Authorization.AuthorizationType.BASIC, StringUtils.encodeBase64("bob:wrong-secret")));

assertThat(stubbyResponse.getResponseCode()).isEqualTo(HttpStatus.UNAUTHORIZED_401);
assertThat(String.format(UnauthorizedResponseHandlingStrategy.WRONG_AUTHORIZATION_HEADER_TEMPLATE, "Basic Ym9iOndyb25nLXNlY3JldA==")).isEqualTo(stubbyResponse.getContent());
}

@Test
Expand All @@ -224,7 +223,6 @@ public void doGet_ShouldMakeSuccessfulGetWithBearerAuth_WhenWrongAuthCredentials
final StubbyResponse stubbyResponse = STUBBY_CLIENT.doGet(host, uri, port, new Authorization(Authorization.AuthorizationType.BEARER, "blahblahblah=="));

assertThat(stubbyResponse.getResponseCode()).isEqualTo(HttpStatus.UNAUTHORIZED_401);
assertThat(String.format(UnauthorizedResponseHandlingStrategy.WRONG_AUTHORIZATION_HEADER_TEMPLATE, "Bearer blahblahblah==")).isEqualTo(stubbyResponse.getContent());
}

@Test
Expand All @@ -236,7 +234,6 @@ public void doGet_ShouldMakeSuccessfulGetWithCustomAuth_WhenWrongAuthCredentials
final StubbyResponse stubbyResponse = STUBBY_CLIENT.doGet(host, uri, port, new Authorization(Authorization.AuthorizationType.CUSTOM, "CustomAuthorizationName blahblahblah=="));

assertThat(stubbyResponse.getResponseCode()).isEqualTo(HttpStatus.UNAUTHORIZED_401);
assertThat(String.format(UnauthorizedResponseHandlingStrategy.WRONG_AUTHORIZATION_HEADER_TEMPLATE, "CustomAuthorizationName blahblahblah==")).isEqualTo(stubbyResponse.getContent());
}

@Test
Expand All @@ -248,7 +245,6 @@ public void doGet_ShouldMakeSuccessfulGetWithBasicAuth_WhenNoAuthCredentialsIsPr
final StubbyResponse stubbyResponse = STUBBY_CLIENT.doGet(host, uri, port);

assertThat(stubbyResponse.getResponseCode()).isEqualTo(HttpStatus.UNAUTHORIZED_401);
assertThat(UnauthorizedResponseHandlingStrategy.NO_AUTHORIZATION_HEADER).isEqualTo(stubbyResponse.getContent());
}

@Test
Expand All @@ -260,7 +256,6 @@ public void doGet_ShouldMakeSuccessfulGetWithBearerAuth_WhenNoAuthCredentialsIsP
final StubbyResponse stubbyResponse = STUBBY_CLIENT.doGet(host, uri, port);

assertThat(stubbyResponse.getResponseCode()).isEqualTo(HttpStatus.UNAUTHORIZED_401);
assertThat(UnauthorizedResponseHandlingStrategy.NO_AUTHORIZATION_HEADER).isEqualTo(stubbyResponse.getContent());
}

@Test
Expand All @@ -272,7 +267,6 @@ public void doGet_ShouldMakeSuccessfulGetWithCustomAuth_WhenNoAuthCredentialsIsP
final StubbyResponse stubbyResponse = STUBBY_CLIENT.doGet(host, uri, port);

assertThat(stubbyResponse.getResponseCode()).isEqualTo(HttpStatus.UNAUTHORIZED_401);
assertThat(UnauthorizedResponseHandlingStrategy.NO_AUTHORIZATION_HEADER).isEqualTo(stubbyResponse.getContent());
}

@Test
Expand All @@ -284,10 +278,8 @@ public void doGet_ShouldMakeSuccessfulGet_WhenGivenEmptyUri() throws Exception {
final StubbyResponse stubbyResponse = STUBBY_CLIENT.doGet(host, uri, port);

assertThat(stubbyResponse.getResponseCode()).isEqualTo(HttpStatus.NOT_FOUND_404);
assertThat(stubbyResponse.getContent()).contains("(404) Nothing found for GET request at URI /item/888");
}


@Test
public void doPost_ShouldMakeSuccessfulPost() throws Exception {
final String host = "localhost";
Expand Down Expand Up @@ -344,11 +336,8 @@ public void doPost_ShouldMakeSuccessfulPost_WhenGivenEmptyUri() throws Exception
final StubbyResponse stubbyResponse = STUBBY_CLIENT.doPost(host, uri, port, "post body");

assertThat(stubbyResponse.getResponseCode()).isEqualTo(HttpStatus.NOT_FOUND_404);
assertThat(stubbyResponse.getContent()).contains("(404) Nothing found for POST request at URI /");
assertThat(stubbyResponse.getContent()).contains("post body");
}


@Test
public void doPost_ShouldMakeSuccessfulPost_WhenGivenNullUri() throws Exception {
final String host = "localhost";
Expand All @@ -358,8 +347,6 @@ public void doPost_ShouldMakeSuccessfulPost_WhenGivenNullUri() throws Exception
final StubbyResponse stubbyResponse = STUBBY_CLIENT.doPost(host, uri, port, "post body");

assertThat(stubbyResponse.getResponseCode()).isEqualTo(HttpStatus.NOT_FOUND_404);
assertThat(stubbyResponse.getContent()).contains("(404) Nothing found for POST request at URI /");
assertThat(stubbyResponse.getContent()).contains("post body");
}

@Test
Expand All @@ -371,8 +358,6 @@ public void doPost_ShouldMakeSuccessfulPost_WhenGivenWrongPostData() throws Exce
final StubbyResponse stubbyResponse = STUBBY_CLIENT.doPost(host, uri, port, "unexpected or wrong post body");

assertThat(stubbyResponse.getResponseCode()).isEqualTo(HttpStatus.NOT_FOUND_404);
assertThat(stubbyResponse.getContent()).contains("(404) Nothing found for POST request at URI /item/1");
assertThat(stubbyResponse.getContent()).contains("unexpected or wrong post body");
}

@Test
Expand All @@ -384,7 +369,6 @@ public void doPost_ShouldMakeSuccessfulPost_WhenGivenEmptyPostData() throws Exce
final StubbyResponse stubbyResponse = STUBBY_CLIENT.doPost(host, uri, port, "");

assertThat(stubbyResponse.getResponseCode()).isEqualTo(HttpStatus.NOT_FOUND_404);
assertThat(stubbyResponse.getContent()).contains("(404) Nothing found for POST request at URI /item/1");
}

@Test
Expand Down Expand Up @@ -463,7 +447,6 @@ public void doPost_ShouldMakeSuccessfulPost_WhenPostStubDataIsEmpty() throws Exc
final StubbyResponse stubbyResponse = STUBBY_CLIENT.doPost(host, uri, port, "");

assertThat(stubbyResponse.getResponseCode()).isEqualTo(HttpStatus.NO_CONTENT_204);
assertThat("POST request on URI / was empty").isEqualTo(stubbyResponse.getContent());
}

@Test
Expand All @@ -475,7 +458,6 @@ public void doPost_ShouldMakeSuccessfulPost_WhenPostStubDataIsNull() throws Exce
final StubbyResponse stubbyResponse = STUBBY_CLIENT.doPost(host, uri, port, null);

assertThat(stubbyResponse.getResponseCode()).isEqualTo(HttpStatus.NO_CONTENT_204);
assertThat(stubbyResponse.getContent()).isEqualTo("POST request on URI / was empty");
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
org.gradle.daemon=true
org.gradle.parallel=true
configureondemand=true
jettyVersion=9.4.20.v20190813
jettyVersion=9.4.31.v20200723
stubbyProjectName=stubby4j
stubbyProjectGroup=io.github.azagniotov
version=6.0.6-SNAPSHOT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@
package io.github.azagniotov.stubby4j.utils;

import io.github.azagniotov.stubby4j.annotations.CoberturaIgnore;
import io.github.azagniotov.stubby4j.cli.ANSITerminal;
import io.github.azagniotov.stubby4j.common.Common;
import org.eclipse.jetty.http.HttpHeader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
Expand All @@ -41,14 +44,22 @@
@SuppressWarnings("serial")
public final class HandlerUtils {

private static final Logger LOGGER = LoggerFactory.getLogger(HandlerUtils.class);

private HandlerUtils() {

}

public static void configureErrorResponse(final HttpServletResponse response, final int httpStatus, final String message) throws IOException {
response.setStatus(httpStatus);
response.sendError(httpStatus, message);
// Setting custom error message will no longer work in Jetty versions > 9.4.20, see:
// https://github.com/eclipse/jetty.project/issues/4154
// response.sendError(httpStatus, message);
response.sendError(httpStatus);
response.flushBuffer();

ANSITerminal.error(message);
LOGGER.error(message);
}

public static String getHtmlResourceByName(final String templateSuffix) throws IOException {
Expand Down
Loading