Search in sources :

Example 6 with RevisionApi

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

the class ImpersonationIT method voteOnBehalfOf.

@Test
public void voteOnBehalfOf() throws Exception {
    allowCodeReviewOnBehalfOf();
    PushOneCommit.Result r = createChange();
    RevisionApi revision = gApi.changes().id(r.getChangeId()).current();
    ReviewInput in = ReviewInput.recommend();
    in.onBehalfOf = user.id.toString();
    in.message = "Message on behalf of";
    revision.review(in);
    PatchSetApproval psa = Iterables.getOnlyElement(r.getChange().approvals().values());
    assertThat(psa.getPatchSetId().get()).isEqualTo(1);
    assertThat(psa.getLabel()).isEqualTo("Code-Review");
    assertThat(psa.getAccountId()).isEqualTo(user.id);
    assertThat(psa.getValue()).isEqualTo(1);
    assertThat(psa.getRealAccountId()).isEqualTo(admin.id);
    ChangeData cd = r.getChange();
    ChangeMessage m = Iterables.getLast(cmUtil.byChange(db, cd.notes()));
    assertThat(m.getMessage()).endsWith(in.message);
    assertThat(m.getAuthor()).isEqualTo(user.id);
    assertThat(m.getRealAuthor()).isEqualTo(admin.id);
}
Also used : RevisionApi(com.google.gerrit.extensions.api.changes.RevisionApi) ChangeMessage(com.google.gerrit.reviewdb.client.ChangeMessage) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) ChangeData(com.google.gerrit.server.query.change.ChangeData) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 7 with RevisionApi

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

the class ImpersonationIT method voteOnBehalfOfLabelNotPermitted.

@Test
public void voteOnBehalfOfLabelNotPermitted() throws Exception {
    ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
    LabelType verified = Util.verified();
    cfg.getLabelSections().put(verified.getName(), verified);
    saveProjectConfig(project, cfg);
    PushOneCommit.Result r = createChange();
    RevisionApi revision = gApi.changes().id(r.getChangeId()).current();
    ReviewInput in = new ReviewInput();
    in.onBehalfOf = user.id.toString();
    in.label("Verified", 1);
    exception.expect(AuthException.class);
    exception.expectMessage("not permitted to modify label \"Verified\" on behalf of \"" + in.onBehalfOf + '"');
    revision.review(in);
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) RevisionApi(com.google.gerrit.extensions.api.changes.RevisionApi) LabelType(com.google.gerrit.common.data.LabelType) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 8 with RevisionApi

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

the class ImpersonationIT method voteOnBehalfOfInvalidLabelIgnoredWithoutStrictLabels.

@Test
public void voteOnBehalfOfInvalidLabelIgnoredWithoutStrictLabels() throws Exception {
    allowCodeReviewOnBehalfOf();
    PushOneCommit.Result r = createChange();
    RevisionApi revision = gApi.changes().id(r.getChangeId()).current();
    ReviewInput in = new ReviewInput();
    in.onBehalfOf = user.id.toString();
    in.strictLabels = false;
    in.label("Code-Review", 1);
    in.label("Not-A-Label", 5);
    revision.review(in);
    assertThat(gApi.changes().id(r.getChangeId()).get().labels).doesNotContainKey("Not-A-Label");
}
Also used : RevisionApi(com.google.gerrit.extensions.api.changes.RevisionApi) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 9 with RevisionApi

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

the class ImpersonationIT method voteOnBehalfOfFailsWhenUserCannotSeeDestinationRef.

@Test
public void voteOnBehalfOfFailsWhenUserCannotSeeDestinationRef() throws Exception {
    blockRead(newGroup);
    allowCodeReviewOnBehalfOf();
    PushOneCommit.Result r = createChange();
    RevisionApi revision = gApi.changes().id(r.getChangeId()).current();
    ReviewInput in = new ReviewInput();
    in.onBehalfOf = user.id.toString();
    in.label("Code-Review", 1);
    exception.expect(UnprocessableEntityException.class);
    exception.expectMessage("on_behalf_of account " + user.id + " cannot see change");
    revision.review(in);
}
Also used : RevisionApi(com.google.gerrit.extensions.api.changes.RevisionApi) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 10 with RevisionApi

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

the class ChangeIT method rebaseNotAllowedForOwnerWithoutPushPermission.

@Test
public void rebaseNotAllowedForOwnerWithoutPushPermission() throws Exception {
    // Create two changes both with the same parent
    PushOneCommit.Result r = createChange();
    testRepo.reset("HEAD~1");
    PushOneCommit.Result r2 = createChange();
    // Approve and submit the first change
    RevisionApi revision = gApi.changes().id(r.getChangeId()).current();
    revision.review(ReviewInput.approve());
    revision.submit();
    block("refs/for/*", Permission.PUSH, REGISTERED_USERS);
    // Rebase the second
    String changeId = r2.getChangeId();
    exception.expect(AuthException.class);
    exception.expectMessage("rebase not permitted");
    gApi.changes().id(changeId).rebase();
}
Also used : RevisionApi(com.google.gerrit.extensions.api.changes.RevisionApi) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)15 RevisionApi (com.google.gerrit.extensions.api.changes.RevisionApi)15 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)13 Test (org.junit.Test)13 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)9 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)2 GerritConfig (com.google.gerrit.acceptance.GerritConfig)1 LabelType (com.google.gerrit.common.data.LabelType)1 ChangeApi (com.google.gerrit.extensions.api.changes.ChangeApi)1 CherryPickInput (com.google.gerrit.extensions.api.changes.CherryPickInput)1 ChangeMessageInfo (com.google.gerrit.extensions.common.ChangeMessageInfo)1 GitPerson (com.google.gerrit.extensions.common.GitPerson)1 ChangeMessage (com.google.gerrit.reviewdb.client.ChangeMessage)1 PatchSetApproval (com.google.gerrit.reviewdb.client.PatchSetApproval)1 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)1 ChangeData (com.google.gerrit.server.query.change.ChangeData)1