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);
}
}
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());
}
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);
}
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");
}
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");
}
Aggregations