Search in sources :

Example 21 with SubmitInput

use of com.google.gerrit.extensions.api.changes.SubmitInput in project gerrit by GerritCodeReview.

the class ImpersonationIT method submitOnBehalfOfFailsWhenUserCannotSeeDestinationRef.

@Test
public void submitOnBehalfOfFailsWhenUserCannotSeeDestinationRef() throws Exception {
    blockRead(newGroup);
    allowSubmitOnBehalfOf();
    PushOneCommit.Result r = createChange();
    String changeId = project.get() + "~master~" + r.getChangeId();
    gApi.changes().id(changeId).current().review(ReviewInput.approve());
    SubmitInput in = new SubmitInput();
    in.onBehalfOf = user.email();
    UnprocessableEntityException thrown = assertThrows(UnprocessableEntityException.class, () -> gApi.changes().id(changeId).current().submit(in));
    assertThat(thrown).hasMessageThat().contains("on_behalf_of account " + user.id() + " cannot see change");
}
Also used : SubmitInput(com.google.gerrit.extensions.api.changes.SubmitInput) UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 22 with SubmitInput

use of com.google.gerrit.extensions.api.changes.SubmitInput in project gerrit by GerritCodeReview.

the class AbstractSubmit method submitNoPermission.

@Test
public void submitNoPermission() throws Throwable {
    // create project where submit is blocked
    Project.NameKey p = projectOperations.newProject().create();
    projectOperations.project(p).forUpdate().add(block(Permission.SUBMIT).ref("refs/*").group(REGISTERED_USERS)).update();
    TestRepository<InMemoryRepository> repo = cloneProject(p, admin);
    PushOneCommit push = pushFactory.create(admin.newIdent(), repo);
    PushOneCommit.Result result = push.to("refs/for/master");
    result.assertOkStatus();
    submit(result.getChangeId(), new SubmitInput(), AuthException.class, "submit not permitted");
}
Also used : TestSubmitInput(com.google.gerrit.server.change.TestSubmitInput) SubmitInput(com.google.gerrit.extensions.api.changes.SubmitInput) Project(com.google.gerrit.entities.Project) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 23 with SubmitInput

use of com.google.gerrit.extensions.api.changes.SubmitInput in project gerrit by GerritCodeReview.

the class ImpersonationIT method submitOnBehalfOf.

@Test
public void submitOnBehalfOf() throws Exception {
    allowSubmitOnBehalfOf();
    PushOneCommit.Result r = createChange();
    String changeId = project.get() + "~master~" + r.getChangeId();
    gApi.changes().id(changeId).current().review(ReviewInput.approve());
    SubmitInput in = new SubmitInput();
    in.onBehalfOf = admin2.email();
    gApi.changes().id(changeId).current().submit(in);
    ChangeData cd = r.getChange();
    assertThat(cd.change().isMerged()).isTrue();
    PatchSetApproval submitter = approvalsUtil.getSubmitter(cd.notes(), cd.change().currentPatchSetId());
    assertThat(submitter.accountId()).isEqualTo(admin2.id());
    assertThat(submitter.realAccountId()).isEqualTo(admin.id());
}
Also used : SubmitInput(com.google.gerrit.extensions.api.changes.SubmitInput) ChangeData(com.google.gerrit.server.query.change.ChangeData) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 24 with SubmitInput

use of com.google.gerrit.extensions.api.changes.SubmitInput in project gerrit by GerritCodeReview.

the class ImpersonationIT method submitOnBehalfOfInvisibleUserNotAllowed.

@GerritConfig(name = "accounts.visibility", value = "SAME_GROUP")
@Test
public void submitOnBehalfOfInvisibleUserNotAllowed() throws Exception {
    allowSubmitOnBehalfOf();
    requestScopeOperations.setApiUser(accountCreator.user2().id());
    assertThat(accountControlFactory.get().canSee(user.id())).isFalse();
    PushOneCommit.Result r = createChange();
    String changeId = project.get() + "~master~" + r.getChangeId();
    gApi.changes().id(changeId).current().review(ReviewInput.approve());
    SubmitInput in = new SubmitInput();
    in.onBehalfOf = user.email();
    UnprocessableEntityException thrown = assertThrows(UnprocessableEntityException.class, () -> gApi.changes().id(changeId).current().submit(in));
    assertThat(thrown).hasMessageThat().contains("not found");
    assertThat(thrown).hasMessageThat().contains(in.onBehalfOf);
}
Also used : SubmitInput(com.google.gerrit.extensions.api.changes.SubmitInput) UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 25 with SubmitInput

use of com.google.gerrit.extensions.api.changes.SubmitInput in project gerrit by GerritCodeReview.

the class SubmitByCherryPickIT method submitIdenticalTree.

@Test
@TestProjectInput(useContentMerge = InheritableBoolean.TRUE)
public void submitIdenticalTree() throws Throwable {
    RevCommit initialHead = projectOperations.project(project).getHead("master");
    PushOneCommit.Result change1 = createChange("Change 1", "a.txt", "a");
    testRepo.reset(initialHead);
    PushOneCommit.Result change2 = createChange("Change 2", "a.txt", "a");
    submit(change1.getChangeId());
    RevCommit headAfterFirstSubmit = projectOperations.project(project).getHead("master");
    assertThat(headAfterFirstSubmit.getShortMessage()).isEqualTo("Change 1");
    submit(change2.getChangeId(), new SubmitInput(), null, null);
    assertThat(projectOperations.project(project).getHead("master")).isEqualTo(headAfterFirstSubmit);
    ChangeInfo info2 = get(change2.getChangeId(), MESSAGES);
    assertThat(info2.status).isEqualTo(ChangeStatus.MERGED);
    assertThat(Iterables.getLast(info2.messages).message).isEqualTo(CommitMergeStatus.SKIPPED_IDENTICAL_TREE.getDescription());
    assertRefUpdatedEvents(initialHead, headAfterFirstSubmit);
    assertChangeMergedEvents(change1.getChangeId(), headAfterFirstSubmit.name(), change2.getChangeId(), headAfterFirstSubmit.name());
}
Also used : SubmitInput(com.google.gerrit.extensions.api.changes.SubmitInput) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) Test(org.junit.Test)

Aggregations

SubmitInput (com.google.gerrit.extensions.api.changes.SubmitInput)26 Test (org.junit.Test)18 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)14 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)13 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)11 ObjectId (org.eclipse.jgit.lib.ObjectId)8 AuthException (com.google.gerrit.extensions.restapi.AuthException)6 Change (com.google.gerrit.reviewdb.client.Change)6 RevCommit (org.eclipse.jgit.revwalk.RevCommit)6 Project (com.google.gerrit.entities.Project)5 Change (com.google.gerrit.entities.Change)4 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)4 TestSubmitInput (com.google.gerrit.server.change.Submit.TestSubmitInput)4 Repository (org.eclipse.jgit.lib.Repository)4 RevWalk (org.eclipse.jgit.revwalk.RevWalk)4 TestSubmitInput (com.google.gerrit.server.change.TestSubmitInput)3 Attempt (com.github.rholder.retry.Attempt)2 RetryListener (com.github.rholder.retry.RetryListener)2 AutoValue (com.google.auto.value.AutoValue)2 Joiner (com.google.common.base.Joiner)2