Search in sources :

Example 11 with GerritConfig

use of com.google.gerrit.acceptance.GerritConfig in project gerrit by GerritCodeReview.

the class ImpersonationIT method submitOnBehalfOfInvisibleUserNotAllowed.

@GerritConfig(name = "accounts.visibility", value = "SAME_GROUP")
@Test
public void submitOnBehalfOfInvisibleUserNotAllowed() throws Exception {
    allowSubmitOnBehalfOf();
    setApiUser(accounts.user2());
    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;
    exception.expect(UnprocessableEntityException.class);
    exception.expectMessage("Account Not Found: " + in.onBehalfOf);
    gApi.changes().id(changeId).current().submit(in);
}
Also used : SubmitInput(com.google.gerrit.extensions.api.changes.SubmitInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) GerritConfig(com.google.gerrit.acceptance.GerritConfig) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 12 with GerritConfig

use of com.google.gerrit.acceptance.GerritConfig 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 13 with GerritConfig

use of com.google.gerrit.acceptance.GerritConfig in project gerrit by GerritCodeReview.

the class ImpersonationIT method runAsDisabledByConfig.

@GerritConfig(name = "auth.enableRunAs", value = "false")
@Test
public void runAsDisabledByConfig() throws Exception {
    allowRunAs();
    RestResponse res = adminRestSession.getWithHeader("/changes/", runAsHeader(user.id));
    res.assertForbidden();
    assertThat(res.getEntityContent()).isEqualTo("X-Gerrit-RunAs disabled by auth.enableRunAs = false");
}
Also used : RestResponse(com.google.gerrit.acceptance.RestResponse) GerritConfig(com.google.gerrit.acceptance.GerritConfig) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 14 with GerritConfig

use of com.google.gerrit.acceptance.GerritConfig 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 15 with GerritConfig

use of com.google.gerrit.acceptance.GerritConfig in project gerrit by GerritCodeReview.

the class ServerInfoIT method serverConfigWithPlugin.

@Test
@UseSsh
@GerritConfig(name = "plugins.allowRemoteAdmin", value = "true")
public void serverConfigWithPlugin() throws Exception {
    Path plugins = tempSiteDir.newFolder("plugins").toPath();
    Path jsplugin = plugins.resolve("js-plugin-1.js");
    Files.write(jsplugin, "Gerrit.install(function(self){});\n".getBytes(UTF_8));
    adminSshSession.exec("gerrit plugin reload");
    ServerInfo i = gApi.config().server().getInfo();
    // plugin
    assertThat(i.plugin.jsResourcePaths).hasSize(1);
}
Also used : Path(java.nio.file.Path) ServerInfo(com.google.gerrit.extensions.common.ServerInfo) GerritConfig(com.google.gerrit.acceptance.GerritConfig) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) UseSsh(com.google.gerrit.acceptance.UseSsh)

Aggregations

GerritConfig (com.google.gerrit.acceptance.GerritConfig)19 Test (org.junit.Test)19 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)12 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)6 ChangeMessageInfo (com.google.gerrit.extensions.common.ChangeMessageInfo)5 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)4 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)3 ObjectId (org.eclipse.jgit.lib.ObjectId)3 ServerInfo (com.google.gerrit.extensions.common.ServerInfo)2 SuggestedReviewerInfo (com.google.gerrit.extensions.common.SuggestedReviewerInfo)2 ChangeData (com.google.gerrit.server.query.change.ChangeData)2 RevCommit (org.eclipse.jgit.revwalk.RevCommit)2 RestResponse (com.google.gerrit.acceptance.RestResponse)1 TestAccount (com.google.gerrit.acceptance.TestAccount)1 UseSsh (com.google.gerrit.acceptance.UseSsh)1 GroupAssert.assertGroupInfo (com.google.gerrit.acceptance.api.group.GroupAssert.assertGroupInfo)1 GroupReference (com.google.gerrit.common.data.GroupReference)1 RobotCommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput)1 RevisionApi (com.google.gerrit.extensions.api.changes.RevisionApi)1 SubmitInput (com.google.gerrit.extensions.api.changes.SubmitInput)1