Search in sources :

Example 41 with RestResponse

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

the class CapabilitiesIT method capabilitiesUser.

@Test
public void capabilitiesUser() throws Exception {
    Iterable<String> all = Iterables.filter(GlobalCapability.getAllNames(), c -> !ADMINISTRATE_SERVER.equals(c) && !PRIORITY.equals(c));
    allowGlobalCapabilities(REGISTERED_USERS, all);
    try {
        RestResponse r = userRestSession.get("/accounts/self/capabilities");
        r.assertOK();
        CapabilityInfo info = (new Gson()).fromJson(r.getReader(), new TypeToken<CapabilityInfo>() {
        }.getType());
        for (String c : GlobalCapability.getAllNames()) {
            if (ADMINISTRATE_SERVER.equals(c)) {
                assertThat(info.administrateServer).isFalse();
            } else if (BATCH_CHANGES_LIMIT.equals(c)) {
                assertThat(info.batchChangesLimit.min).isEqualTo((short) 0);
                assertThat(info.batchChangesLimit.max).isEqualTo((short) DEFAULT_MAX_BATCH_CHANGES_LIMIT);
            } else if (PRIORITY.equals(c)) {
                assertThat(info.priority).isFalse();
            } else if (QUERY_LIMIT.equals(c)) {
                assertThat(info.queryLimit.min).isEqualTo((short) 0);
                assertThat(info.queryLimit.max).isEqualTo((short) DEFAULT_MAX_QUERY_LIMIT);
            } else {
                assert_().withFailureMessage(String.format("capability %s was not granted", c)).that((Boolean) CapabilityInfo.class.getField(c).get(info)).isTrue();
            }
        }
    } finally {
        removeGlobalCapabilities(REGISTERED_USERS, all);
    }
}
Also used : RestResponse(com.google.gerrit.acceptance.RestResponse) TypeToken(com.google.gson.reflect.TypeToken) Gson(com.google.gson.Gson) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 42 with RestResponse

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

the class GetAccountDetailIT method getDetail.

@Test
public void getDetail() throws Exception {
    RestResponse r = adminRestSession.get("/accounts/" + admin.username + "/detail/");
    AccountDetailInfo info = newGson().fromJson(r.getReader(), AccountDetailInfo.class);
    assertAccountInfo(admin, info);
    Account account = accountCache.get(admin.getId()).getAccount();
    assertThat(info.registeredOn).isEqualTo(account.getRegisteredOn());
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) AccountDetailInfo(com.google.gerrit.server.account.GetDetail.AccountDetailInfo) RestResponse(com.google.gerrit.acceptance.RestResponse) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 43 with RestResponse

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

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

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

the class ImpersonationIT method runAsNotPermitted.

@Test
public void runAsNotPermitted() throws Exception {
    RestResponse res = adminRestSession.getWithHeader("/changes/", runAsHeader(user.id));
    res.assertForbidden();
    assertThat(res.getEntityContent()).isEqualTo("not permitted to use X-Gerrit-RunAs");
}
Also used : RestResponse(com.google.gerrit.acceptance.RestResponse) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

RestResponse (com.google.gerrit.acceptance.RestResponse)79 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)67 Test (org.junit.Test)67 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)17 TypeToken (com.google.gson.reflect.TypeToken)15 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)9 CacheInfo (com.google.gerrit.server.config.ListCaches.CacheInfo)6 TaskInfo (com.google.gerrit.server.config.ListTasks.TaskInfo)6 ReviewResult (com.google.gerrit.extensions.api.changes.ReviewResult)5 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)5 Result (com.google.gerrit.acceptance.PushOneCommit.Result)4 AccountExternalIdInfo (com.google.gerrit.extensions.common.AccountExternalIdInfo)4 LabelInfo (com.google.gerrit.extensions.common.LabelInfo)4 ArrayList (java.util.ArrayList)4 ApprovalInfo (com.google.gerrit.extensions.common.ApprovalInfo)3 Truth.assertThat (com.google.common.truth.Truth.assertThat)2 TestProjectInput (com.google.gerrit.acceptance.TestProjectInput)2 EmailInput (com.google.gerrit.extensions.api.accounts.EmailInput)2 AddReviewerInput (com.google.gerrit.extensions.api.changes.AddReviewerInput)2 PublishChangeEditInput (com.google.gerrit.extensions.api.changes.PublishChangeEditInput)2