Expose authenticated healthcheck for replicas

The healthcheck endpoint for non-replica instances is available over
anonymous and authenticated paths, so that both
/admin/config/healthcheck~status and /a/admin/config/healthcheck~status
can be hit by a client.

Replicas however, since they don't provide any REST endpoint,
install an HTTP filter as HTTP-Module, consuming requests matching
/admin/config/healthcheck~status only.

Fix the HTTP filter for replica by matching also authenticated
requests, to be consistent with the non-replica REST endpoints.

Bug: Issue 13560
Change-Id: Ib68a606f17bbf2720bb8734f8f45723bde659ef8
diff --git a/src/main/java/com/googlesource/gerrit/plugins/healthcheck/filter/HealthCheckStatusFilter.java b/src/main/java/com/googlesource/gerrit/plugins/healthcheck/filter/HealthCheckStatusFilter.java
index e19f18a..3b7773c 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/healthcheck/filter/HealthCheckStatusFilter.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/healthcheck/filter/HealthCheckStatusFilter.java
@@ -61,7 +61,7 @@
   }
 
   private boolean isStatusCheck(HttpServletRequest httpServletRequest) {
-    return httpServletRequest.getRequestURI().equals("/config/server/healthcheck~status");
+    return httpServletRequest.getRequestURI().matches("(?:/a)?/config/server/healthcheck~status");
   }
 
   private void doStatusCheck(HttpServletResponse httpResponse) throws ServletException {
diff --git a/src/test/java/com/googlesource/gerrit/plugins/healthcheck/HealthCheckIT.java b/src/test/java/com/googlesource/gerrit/plugins/healthcheck/HealthCheckIT.java
index 199543b..bccc626 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/healthcheck/HealthCheckIT.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/healthcheck/HealthCheckIT.java
@@ -21,6 +21,7 @@
 import static com.googlesource.gerrit.plugins.healthcheck.check.HealthCheckNames.JGIT;
 import static com.googlesource.gerrit.plugins.healthcheck.check.HealthCheckNames.QUERYCHANGES;
 
+import com.google.gerrit.acceptance.GerritConfig;
 import com.google.gerrit.acceptance.LightweightPluginDaemonTest;
 import com.google.gerrit.acceptance.RestResponse;
 import com.google.gerrit.acceptance.Sandboxed;
@@ -33,7 +34,10 @@
 import org.junit.Before;
 import org.junit.Test;
 
-@TestPlugin(name = "healthcheck", sysModule = "com.googlesource.gerrit.plugins.healthcheck.Module")
+@TestPlugin(
+    name = "healthcheck",
+    sysModule = "com.googlesource.gerrit.plugins.healthcheck.Module",
+    httpModule = "com.googlesource.gerrit.plugins.healthcheck.HttpModule")
 @Sandboxed
 public class HealthCheckIT extends LightweightPluginDaemonTest {
   Gson gson = new Gson();
@@ -80,6 +84,20 @@
   }
 
   @Test
+  @GerritConfig(name = "container.slave", value = "true")
+  public void shouldHitHealthCheckStatusForReplicaWhenAuthenticated() throws Exception {
+    RestResponse resp = getHealthCheckStatus();
+    resp.assertOK();
+  }
+
+  @Test
+  @GerritConfig(name = "container.slave", value = "true")
+  public void shouldHitHealthCheckStatusForReplicaAnonymously() throws Exception {
+    RestResponse resp = getHealthCheckStatusAnonymously();
+    resp.assertOK();
+  }
+
+  @Test
   public void shouldReturnAuthCheck() throws Exception {
     RestResponse resp = getHealthCheckStatus();
 
@@ -156,6 +174,10 @@
     return adminRestSession.get("/config/server/healthcheck~status");
   }
 
+  private RestResponse getHealthCheckStatusAnonymously() throws IOException {
+    return anonymousRestSession.get("/config/server/healthcheck~status");
+  }
+
   private void assertCheckResult(JsonObject respPayload, String checkName, String result) {
     assertThat(respPayload.has(checkName)).isTrue();
     JsonObject reviewDbStatus = respPayload.get(checkName).getAsJsonObject();