Search in sources :

Example 6 with ConsistencyProblemInfo

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);
}
Also used : ConsistencyCheckInput(com.google.gerrit.extensions.api.config.ConsistencyCheckInput) ConsistencyCheckInfo(com.google.gerrit.extensions.api.config.ConsistencyCheckInfo) CheckAccountsInput(com.google.gerrit.extensions.api.config.ConsistencyCheckInput.CheckAccountsInput) ConsistencyProblemInfo(com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) TestAccount(com.google.gerrit.acceptance.TestAccount) HashSet(java.util.HashSet) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 7 with ConsistencyProblemInfo

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();
}
Also used : ConsistencyProblemInfo(com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo)

Example 8 with ConsistencyProblemInfo

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);
}
Also used : ConsistencyCheckInput(com.google.gerrit.extensions.api.config.ConsistencyCheckInput) ConsistencyCheckInfo(com.google.gerrit.extensions.api.config.ConsistencyCheckInfo) CheckAccountExternalIdsInput(com.google.gerrit.extensions.api.config.ConsistencyCheckInput.CheckAccountExternalIdsInput) ConsistencyProblemInfo(com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo) HashSet(java.util.HashSet) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 9 with ConsistencyProblemInfo

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;
}
Also used : MutableInteger(org.eclipse.jgit.util.MutableInteger) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) ConsistencyProblemInfo(com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo) HashSet(java.util.HashSet)

Aggregations

ConsistencyProblemInfo (com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo)9 HashSet (java.util.HashSet)5 ArrayList (java.util.ArrayList)4 ObjectId (org.eclipse.jgit.lib.ObjectId)3 Repository (org.eclipse.jgit.lib.Repository)3 RevWalk (org.eclipse.jgit.revwalk.RevWalk)3 ListMultimap (com.google.common.collect.ListMultimap)2 MultimapBuilder (com.google.common.collect.MultimapBuilder)2 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)2 AccountGroup (com.google.gerrit.entities.AccountGroup)2 InternalGroup (com.google.gerrit.entities.InternalGroup)2 ConsistencyCheckInfo (com.google.gerrit.extensions.api.config.ConsistencyCheckInfo)2 ConsistencyCheckInput (com.google.gerrit.extensions.api.config.ConsistencyCheckInput)2 AccountCache (com.google.gerrit.server.account.AccountCache)2 HashedPassword (com.google.gerrit.server.account.HashedPassword)2 SCHEME_USERNAME (com.google.gerrit.server.account.externalids.ExternalId.SCHEME_USERNAME)2 AllUsersName (com.google.gerrit.server.config.AllUsersName)2 GitRepositoryManager (com.google.gerrit.server.git.GitRepositoryManager)2 OutgoingEmailValidator (com.google.gerrit.server.mail.send.OutgoingEmailValidator)2 Inject (com.google.inject.Inject)2