@@ -0,0 +1,3317 @@
+// Copyright (C) 2018 The Android Open Source Project%0A//%0A// Licensed under the Apache License, Version 2.0 (the %22License%22);%0A// you may not use this file except in compliance with the License.%0A// You may obtain a copy of the License at%0A//%0A// http://www.apache.org/licenses/LICENSE-2.0%0A//%0A// Unless required by applicable law or agreed to in writing, software%0A// distributed under the License is distributed on an %22AS IS%22 BASIS,%0A// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A// See the License for the specific language governing permissions and%0A// limitations under the License.%0A%0Apackage com.google.gerrit.acceptance.git;%0A%0Aimport static com.google.common.truth.Truth.assertWithMessage;%0Aimport static com.google.gerrit.git.testing.PushResultSubject.assertThat;%0Aimport static java.util.stream.Collectors.toList;%0A%0Aimport com.google.common.collect.ImmutableMap;%0Aimport com.google.gerrit.acceptance.AbstractDaemonTest;%0Aimport com.google.gerrit.common.data.Permission;%0Aimport com.google.gerrit.server.git.meta.MetaDataUpdate;%0Aimport com.google.gerrit.server.project.ProjectConfig;%0Aimport java.util.Arrays;%0Aimport org.eclipse.jgit.transport.PushResult;%0Aimport org.eclipse.jgit.transport.RefSpec;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0A%0Apublic class PushPermissionsIT extends AbstractDaemonTest %7B%0A  @Before%0A  public void setUp() throws Exception %7B%0A    // Remove all push-related permissions, so they can be added back individually by test methods.%0A    try (MetaDataUpdate md = metaDataUpdateFactory.create(allProjects)) %7B%0A      ProjectConfig cfg = ProjectConfig.read(md);%0A      removeAllBranchPermissions(cfg, Permission.PUSH);%0A      removeAllBranchPermissions(cfg, Permission.CREATE);%0A      removeAllBranchPermissions(cfg, Permission.DELETE);%0A      removeAllBranchPermissions(cfg, Permission.PUSH_MERGE);%0A      saveProjectConfig(allProjects, cfg);%0A    %7D%0A  %7D%0A%0A  @Test%0A  public void noDirectPushPermissions() throws Exception %7B%0A    testRepo.branch(%22HEAD%22).commit().create();%0A    PushResult r = push(%22HEAD:refs/heads/master%22);%0A    assertThat(r)%0A        .onlyRef(%22refs/heads/master%22)%0A        .isRejected(%22prohibited by Gerrit: ref update access denied%22);%0A    assertThat(r)%0A        .hasMessages(%0A            %22Branch refs/heads/master:%22,%0A            %22You are not allowed to perform this operation.%22,%0A            %22To push into this reference you need 'Push' rights.%22,%0A            %22User: admin%22,%0A            %22Please read the documentation and contact an administrator%22,%0A            %22if you feel the configuration is incorrect%22);%0A    assertThat(r).hasProcessed(ImmutableMap.of(%22refs%22, 1));%0A  %7D%0A%0A  private static void removeAllBranchPermissions(ProjectConfig cfg, String permission) %7B%0A    cfg.getAccessSections()%0A        .stream()%0A        .filter(s -%3E s.getName().startsWith(%22refs/heads/%22) %7C%7C s.getName().equals(%22refs/*%22))%0A        .forEach(s -%3E s.removePermission(permission));%0A  %7D%0A%0A  private PushResult push(String... refSpecs) throws Exception %7B%0A    Iterable%3CPushResult%3E results =%0A        testRepo%0A            .git()%0A            .push()%0A            .setRemote(%22origin%22)%0A            .setRefSpecs(Arrays.stream(refSpecs).map(RefSpec::new).collect(toList()))%0A            .call();%0A    assertWithMessage(%22expected 1 PushResult%22).that(results).hasSize(1);%0A    return results.iterator().next();%0A  %7D%0A%7D%0A

Add a proof-of-concept test for error messages in ReceiveCommits