Search in sources :

Example 26 with ChangeInput

use of com.google.gerrit.extensions.common.ChangeInput in project gerrit by GerritCodeReview.

the class CreateChangeIT method createEmptyChange_InvalidChangeId.

@Test
public void createEmptyChange_InvalidChangeId() throws Exception {
    ChangeInput ci = newChangeInput(ChangeStatus.NEW);
    ci.subject = "Subject\n\nChange-Id: I0000000000000000000000000000000000000000";
    assertCreateFails(ci, ResourceConflictException.class, "invalid Change-Id line format in message footer");
}
Also used : ChangeInput(com.google.gerrit.extensions.common.ChangeInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 27 with ChangeInput

use of com.google.gerrit.extensions.common.ChangeInput in project gerrit by GerritCodeReview.

the class CreateChangeIT method createChangeOnExistingBranchNotPermitted.

@Test
public void createChangeOnExistingBranchNotPermitted() throws Exception {
    createBranch(BranchNameKey.create(project, "foo"));
    projectOperations.project(project).forUpdate().add(allow(READ).ref("refs/meta/config").group(REGISTERED_USERS)).add(block(READ).ref("refs/heads/*").group(REGISTERED_USERS)).update();
    requestScopeOperations.setApiUser(user.id());
    ChangeInput input = newChangeInput(ChangeStatus.NEW);
    input.branch = "foo";
    assertCreateFails(input, ResourceNotFoundException.class, "ref refs/heads/foo not found");
}
Also used : ChangeInput(com.google.gerrit.extensions.common.ChangeInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 28 with ChangeInput

use of com.google.gerrit.extensions.common.ChangeInput in project gerrit by GerritCodeReview.

the class GitProtocolV2IT method testGitWireProtocolV2WithSsh.

@Test
public void testGitWireProtocolV2WithSsh() throws Exception {
    try (ServerContext ctx = startServer()) {
        ctx.getInjector().injectMembers(this);
        // Create project
        Project.NameKey project = Project.nameKey("foo");
        gApi.projects().create(project.get());
        // Set up project permission
        projectOperations.project(project).forUpdate().add(deny(Permission.READ).ref("refs/heads/*").group(SystemGroupBackend.ANONYMOUS_USERS)).add(allow(Permission.READ).ref("refs/heads/master").group(SystemGroupBackend.REGISTERED_USERS)).update();
        // Retrieve HTTP url
        String url = config.getString("gerrit", null, "canonicalweburl");
        String urlDestinationTemplate = url.substring(0, 7) + "%s:secret@" + url.substring(7, url.length()) + "/a/" + project.get();
        // Retrieve SSH host and port
        String sshDestinationTemplate = "ssh://%s@" + sshAddress.getHostName() + ":" + sshAddress.getPort() + "/" + project.get();
        // Admin user was already created by the base class
        setUpUserAuthentication(admin.username());
        // Create non-admin user
        TestAccount user = accountCreator.user1();
        setUpUserAuthentication(user.username());
        // Prepare data for new change on master branch
        ChangeInput in = new ChangeInput(project.get(), "master", "Test public change");
        in.newBranch = true;
        // Create new change and retrieve SHA1 for the created patch set
        String commit = gApi.changes().id(gApi.changes().create(in).info().changeId).current().commit(false).commit;
        // Prepare new change on secret branch
        in = new ChangeInput(project.get(), ADMIN_PASSWORD, "Test secret change");
        in.newBranch = true;
        // Create new change and retrieve SHA1 for the created patch set
        String secretCommit = gApi.changes().id(gApi.changes().create(in).info().changeId).current().commit(false).commit;
        // Read refs from target repository using git wire protocol v2 over HTTP for admin user
        String out = execute(ImmutableList.<String>builder().add(GIT_LS_REMOTE).add(String.format(urlDestinationTemplate, admin.username())).build(), ImmutableMap.of("GIT_TRACE_PACKET", "1"));
        assertGitProtocolV2Refs(commit, out);
        assertThat(out).contains(secretCommit);
        // Read refs from target repository using git wire protocol v2 over SSH for admin user
        out = execute(ImmutableList.<String>builder().add(GIT_LS_REMOTE).add(String.format(sshDestinationTemplate, admin.username())).build(), ImmutableMap.of("GIT_SSH_COMMAND", GIT_SSH_COMMAND + sitePaths.data_dir.resolve(String.format("id_rsa_%s", admin.username())), "GIT_TRACE_PACKET", "1"));
        assertGitProtocolV2Refs(commit, out);
        assertThat(out).contains(secretCommit);
        // Read refs from target repository using git wire protocol v2 over HTTP for non-admin user
        out = execute(ImmutableList.<String>builder().add(GIT_LS_REMOTE).add(String.format(urlDestinationTemplate, user.username())).build(), ImmutableMap.of("GIT_TRACE_PACKET", "1"));
        assertGitProtocolV2Refs(commit, out);
        assertThat(out).doesNotContain(secretCommit);
        // Read refs from target repository using git wire protocol v2 over SSH for non-admin user
        out = execute(ImmutableList.<String>builder().add(GIT_LS_REMOTE).add(String.format(sshDestinationTemplate, user.username())).build(), ImmutableMap.of("GIT_SSH_COMMAND", GIT_SSH_COMMAND + sitePaths.data_dir.resolve(String.format("id_rsa_%s", user.username())), "GIT_TRACE_PACKET", "1"));
        assertGitProtocolV2Refs(commit, out);
        assertThat(out).doesNotContain(secretCommit);
    }
}
Also used : Project(com.google.gerrit.entities.Project) ChangeInput(com.google.gerrit.extensions.common.ChangeInput) TestAccount(com.google.gerrit.acceptance.TestAccount) StandaloneSiteTest(com.google.gerrit.acceptance.StandaloneSiteTest) Test(org.junit.Test)

Example 29 with ChangeInput

use of com.google.gerrit.extensions.common.ChangeInput in project gerrit by GerritCodeReview.

the class GitProtocolV2IT method testGitWireProtocolV2HidesRefMetaConfig.

@Test
public void testGitWireProtocolV2HidesRefMetaConfig() throws Exception {
    try (ServerContext ctx = startServer()) {
        ctx.getInjector().injectMembers(this);
        String url = config.getString("gerrit", null, "canonicalweburl");
        // Create project
        Project.NameKey allRefsVisibleProject = Project.nameKey("all-refs-visible");
        gApi.projects().create(allRefsVisibleProject.get());
        // Set up project permission to allow reading all refs
        projectOperations.project(allRefsVisibleProject).forUpdate().add(allow(Permission.READ).ref("refs/heads/*").group(SystemGroupBackend.ANONYMOUS_USERS)).add(allow(Permission.READ).ref("refs/changes/*").group(SystemGroupBackend.ANONYMOUS_USERS)).update();
        // Create new change and retrieve refs for the created patch set
        ChangeInput visibleChangeIn = new ChangeInput(allRefsVisibleProject.get(), "master", "Test public change");
        visibleChangeIn.newBranch = true;
        int visibleChangeNumber = gApi.changes().create(visibleChangeIn).info()._number;
        Change.Id changeId = Change.id(visibleChangeNumber);
        String visibleChangeNumberRef = RefNames.patchSetRef(PatchSet.id(changeId, 1));
        String visibleChangeNumberMetaRef = RefNames.changeMetaRef(changeId);
        // Read refs from target repository using git wire protocol v2 over HTTP anonymously
        String outAnonymousLsRemote = execute(ImmutableList.<String>builder().add(GIT_CLONE_MIRROR).add(url + "/" + allRefsVisibleProject.get()).build(), ImmutableMap.of("GIT_TRACE_PACKET", "1"));
        assertThat(outAnonymousLsRemote).contains("git< version 2");
        assertThat(outAnonymousLsRemote).doesNotContain(RefNames.REFS_CONFIG);
        assertThat(outAnonymousLsRemote).contains(visibleChangeNumberRef);
        assertThat(outAnonymousLsRemote).contains(visibleChangeNumberMetaRef);
    }
}
Also used : Project(com.google.gerrit.entities.Project) ChangeInput(com.google.gerrit.extensions.common.ChangeInput) Change(com.google.gerrit.entities.Change) StandaloneSiteTest(com.google.gerrit.acceptance.StandaloneSiteTest) Test(org.junit.Test)

Example 30 with ChangeInput

use of com.google.gerrit.extensions.common.ChangeInput in project gerrit by GerritCodeReview.

the class PushPermissionsIT method addPatchSetDenied.

@Test
public void addPatchSetDenied() throws Exception {
    projectOperations.project(project).forUpdate().add(allow(Permission.PUSH).ref("refs/for/refs/heads/*").group(REGISTERED_USERS)).update();
    requestScopeOperations.setApiUser(user.id());
    ChangeInput ci = new ChangeInput();
    ci.project = project.get();
    ci.branch = "master";
    ci.subject = "A change";
    Change.Id id = Change.id(gApi.changes().create(ci).get()._number);
    requestScopeOperations.setApiUser(admin.id());
    ObjectId ps1Id = forceFetch(PatchSet.id(id, 1).toRefName());
    ObjectId ps2Id = testRepo.amend(ps1Id).add("file", "content").create();
    PushResult r = push(ps2Id.name() + ":refs/for/master");
    // Admin had ADD_PATCH_SET removed in setup.
    assertThat(r).onlyRef("refs/for/master").isRejected("cannot add patch set to " + id.get() + ".");
    assertThat(r).hasNoMessages();
    assertThat(r).hasProcessed(ImmutableMap.of("refs", 1));
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) ChangeInput(com.google.gerrit.extensions.common.ChangeInput) Change(com.google.gerrit.entities.Change) PushResult(org.eclipse.jgit.transport.PushResult) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

ChangeInput (com.google.gerrit.extensions.common.ChangeInput)107 Test (org.junit.Test)94 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)89 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)30 Project (com.google.gerrit.entities.Project)10 Result (com.google.gerrit.acceptance.PushOneCommit.Result)7 AccountInput (com.google.gerrit.extensions.api.accounts.AccountInput)7 MergeInput (com.google.gerrit.extensions.common.MergeInput)6 BinaryResult (com.google.gerrit.extensions.restapi.BinaryResult)6 Change (com.google.gerrit.entities.Change)5 ChangeApi (com.google.gerrit.extensions.api.changes.ChangeApi)5 TestAccount (com.google.gerrit.acceptance.TestAccount)4 StandaloneSiteTest (com.google.gerrit.acceptance.StandaloneSiteTest)3 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)3 GitPerson (com.google.gerrit.extensions.common.GitPerson)3 ObjectId (org.eclipse.jgit.lib.ObjectId)3 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)2 TestProjectInput (com.google.gerrit.acceptance.TestProjectInput)2 UseSystemTime (com.google.gerrit.acceptance.UseSystemTime)2 RevisionApi (com.google.gerrit.extensions.api.changes.RevisionApi)2