Search in sources :

Example 1 with ExternalIdNotes

use of com.google.gerrit.server.account.externalids.ExternalIdNotes in project gerrit by GerritCodeReview.

the class AccountsUpdate method createExternalIdNotes.

private ExternalIdNotes createExternalIdNotes(Repository allUsersRepo, Optional<ObjectId> rev, Account.Id accountId, AccountDelta update) throws IOException, ConfigInvalidException, DuplicateKeyException {
    ExternalIdNotes.checkSameAccount(Iterables.concat(update.getCreatedExternalIds(), update.getUpdatedExternalIds(), update.getDeletedExternalIds()), accountId);
    ExternalIdNotes extIdNotes = extIdNotesLoader.load(allUsersRepo, rev.orElse(ObjectId.zeroId()));
    extIdNotes.replace(update.getDeletedExternalIds(), update.getCreatedExternalIds());
    extIdNotes.upsert(update.getUpdatedExternalIds());
    return extIdNotes;
}
Also used : ExternalIdNotes(com.google.gerrit.server.account.externalids.ExternalIdNotes)

Example 2 with ExternalIdNotes

use of com.google.gerrit.server.account.externalids.ExternalIdNotes in project gerrit by GerritCodeReview.

the class ExternalIdIT method shouldTolerateDuplicateExternalIdsWhenInMigrationMode.

@Test
@GerritConfig(name = "auth.userNameCaseInsensitive", value = "true")
@GerritConfig(name = "auth.userNameCaseInsensitiveMigrationMode", value = "true")
public void shouldTolerateDuplicateExternalIdsWhenInMigrationMode() throws Exception {
    Account.Id firstAccountId = Account.id(1);
    Account.Id secondAccountId = Account.id(2);
    try (Repository allUsersRepo = repoManager.openRepository(allUsers);
        MetaDataUpdate md = metaDataUpdateFactory.create(allUsers)) {
        ExternalIdNotes extIdNotes = externalIdNotesFactory.load(allUsersRepo);
        createExternalId(md, extIdNotes, SCHEME_GERRIT, "janedoe", firstAccountId, CASE_SENSITIVE_USERNAME);
        createExternalId(md, extIdNotes, SCHEME_GERRIT, "JaneDoe", secondAccountId, CASE_SENSITIVE_USERNAME);
        ExternalId.Key firstAccountExternalId = externalIdKeyFactory.create(SCHEME_GERRIT, "janedoe", CASE_INSENSITIVE_USERNAME);
        assertThat(externalIds.get(firstAccountExternalId).get().accountId()).isEqualTo(firstAccountId);
        ExternalId.Key secondAccountExternalId = externalIdKeyFactory.create(SCHEME_GERRIT, "JaneDoe", CASE_INSENSITIVE_USERNAME);
        assertThat(externalIds.get(secondAccountExternalId).get().accountId()).isEqualTo(secondAccountId);
    }
}
Also used : TestAccount(com.google.gerrit.acceptance.TestAccount) Account(com.google.gerrit.entities.Account) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) ExternalIdNotes(com.google.gerrit.server.account.externalids.ExternalIdNotes) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 3 with ExternalIdNotes

use of com.google.gerrit.server.account.externalids.ExternalIdNotes in project gerrit by GerritCodeReview.

the class ExternalIdIT method createCaseSensitiveExternalId_SchemeWithoutUsername.

@Test
@GerritConfig(name = "auth.userNameCaseInsensitive", value = "true")
public void createCaseSensitiveExternalId_SchemeWithoutUsername() throws Exception {
    try (Repository allUsersRepo = repoManager.openRepository(allUsers);
        MetaDataUpdate md = metaDataUpdateFactory.create(allUsers)) {
        ExternalIdNotes extIdNotes = externalIdNotesFactory.load(allUsersRepo);
        testCaseSensitiveExternalIdKey(md, extIdNotes, SCHEME_MAILTO, "Jane@doe.com", Account.id(66));
        testCaseSensitiveExternalIdKey(md, extIdNotes, SCHEME_UUID, "1234ABCD", Account.id(66));
        testCaseSensitiveExternalIdKey(md, extIdNotes, SCHEME_GPGKEY, "1234ABCD", Account.id(66));
    }
}
Also used : InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) ExternalIdNotes(com.google.gerrit.server.account.externalids.ExternalIdNotes) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 4 with ExternalIdNotes

use of com.google.gerrit.server.account.externalids.ExternalIdNotes in project gerrit by GerritCodeReview.

the class ExternalIdIT method insertExtIdForNonExistingAccount.

private void insertExtIdForNonExistingAccount(ExternalId extId) throws Exception {
    // Cannot use AccountsUpdate to insert an external ID for a non-existing account.
    try (Repository repo = repoManager.openRepository(allUsers);
        MetaDataUpdate update = metaDataUpdateFactory.create(allUsers)) {
        ExternalIdNotes extIdNotes = externalIdNotesFactory.load(repo);
        extIdNotes.insert(extId);
        extIdNotes.commit(update);
        externalIdNotesFactory.updateExternalIdCacheAndMaybeReindexAccounts(extIdNotes, ImmutableList.of());
    }
}
Also used : InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) ExternalIdNotes(com.google.gerrit.server.account.externalids.ExternalIdNotes) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate)

Example 5 with ExternalIdNotes

use of com.google.gerrit.server.account.externalids.ExternalIdNotes in project gerrit by GerritCodeReview.

the class ExternalIdIT method createCaseInsensitiveExternalId_DuplicateKey.

@Test
@GerritConfig(name = "auth.userNameCaseInsensitive", value = "true")
public void createCaseInsensitiveExternalId_DuplicateKey() throws Exception {
    try (Repository allUsersRepo = repoManager.openRepository(allUsers);
        MetaDataUpdate md = metaDataUpdateFactory.create(allUsers)) {
        ExternalIdNotes extIdNotes = externalIdNotesFactory.load(allUsersRepo);
        testCaseInsensitiveExternalIdKey(md, extIdNotes, SCHEME_USERNAME, "JohnDoe", Account.id(42));
        assertThrows(DuplicateExternalIdKeyException.class, () -> extIdNotes.insert(externalIdFactory.create(SCHEME_USERNAME, "johndoe", Account.id(23))));
    }
}
Also used : InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) ExternalIdNotes(com.google.gerrit.server.account.externalids.ExternalIdNotes) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

ExternalIdNotes (com.google.gerrit.server.account.externalids.ExternalIdNotes)31 MetaDataUpdate (com.google.gerrit.server.git.meta.MetaDataUpdate)29 Repository (org.eclipse.jgit.lib.Repository)28 Test (org.junit.Test)23 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)18 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)14 ExternalId (com.google.gerrit.server.account.externalids.ExternalId)13 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)12 TestRepository (org.eclipse.jgit.junit.TestRepository)12 Account (com.google.gerrit.entities.Account)11 LightweightPluginDaemonTest (com.google.gerrit.acceptance.LightweightPluginDaemonTest)5 TestAccount (com.google.gerrit.acceptance.TestAccount)5 FactoryModule (com.google.gerrit.extensions.config.FactoryModule)2 GitReferenceUpdated (com.google.gerrit.server.extensions.events.GitReferenceUpdated)2 GitRepositoryManager (com.google.gerrit.server.git.GitRepositoryManager)2 Injector (com.google.inject.Injector)2 PersonIdent (org.eclipse.jgit.lib.PersonIdent)2 DuplicateKeyException (com.google.gerrit.exceptions.DuplicateKeyException)1 StorageException (com.google.gerrit.exceptions.StorageException)1 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)1