diff --git a/java/com/google/gerrit/acceptance/testsuite/project/ProjectOperationsImpl.java b/java/com/google/gerrit/acceptance/testsuite/project/ProjectOperationsImpl.java index dede7e0c68..21bfcd1b8a 100644 --- a/java/com/google/gerrit/acceptance/testsuite/project/ProjectOperationsImpl.java +++ b/java/com/google/gerrit/acceptance/testsuite/project/ProjectOperationsImpl.java @@ -280,6 +280,29 @@ public class ProjectOperationsImpl implements ProjectOperations { private void invalidateProject(TestProjectInvalidation testProjectInvalidation) throws Exception { + if (testProjectInvalidation.makeProjectConfigInvalid()) { + Config projectConfig = new Config(); + projectConfig.fromText(getConfig().toText()); + + // Make the project config invalid by adding a permission entry with an invalid permission + // name. + projectConfig.setString( + "access", "refs/*", "Invalid Permission Name", "group Administrators"); + + setConfig(projectConfig); + try { + projectCache.evict(nameKey); + } catch (Exception e) { + // Evicting the project from the cache, also triggers a reindex of the project. + // The reindex step fails if the project config is invalid. That's fine, since it was our + // intention to make the project config invalid. Hence we ignore exceptions that are cause + // by an invalid project config here. + if (!Throwables.getCausalChain(e).stream() + .anyMatch(ConfigInvalidException.class::isInstance)) { + throw e; + } + } + } if (!testProjectInvalidation.projectConfigUpdater().isEmpty()) { Config projectConfig = new Config(); projectConfig.fromText(getConfig().toText()); diff --git a/java/com/google/gerrit/acceptance/testsuite/project/TestProjectInvalidation.java b/java/com/google/gerrit/acceptance/testsuite/project/TestProjectInvalidation.java index f070b5603f..d4bd912208 100644 --- a/java/com/google/gerrit/acceptance/testsuite/project/TestProjectInvalidation.java +++ b/java/com/google/gerrit/acceptance/testsuite/project/TestProjectInvalidation.java @@ -28,16 +28,31 @@ import org.eclipse.jgit.lib.Config; */ @AutoValue public abstract class TestProjectInvalidation { + public abstract boolean makeProjectConfigInvalid(); + public abstract ImmutableList> projectConfigUpdater(); abstract ThrowingConsumer projectInvalidator(); public static Builder builder(ThrowingConsumer projectInvalidator) { - return new AutoValue_TestProjectInvalidation.Builder().projectInvalidator(projectInvalidator); + return new AutoValue_TestProjectInvalidation.Builder() + .projectInvalidator(projectInvalidator) + .makeProjectConfigInvalid(false); } @AutoValue.Builder public abstract static class Builder { + /** + * Updates the project.config file so that it becomes invalid and loading it within Gerrit fails + * with {@link org.eclipse.jgit.errors.ConfigInvalidException}. + */ + public Builder makeProjectConfigInvalid() { + makeProjectConfigInvalid(true); + return this; + } + + protected abstract Builder makeProjectConfigInvalid(boolean makeProjectConfigInvalid); + /** * Adds a consumer that can update the project config. * diff --git a/javatests/com/google/gerrit/acceptance/api/project/ProjectIT.java b/javatests/com/google/gerrit/acceptance/api/project/ProjectIT.java index cad20b6e19..8dc76dd78b 100644 --- a/javatests/com/google/gerrit/acceptance/api/project/ProjectIT.java +++ b/javatests/com/google/gerrit/acceptance/api/project/ProjectIT.java @@ -894,14 +894,10 @@ public class ProjectIT extends AbstractDaemonTest { @Test public void getProjectThatHasInvalidProjectConfig() throws Exception { - // Make the project config invalid by adding permission entry with an invalid permission name. projectOperations .project(allProjects) .forInvalidation() - .addProjectConfigUpdater( - cfg -> - cfg.setString( - "access", "refs/*", "Invalid Permission Name", "group Administrators")) + .makeProjectConfigInvalid() .invalidate(); // We must test this via the REST API since ExceptionHook is not invoked from the Java API.