Handle trailing slash on status and health_check

This commit is contained in:
Shane Kilkelly 2020-06-25 16:43:57 +01:00
parent 0830102cec
commit a9a7f54a96
3 changed files with 33 additions and 2 deletions

View file

@ -28,7 +28,11 @@ public class HealthCheckHandler extends AbstractHandler {
HttpServletRequest request,
HttpServletResponse response
) throws IOException {
if ("GET".equals(baseRequest.getMethod()) && "/health_check".equals(target)) {
if (
"GET".equals(baseRequest.getMethod())
&& target != null
&& target.matches("^\\/health_check\\/?$")
) {
Log.info("GET <- /health_check");
baseRequest.setHandled(true);
response.setContentType("text/plain");

View file

@ -28,7 +28,11 @@ public class StatusHandler extends AbstractHandler {
HttpServletRequest request,
HttpServletResponse response
) throws IOException {
if ("GET".equals(baseRequest.getMethod()) && "/status".equals(target)) {
if (
"GET".equals(baseRequest.getMethod())
&& target != null
&& target.matches("^\\/status\\/?$")
) {
Log.info("GET <- /status");
baseRequest.setHandled(true);
response.setContentType("text/plain");

View file

@ -921,6 +921,29 @@ public class WLGitBridgeIntegrationTest {
assertEquals(200, healthCheckResponse.getStatusLine().getStatusCode());
}
@Test
public void testStatusAndHealthCheckEndpointsWithTrailingSlash() throws ClientProtocolException, IOException {
int gitBridgePort = 33888;
int mockServerPort = 3888;
server = new MockSnapshotServer(mockServerPort, getResource("/canCloneARepository").toFile());
server.start();
server.setState(states.get("canCloneARepository").get("state"));
wlgb = new GitBridgeApp(new String[] {
makeConfigFile(gitBridgePort, mockServerPort)
});
wlgb.run();
HttpClient client = HttpClients.createDefault();
String urlBase = "http://127.0.0.1:" + gitBridgePort;
// Status
HttpGet statusRequest = new HttpGet(urlBase+"/status/");
HttpResponse statusResponse = client.execute(statusRequest);
assertEquals(200, statusResponse.getStatusLine().getStatusCode());
// Health Check
HttpGet healthCheckRequest = new HttpGet(urlBase+"/health_check/");
HttpResponse healthCheckResponse = client.execute(healthCheckRequest);
assertEquals(200, healthCheckResponse.getStatusLine().getStatusCode());
}
private String makeConfigFile(
int port,
int apiPort