use of com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo in project gerrit by GerritCodeReview.
the class AccountIT method checkConsistency.
@Test
public void checkConsistency() throws Exception {
projectOperations.allProjectsForUpdate().add(allowCapability(GlobalCapability.ACCESS_DATABASE).group(REGISTERED_USERS)).update();
requestScopeOperations.resetCurrentApiUser();
// Create an account with a preferred email.
String username = name("foo");
String email = username + "@example.com";
TestAccount account = accountCreator.create(username, email, "Foo Bar", null);
ConsistencyCheckInput input = new ConsistencyCheckInput();
input.checkAccounts = new CheckAccountsInput();
ConsistencyCheckInfo checkInfo = gApi.config().server().checkConsistency(input);
assertThat(checkInfo.checkAccountsResult.problems).isEmpty();
Set<ConsistencyProblemInfo> expectedProblems = new HashSet<>();
// Delete the external ID for the preferred email. This makes the account inconsistent since it
// now doesn't have an external ID for its preferred email.
accountsUpdateProvider.get().update("Delete External ID", account.id(), u -> u.deleteExternalId(externalIdFactory.createEmail(account.id(), email)));
expectedProblems.add(new ConsistencyProblemInfo(ConsistencyProblemInfo.Status.ERROR, "Account '" + account.id().get() + "' has no external ID for its preferred email '" + email + "'"));
checkInfo = gApi.config().server().checkConsistency(input);
assertThat(checkInfo.checkAccountsResult.problems).hasSize(expectedProblems.size());
assertThat(checkInfo.checkAccountsResult.problems).containsExactlyElementsIn(expectedProblems);
}
use of com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo in project gerrit by GerritCodeReview.
the class GroupsConsistencyIT method assertConsistency.
private void assertConsistency(String msg, ConsistencyProblemInfo.Status want) throws Exception {
List<ConsistencyProblemInfo> problems = check();
for (ConsistencyProblemInfo i : problems) {
if (!i.status.equals(want)) {
continue;
}
if (i.message.contains(msg)) {
return;
}
}
assertWithMessage(String.format("could not find %s substring '%s' in %s", want, msg, problems)).fail();
}
use of com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo in project gerrit by GerritCodeReview.
the class ExternalIdIT method checkConsistency.
@Test
public void checkConsistency() throws Exception {
projectOperations.allProjectsForUpdate().add(allowCapability(GlobalCapability.ACCESS_DATABASE).group(REGISTERED_USERS)).update();
requestScopeOperations.resetCurrentApiUser();
insertValidExternalIds();
ConsistencyCheckInput input = new ConsistencyCheckInput();
input.checkAccountExternalIds = new CheckAccountExternalIdsInput();
ConsistencyCheckInfo checkInfo = gApi.config().server().checkConsistency(input);
assertThat(checkInfo.checkAccountExternalIdsResult.problems).isEmpty();
Set<ConsistencyProblemInfo> expectedProblems = new HashSet<>();
expectedProblems.addAll(insertInvalidButParsableExternalIds());
expectedProblems.addAll(insertNonParsableExternalIds());
checkInfo = gApi.config().server().checkConsistency(input);
assertThat(checkInfo.checkAccountExternalIdsResult.problems).hasSize(expectedProblems.size());
assertThat(checkInfo.checkAccountExternalIdsResult.problems).containsExactlyElementsIn(expectedProblems);
}
use of com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo in project gerrit by GerritCodeReview.
the class ExternalIdIT method insertInvalidButParsableExternalIds.
private Set<ConsistencyProblemInfo> insertInvalidButParsableExternalIds() throws Exception {
MutableInteger i = new MutableInteger();
String scheme = "invalid";
Set<ConsistencyProblemInfo> expectedProblems = new HashSet<>();
ExternalId extIdForNonExistingAccount = createExternalIdForNonExistingAccount(nextId(scheme, i));
insertExtIdForNonExistingAccount(extIdForNonExistingAccount);
expectedProblems.add(consistencyError("External ID '" + extIdForNonExistingAccount.key().get() + "' belongs to account that doesn't exist: " + extIdForNonExistingAccount.accountId().get()));
ExternalId extIdWithInvalidEmail = createExternalIdWithInvalidEmail(nextId(scheme, i));
insertExtId(extIdWithInvalidEmail);
expectedProblems.add(consistencyError("External ID '" + extIdWithInvalidEmail.key().get() + "' has an invalid email: " + extIdWithInvalidEmail.email()));
ExternalId extIdWithDuplicateEmail = createExternalIdWithDuplicateEmail(nextId(scheme, i));
insertExtId(extIdWithDuplicateEmail);
expectedProblems.add(consistencyError("Email '" + extIdWithDuplicateEmail.email() + "' is not unique, it's used by the following external IDs: '" + extIdWithDuplicateEmail.key().get() + "', 'mailto:" + extIdWithDuplicateEmail.email() + "'"));
ExternalId extIdWithBadPassword = createExternalIdWithBadPassword("admin-username");
insertExtId(extIdWithBadPassword);
expectedProblems.add(consistencyError("External ID '" + extIdWithBadPassword.key().get() + "' has an invalid password: unrecognized algorithm"));
return expectedProblems;
}
Aggregations