use of com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS in project gerrit by GerritCodeReview.
the class AccountIT method atomicReadMofifyWriteExternalIds.
@Test
public void atomicReadMofifyWriteExternalIds() throws Exception {
projectOperations.allProjectsForUpdate().add(allowCapability(GlobalCapability.ACCESS_DATABASE).group(REGISTERED_USERS)).update();
Account.Id accountId = Account.id(seq.nextAccountId());
ExternalId extIdA1 = externalIdFactory.create("foo", "A-1", accountId);
accountsUpdateProvider.get().insert("Create Test Account", accountId, u -> u.addExternalId(extIdA1));
AtomicInteger bgCounterA1 = new AtomicInteger(0);
AtomicInteger bgCounterA2 = new AtomicInteger(0);
PersonIdent ident = serverIdent.get();
ExternalId extIdA2 = externalIdFactory.create("foo", "A-2", accountId);
AccountsUpdate update = new AccountsUpdate(repoManager, gitReferenceUpdated, Optional.empty(), allUsers, externalIds, metaDataUpdateInternalFactory, new RetryHelper(cfg, retryMetrics, null, null, null, exceptionHooks, r -> r.withBlockStrategy(noSleepBlockStrategy)), extIdNotesFactory, ident, ident, Runnables.doNothing(), () -> {
try {
accountsUpdateProvider.get().update("Update External ID", accountId, u -> u.replaceExternalId(extIdA1, extIdA2));
} catch (IOException | ConfigInvalidException | StorageException e) {
// Ignore, the expected exception is asserted later
}
});
assertThat(bgCounterA1.get()).isEqualTo(0);
assertThat(bgCounterA2.get()).isEqualTo(0);
assertThat(gApi.accounts().id(accountId.get()).getExternalIds().stream().map(i -> i.identity).collect(toSet())).containsExactly(extIdA1.key().get());
ExternalId extIdB1 = externalIdFactory.create("foo", "B-1", accountId);
ExternalId extIdB2 = externalIdFactory.create("foo", "B-2", accountId);
Optional<AccountState> updatedAccount = update.update("Update External ID", accountId, (a, u) -> {
if (a.externalIds().contains(extIdA1)) {
bgCounterA1.getAndIncrement();
u.replaceExternalId(extIdA1, extIdB1);
}
if (a.externalIds().contains(extIdA2)) {
bgCounterA2.getAndIncrement();
u.replaceExternalId(extIdA2, extIdB2);
}
});
assertThat(bgCounterA1.get()).isEqualTo(1);
assertThat(bgCounterA2.get()).isEqualTo(1);
assertThat(updatedAccount).isPresent();
assertThat(updatedAccount.get().externalIds()).containsExactly(extIdB2);
assertThat(accounts.get(accountId).get().externalIds()).containsExactly(extIdB2);
assertThat(gApi.accounts().id(accountId.get()).getExternalIds().stream().map(i -> i.identity).collect(toSet())).containsExactly(extIdB2.key().get());
}
use of com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS in project gerrit by GerritCodeReview.
the class QueryChangesIT method withPagedResults.
@Test
@UseClockStep
@SuppressWarnings("unchecked")
public void withPagedResults() throws Exception {
// Create 4 visible changes.
createChange(testRepo).getChange().getId().get();
createChange(testRepo).getChange().getId().get();
int changeId3 = createChange(testRepo).getChange().getId().get();
int changeId4 = createChange(testRepo).getChange().getId().get();
// Create hidden project.
Project.NameKey hiddenProject = projectOperations.newProject().create();
TestRepository<InMemoryRepository> hiddenRepo = cloneProject(hiddenProject, admin);
// Create 2 hidden changes.
createChange(hiddenRepo);
createChange(hiddenRepo);
// Actually hide project
projectOperations.project(hiddenProject).forUpdate().add(block(Permission.READ).ref("refs/*").group(REGISTERED_USERS)).update();
// Create a change query that matches all changes (visible and hidden changes).
// The index returns the changes ordered by last updated timestamp:
// hiddenChange2, hiddenChange1, change4, change3, change2, change1
QueryChanges queryChanges = queryChangesProvider.get();
queryChanges.addQuery("branch:master");
// Set a limit on the query so that we need to paginate over the results from the index.
queryChanges.setLimit(2);
// Execute the query and verify the results.
// Since the limit is set to 2, at most 2 changes are returned to user, but the index query is
// executed with limit 3 (+1 so that we can populate the _more_changes field on the last
// result).
// This means the index query with limit 3 returns these changes:
// hiddenChange2, hiddenChange1, change4
// The 2 hidden changes are filtered out because they are not visible to the caller.
// This means we have only one matching result (change4) but the limit (3) is not exhausted
// yet. Hence the next page is loaded from the index (startIndex is 3 to skip the results
// that we already processed, limit is again 3). The results for the next page are:
// change3, change2, change1
// change2 and change1 are dropped because they are over the limit.
List<ChangeInfo> result = (List<ChangeInfo>) queryChanges.apply(TopLevelResource.INSTANCE).value();
assertThat(result.stream().map(i -> i._number).collect(toList())).containsExactly(changeId3, changeId4);
}
use of com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS in project gerrit by GerritCodeReview.
the class SubmitRequirementIT method submitRequirement_partiallyOverriddenSRIsIgnored.
@Test
public void submitRequirement_partiallyOverriddenSRIsIgnored() throws Exception {
// Create build-cop-override label
LabelDefinitionInput input = new LabelDefinitionInput();
input.function = "NoOp";
input.values = ImmutableMap.of("+1", "Override", " 0", "No Override");
gApi.projects().name(project.get()).label("build-cop-override").create(input).get();
// Allow to vote on the build-cop-override label.
projectOperations.project(project).forUpdate().add(TestProjectUpdate.allowLabel("build-cop-override").range(0, 1).ref("refs/*").group(REGISTERED_USERS).build()).update();
// Define submit requirement in root project.
configSubmitRequirement(allProjects, SubmitRequirement.builder().setName("Code-Review").setSubmittabilityExpression(SubmitRequirementExpression.create("label:Code-Review=+1")).setOverrideExpression(SubmitRequirementExpression.of("label:build-cop-override=+1")).setAllowOverrideInChildProjects(true).build());
// Create Code-Review-Override label
gApi.projects().name(project.get()).label("Code-Review-Override").create(input).get();
// Allow to vote on the Code-Review-Override label.
projectOperations.project(project).forUpdate().add(TestProjectUpdate.allowLabel("Code-Review-Override").range(0, 1).ref("refs/*").group(REGISTERED_USERS).build()).update();
// Override submit requirement in project (requires Code-Review-Override+1 as override instead
// of build-cop-override+1), but do not set all required properties (submittability expression
// is missing). We update the project.config file directly in the remote repository, since
// trying to push such a submit requirement would be rejected by the commit validation.
projectOperations.project(project).forInvalidation().addProjectConfigUpdater(config -> config.setString(ProjectConfig.SUBMIT_REQUIREMENT, "Code-Review", ProjectConfig.KEY_SR_OVERRIDE_EXPRESSION, "label:Code-Review-Override=+1")).invalidate();
PushOneCommit.Result r = createChange();
String changeId = r.getChangeId();
ChangeInfo change = gApi.changes().id(changeId).get();
assertThat(change.submitRequirements).hasSize(1);
assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.UNSATISFIED, /* isLegacy= */
false);
voteLabel(changeId, "Code-Review-Override", 1);
change = gApi.changes().id(changeId).get();
assertThat(change.submitRequirements).hasSize(1);
// The override expression in the project is satisfied, but it's ignored since the SR is
// incomplete.
assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.UNSATISFIED, /* isLegacy= */
false);
voteLabel(changeId, "build-cop-override", 1);
change = gApi.changes().id(changeId).get();
assertThat(change.submitRequirements).hasSize(2);
// The submit requirement is overridden now (the override expression in the child project is
// ignored)
assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.OVERRIDDEN, /* isLegacy= */
false);
// Legacy requirement is coming from the label MaxWithBlock function. Still unsatisfied.
assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.UNSATISFIED, /* isLegacy= */
true);
}
use of com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS in project gerrit by GerritCodeReview.
the class CapabilitiesIT method capabilitiesUser.
@Test
public void capabilitiesUser() throws Exception {
ImmutableList<String> all = GlobalCapability.getAllNames().stream().filter(c -> !ADMINISTRATE_SERVER.equals(c) && !PRIORITY.equals(c)).collect(toImmutableList());
TestProjectUpdate.Builder allowBuilder = projectOperations.allProjectsForUpdate();
all.forEach(c -> allowBuilder.add(allowCapability(c).group(REGISTERED_USERS)));
allowBuilder.update();
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 {
assertWithMessage(String.format("capability %s was not granted", c)).that((Boolean) CapabilityInfo.class.getField(c).get(info)).isTrue();
}
}
} finally {
TestProjectUpdate.Builder removeBuilder = projectOperations.allProjectsForUpdate();
all.forEach(c -> removeBuilder.remove(capabilityKey(c).group(REGISTERED_USERS)));
removeBuilder.update();
}
}
use of com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS in project gerrit by GerritCodeReview.
the class MoveChangeIT method moveKeepAllVotesCanMoveAllInRange.
@Test
public void moveKeepAllVotesCanMoveAllInRange() throws Exception {
BranchNameKey destinationBranch = BranchNameKey.create(project, "dest");
createBranch(destinationBranch);
BranchNameKey sourceBranch = BranchNameKey.create(project, "source");
createBranch(sourceBranch);
// The non-block label has the range [-2; 2]
String testLabelA = "Label-A";
configLabel(project, testLabelA, LabelFunction.NO_BLOCK, value(2, "Passes"), value(1, "Mostly ok"), value(0, "No score"), value(-1, "Needs work"), value(-2, "Failed"));
// Registered users have [-2; 2] permissions on all branches.
projectOperations.project(project).forUpdate().add(allowLabel(testLabelA).ref("refs/heads/*").group(REGISTERED_USERS).range(-2, +2)).update();
String changeId = createChangeInBranch(sourceBranch.branch()).getChangeId();
for (int vote = -2; vote <= 2; vote++) {
TestAccount testUser = accountCreator.create("TestUser" + vote);
requestScopeOperations.setApiUser(testUser.id());
ReviewInput userReviewInput = new ReviewInput();
userReviewInput.label(testLabelA, vote);
gApi.changes().id(changeId).current().review(userReviewInput);
}
assertThat(gApi.changes().id(changeId).current().votes().get(testLabelA).stream().map(approvalInfo -> approvalInfo.value).collect(ImmutableList.toImmutableList())).containsExactly(-2, -1, 1, 2);
requestScopeOperations.setApiUser(admin.id());
// Move the change to the destination branch.
assertThat(info(changeId).branch).isEqualTo(sourceBranch.shortName());
move(changeId, destinationBranch.shortName(), true);
assertThat(info(changeId).branch).isEqualTo(destinationBranch.shortName());
// All votes are kept
assertThat(gApi.changes().id(changeId).current().votes().get(testLabelA).stream().map(approvalInfo -> approvalInfo.value).collect(ImmutableList.toImmutableList())).containsExactly(-2, -1, 1, 2);
// Move the change back to the source, the label is kept.
move(changeId, sourceBranch.shortName(), true);
assertThat(info(changeId).branch).isEqualTo(sourceBranch.shortName());
assertThat(gApi.changes().id(changeId).current().votes().get(testLabelA).stream().map(approvalInfo -> approvalInfo.value).collect(ImmutableList.toImmutableList())).containsExactly(-2, -1, 1, 2);
}
Aggregations