Search in sources :

Example 6 with ExternalIdNotes

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

the class ExternalIdIT method addExtId.

private void addExtId(TestRepository<?> testRepo, ExternalId... extIds) throws IOException, DuplicateKeyException, ConfigInvalidException {
    ExternalIdNotes extIdNotes = externalIdNotesFactory.load(testRepo.getRepository());
    extIdNotes.insert(Arrays.asList(extIds));
    try (MetaDataUpdate metaDataUpdate = new MetaDataUpdate(GitReferenceUpdated.DISABLED, null, testRepo.getRepository())) {
        metaDataUpdate.getCommitBuilder().setAuthor(admin.newIdent());
        metaDataUpdate.getCommitBuilder().setCommitter(admin.newIdent());
        extIdNotes.commit(metaDataUpdate);
        externalIdNotesFactory.updateExternalIdCacheAndMaybeReindexAccounts(extIdNotes, ImmutableList.of());
    }
}
Also used : ExternalIdNotes(com.google.gerrit.server.account.externalids.ExternalIdNotes) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate)

Example 7 with ExternalIdNotes

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

the class ExternalIdIT method insertExtIdBehindGerritsBack.

private void insertExtIdBehindGerritsBack(ExternalId extId) throws Exception {
    try (Repository repo = repoManager.openRepository(allUsers)) {
        // Inserting an external ID "behind Gerrit's back" means that the caches are not updated.
        ExternalIdNotes extIdNotes = ExternalIdNotes.load(allUsers, repo, externalIdFactory, IS_USER_NAME_CASE_INSENSITIVE_MIGRATION_MODE);
        extIdNotes.insert(extId);
        try (MetaDataUpdate metaDataUpdate = new MetaDataUpdate(GitReferenceUpdated.DISABLED, null, repo)) {
            metaDataUpdate.getCommitBuilder().setAuthor(admin.newIdent());
            metaDataUpdate.getCommitBuilder().setCommitter(admin.newIdent());
            extIdNotes.commit(metaDataUpdate);
        }
    }
}
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 8 with ExternalIdNotes

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

the class ExternalIdIT method unsetHttpPassword.

@Test
public void unsetHttpPassword() throws Exception {
    ExternalId extId = externalIdFactory.createWithPassword(externalIdKeyFactory.create("y", "1"), user.id(), null, "secret");
    insertExtId(extId);
    ExternalId extIdWithoutPassword = externalIdFactory.create("y", "1", user.id());
    try (Repository allUsersRepo = repoManager.openRepository(allUsers);
        MetaDataUpdate md = metaDataUpdateFactory.create(allUsers)) {
        ExternalIdNotes extIdNotes = externalIdNotesFactory.load(allUsersRepo);
        extIdNotes.upsert(extIdWithoutPassword);
        extIdNotes.commit(md);
        assertThat(extIdNotes.get(extId.key())).hasValue(extIdWithoutPassword);
    }
}
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) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 9 with ExternalIdNotes

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

the class ExternalIdNotesUpsertPreprocessorIT method insert.

@Test
public void insert() throws Exception {
    Account.Id id = Account.id(sequences.nextAccountId());
    ExternalId extId = extIdFactory.create("foo", "bar", id);
    try (Repository allUsersRepo = repoManager.openRepository(allUsers);
        MetaDataUpdate md = metaDataUpdateFactory.create(allUsers)) {
        ExternalIdNotes extIdNotes = extIdNotesFactory.load(allUsersRepo);
        extIdNotes.insert(extId);
        extIdNotes.commit(md);
    }
    assertThat(testPreprocessor.upserted).containsExactly(extId);
}
Also used : Account(com.google.gerrit.entities.Account) 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) Test(org.junit.Test) LightweightPluginDaemonTest(com.google.gerrit.acceptance.LightweightPluginDaemonTest)

Example 10 with ExternalIdNotes

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

the class AccountManagerIT method cannotAuthenticateWithOrphanedExtId.

@Test
public void cannotAuthenticateWithOrphanedExtId() throws Exception {
    String username = "foo";
    ExternalId.Key gerritExtIdKey = externalIdKeyFactory.create(ExternalId.SCHEME_GERRIT, username);
    assertNoSuchExternalIds(gerritExtIdKey);
    // Create orphaned SCHEME_GERRIT external ID.
    Account.Id accountId = Account.id(seq.nextAccountId());
    ExternalId gerritExtId = externalIdFactory.create(gerritExtIdKey, accountId);
    try (Repository allUsersRepo = repoManager.openRepository(allUsers);
        MetaDataUpdate md = metaDataUpdateFactory.create(allUsers)) {
        ExternalIdNotes extIdNotes = extIdNotesFactory.load(allUsersRepo);
        extIdNotes.insert(gerritExtId);
        extIdNotes.commit(md);
    }
    AuthRequest who = authRequestFactory.createForUser(username);
    AccountException thrown = assertThrows(AccountException.class, () -> accountManager.authenticate(who));
    assertThat(thrown).hasMessageThat().contains("Authentication error, account not found");
}
Also used : Account(com.google.gerrit.entities.Account) AuthRequest(com.google.gerrit.server.account.AuthRequest) Repository(org.eclipse.jgit.lib.Repository) AccountException(com.google.gerrit.server.account.AccountException) ExternalIdNotes(com.google.gerrit.server.account.externalids.ExternalIdNotes) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

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