Fix pull-replication update head with Gerrit replica I2211201f2 introduced the support for Gerrit replica but all the tests were run against Gerrit primary with the native REST-API, instead of using the pull-replication plugin specific API executed through a filter. The combination with Gerrit Issue 290794206 made the bug invisible because all UpdateHeadActionIT tests on replicas were still passing, because the underlying Gerrit daemon was still a primary even if the test was configured with container.replica = true. Fix the implementation of the update head functionality on Gerrit replicas and amend the validation tests for making sure that it won't break again in the future. Depends-On: https://gerrit-review.googlesource.com/c/gerrit/+/379199 Bug: Issue 290644998 Change-Id: I3af2d2a883ce948f421c9d51ca8d31eb5435c5ec
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/PullReplicationFilter.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/PullReplicationFilter.java index d646cfb..8feb825 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/PullReplicationFilter.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/PullReplicationFilter.java
@@ -321,7 +321,9 @@ } private boolean isUpdateHEADAction(HttpServletRequest httpRequest) { - return httpRequest.getRequestURI().matches(".*/projects/[^/]+/HEAD") + return httpRequest + .getRequestURI() + .matches(String.format(".*/projects/[^/]+/%s~HEAD", pluginName)) && "PUT".equals(httpRequest.getMethod()); }
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/PullReplicationFilterTest.java b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/PullReplicationFilterTest.java index 2ed1466..9e5ca8d 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/PullReplicationFilterTest.java +++ b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/PullReplicationFilterTest.java
@@ -50,7 +50,8 @@ String.format("any-prefix/projects/%s/%s~apply-object", PROJECT_NAME, PLUGIN_NAME); private final String APPLY_OBJECTS_URI = String.format("any-prefix/projects/%s/%s~apply-objects", PROJECT_NAME, PLUGIN_NAME); - private final String HEAD_URI = String.format("any-prefix/projects/%s/HEAD", PROJECT_NAME); + private final String HEAD_URI = + String.format("any-prefix/projects/%s/%s~HEAD", PROJECT_NAME, PLUGIN_NAME); private final String DELETE_PROJECT_URI = String.format("any-prefix/projects/%s/%s~delete-project", PROJECT_NAME, PLUGIN_NAME); private final String INIT_PROJECT_URI =
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/UpdateHeadActionIT.java b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/UpdateHeadActionIT.java index f6e631f..d0f3214 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/UpdateHeadActionIT.java +++ b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/UpdateHeadActionIT.java
@@ -203,6 +203,7 @@ @Override protected String getURLWithAuthenticationPrefix(String projectName) { - return String.format("%s/a/projects/%s/HEAD", adminRestSession.url(), projectName); + return String.format( + "%s/a/projects/%s/pull-replication~HEAD", adminRestSession.url(), projectName); } }