Search in sources :

Example 56 with ReviewInput

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

the class ImpersonationIT method voteOnBehalfOfInvisibleUserNotAllowed.

@GerritConfig(name = "accounts.visibility", value = "SAME_GROUP")
@Test
public void voteOnBehalfOfInvisibleUserNotAllowed() throws Exception {
    allowCodeReviewOnBehalfOf();
    setApiUser(accounts.user2());
    assertThat(accountControlFactory.get().canSee(user.id)).isFalse();
    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("Account Not Found: " + in.onBehalfOf);
    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) GerritConfig(com.google.gerrit.acceptance.GerritConfig) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 57 with ReviewInput

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

the class ImpersonationIT method runAsWithOnBehalfOf.

@Test
public void runAsWithOnBehalfOf() throws Exception {
    // - Has the same restrictions as on_behalf_of (e.g. requires labels).
    // - Takes the effective user from on_behalf_of (user).
    // - Takes the real user from the real caller, not the intermediate
    //   X-Gerrit-RunAs user (user2).
    allowRunAs();
    allowCodeReviewOnBehalfOf();
    TestAccount user2 = accounts.user2();
    PushOneCommit.Result r = createChange();
    ReviewInput in = new ReviewInput();
    in.onBehalfOf = user.id.toString();
    in.message = "Message on behalf of";
    String endpoint = "/changes/" + r.getChangeId() + "/revisions/current/review";
    RestResponse res = adminRestSession.postWithHeader(endpoint, in, runAsHeader(user2.id));
    res.assertForbidden();
    assertThat(res.getEntityContent()).isEqualTo("label required to post review on behalf of \"" + in.onBehalfOf + '"');
    in.label("Code-Review", 1);
    adminRestSession.postWithHeader(endpoint, in, runAsHeader(user2.id)).assertOK();
    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);
    // not user2
    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);
    // not user2
    assertThat(m.getRealAuthor()).isEqualTo(admin.id);
}
Also used : RestResponse(com.google.gerrit.acceptance.RestResponse) ChangeMessage(com.google.gerrit.reviewdb.client.ChangeMessage) TestAccount(com.google.gerrit.acceptance.TestAccount) 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 58 with ReviewInput

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

the class ImpersonationIT method voteOnBehalfOfMissingUser.

@Test
public void voteOnBehalfOfMissingUser() throws Exception {
    allowCodeReviewOnBehalfOf();
    PushOneCommit.Result r = createChange();
    RevisionApi revision = gApi.changes().id(r.getChangeId()).current();
    ReviewInput in = new ReviewInput();
    in.onBehalfOf = "doesnotexist";
    in.label("Code-Review", 1);
    exception.expect(UnprocessableEntityException.class);
    exception.expectMessage("Account Not Found: doesnotexist");
    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 59 with ReviewInput

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

the class ImpersonationIT method voteOnBehalfOfWithRobotComment.

@GerritConfig(name = "notedb.writeJson", value = "true")
@Test
public void voteOnBehalfOfWithRobotComment() throws Exception {
    assume().that(notesMigration.readChanges()).isTrue();
    allowCodeReviewOnBehalfOf();
    PushOneCommit.Result r = createChange();
    ReviewInput in = new ReviewInput();
    in.onBehalfOf = user.id.toString();
    in.label("Code-Review", 1);
    RobotCommentInput ci = new RobotCommentInput();
    ci.robotId = "my-robot";
    ci.robotRunId = "abcd1234";
    ci.path = Patch.COMMIT_MSG;
    ci.side = Side.REVISION;
    ci.line = 1;
    ci.message = "message";
    in.robotComments = ImmutableMap.of(ci.path, ImmutableList.of(ci));
    gApi.changes().id(r.getChangeId()).current().review(in);
    ChangeData cd = r.getChange();
    RobotComment c = Iterables.getOnlyElement(commentsUtil.robotCommentsByChange(cd.notes()));
    assertThat(c.message).isEqualTo(ci.message);
    assertThat(c.robotId).isEqualTo(ci.robotId);
    assertThat(c.robotRunId).isEqualTo(ci.robotRunId);
    assertThat(c.author.getId()).isEqualTo(user.id);
    assertThat(c.getRealAuthor().getId()).isEqualTo(admin.id);
}
Also used : RobotComment(com.google.gerrit.reviewdb.client.RobotComment) RobotCommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) ChangeData(com.google.gerrit.server.query.change.ChangeData) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) GerritConfig(com.google.gerrit.acceptance.GerritConfig) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 60 with ReviewInput

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

the class ImpersonationIT method changeMessageCreatedOnBehalfOfHasRealUser.

@Test
public void changeMessageCreatedOnBehalfOfHasRealUser() throws Exception {
    allowCodeReviewOnBehalfOf();
    PushOneCommit.Result r = createChange();
    ReviewInput in = new ReviewInput();
    in.onBehalfOf = user.id.toString();
    in.message = "Message on behalf of";
    in.label("Code-Review", 1);
    setApiUser(accounts.user2());
    gApi.changes().id(r.getChangeId()).revision(r.getPatchSetId().getId()).review(in);
    ChangeInfo info = gApi.changes().id(r.getChangeId()).get(EnumSet.of(ListChangesOption.MESSAGES));
    assertThat(info.messages).hasSize(2);
    ChangeMessageInfo changeMessageInfo = Iterables.getLast(info.messages);
    assertThat(changeMessageInfo.realAuthor).isNotNull();
    assertThat(changeMessageInfo.realAuthor._accountId).isEqualTo(accounts.user2().id.get());
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)103 Test (org.junit.Test)85 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)77 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)70 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)25 CommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput)20 Change (com.google.gerrit.reviewdb.client.Change)16 ArrayList (java.util.ArrayList)15 List (java.util.List)14 ImmutableList (com.google.common.collect.ImmutableList)13 LabelInfo (com.google.gerrit.extensions.common.LabelInfo)13 CommentInfo (com.google.gerrit.extensions.common.CommentInfo)12 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)12 RevisionApi (com.google.gerrit.extensions.api.changes.RevisionApi)11 LabelType (com.google.gerrit.common.data.LabelType)10 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)10 RobotCommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput)9 ChangeData (com.google.gerrit.server.query.change.ChangeData)9 RestResponse (com.google.gerrit.acceptance.RestResponse)8 TestAccount (com.google.gerrit.acceptance.TestAccount)8