Search in sources :

Example 56 with MetaDataUpdate

use of com.google.gerrit.server.git.meta.MetaDataUpdate in project gerrit by GerritCodeReview.

the class AccountIndexerIT method updateAccountWithoutCacheOrIndex.

private void updateAccountWithoutCacheOrIndex(Account.Id accountId, AccountDelta accountDelta) throws IOException, ConfigInvalidException {
    try (Repository allUsersRepo = repoManager.openRepository(allUsersName);
        MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, allUsersName, allUsersRepo)) {
        PersonIdent ident = serverIdent.get();
        md.getCommitBuilder().setAuthor(ident);
        md.getCommitBuilder().setCommitter(ident);
        AccountConfig accountConfig = new AccountConfig(accountId, allUsersName, allUsersRepo).load();
        accountConfig.setAccountDelta(accountDelta);
        accountConfig.commit(md);
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) PersonIdent(org.eclipse.jgit.lib.PersonIdent) GerritPersonIdent(com.google.gerrit.server.GerritPersonIdent) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate) AccountConfig(com.google.gerrit.server.account.AccountConfig)

Example 57 with MetaDataUpdate

use of com.google.gerrit.server.git.meta.MetaDataUpdate in project gerrit by GerritCodeReview.

the class AccessIT method grantRevertPermissionOnlyWorksOnce.

@Test
public void grantRevertPermissionOnlyWorksOnce() throws Exception {
    grantRevertPermission.execute(newProjectName);
    grantRevertPermission.execute(newProjectName);
    try (Repository repo = repoManager.openRepository(newProjectName)) {
        MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, newProjectName, repo);
        ProjectConfig projectConfig = projectConfigFactory.read(md);
        AccessSection all = projectConfig.getAccessSection(AccessSection.ALL);
        Permission permission = all.getPermission(Permission.REVERT);
        assertThat(permission.getRules()).hasSize(1);
    }
}
Also used : ProjectConfig(com.google.gerrit.server.project.ProjectConfig) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) GrantRevertPermission(com.google.gerrit.server.schema.GrantRevertPermission) Permission(com.google.gerrit.entities.Permission) AccessSection(com.google.gerrit.entities.AccessSection) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 58 with MetaDataUpdate

use of com.google.gerrit.server.git.meta.MetaDataUpdate in project gerrit by GerritCodeReview.

the class ExternalIdIT method createCaseInsensitiveMigrationModeExternalIdBeforeTheMigration.

@Test
@GerritConfig(name = "auth.userNameCaseInsensitive", value = "true")
@GerritConfig(name = "auth.userNameCaseInsensitiveMigrationMode", value = "true")
public void createCaseInsensitiveMigrationModeExternalIdBeforeTheMigration() throws Exception {
    Account.Id accountId = Account.id(66);
    boolean isUserNameCaseInsensitive = false;
    try (Repository allUsersRepo = repoManager.openRepository(allUsers);
        MetaDataUpdate md = metaDataUpdateFactory.create(allUsers)) {
        ExternalIdNotes extIdNotes = externalIdNotesFactory.load(allUsersRepo);
        createExternalId(md, extIdNotes, SCHEME_GERRIT, "JaneDoe", accountId, isUserNameCaseInsensitive);
        createExternalId(md, extIdNotes, SCHEME_USERNAME, "JaneDoe", accountId, isUserNameCaseInsensitive);
        assertThat(getAccountId(extIdNotes, SCHEME_GERRIT, "JaneDoe")).isEqualTo(accountId.get());
        assertThat(getExternalId(extIdNotes, SCHEME_GERRIT, "janedoe").isPresent()).isFalse();
        assertThat(getAccountId(extIdNotes, SCHEME_USERNAME, "JaneDoe")).isEqualTo(accountId.get());
        assertThat(getExternalId(extIdNotes, SCHEME_USERNAME, "janedoe").isPresent()).isFalse();
    }
}
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) 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 59 with MetaDataUpdate

use of com.google.gerrit.server.git.meta.MetaDataUpdate in project gerrit by GerritCodeReview.

the class ExternalIdNotesUpsertPreprocessorIT method blockUpsert_replace.

@Test
public void blockUpsert_replace() throws Exception {
    Account.Id id = Account.id(sequences.nextAccountId());
    ExternalId extId1 = extIdFactory.create("foo", "bar", id, "email1@foo", "hash");
    ExternalId extId2 = extIdFactory.create("foo", "bar", id, "email2@foo", "hash");
    accountsUpdateProvider.get().insert("test", id, u -> u.addExternalId(extId1));
    assertThat(accounts.get(id).get().externalIds()).containsExactly(extId1);
    testPreprocessor.reset();
    testPreprocessor.throwException = true;
    try (Repository allUsersRepo = repoManager.openRepository(allUsers);
        MetaDataUpdate md = metaDataUpdateFactory.create(allUsers)) {
        ExternalIdNotes extIdNotes = extIdNotesFactory.load(allUsersRepo);
        extIdNotes.replace(ImmutableSet.of(extId1), ImmutableSet.of(extId2));
        StorageException e = assertThrows(StorageException.class, () -> extIdNotes.commit(md));
        assertThat(e).hasMessageThat().contains("upsert not good");
    }
    assertThat(testPreprocessor.upserted).isEmpty();
    assertThat(accounts.get(id).get().externalIds()).containsExactly(extId1);
}
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) StorageException(com.google.gerrit.exceptions.StorageException) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate) Test(org.junit.Test) LightweightPluginDaemonTest(com.google.gerrit.acceptance.LightweightPluginDaemonTest)

Example 60 with MetaDataUpdate

use of com.google.gerrit.server.git.meta.MetaDataUpdate in project gerrit by GerritCodeReview.

the class ExternalIdNotesUpsertPreprocessorIT method upsert.

@Test
public void upsert() 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.upsert(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)

Aggregations

MetaDataUpdate (com.google.gerrit.server.git.meta.MetaDataUpdate)84 Test (org.junit.Test)39 Repository (org.eclipse.jgit.lib.Repository)36 ExternalIdNotes (com.google.gerrit.server.account.externalids.ExternalIdNotes)28 ProjectConfig (com.google.gerrit.server.project.ProjectConfig)26 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)22 TestRepository (org.eclipse.jgit.junit.TestRepository)17 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)15 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)15 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)14 Account (com.google.gerrit.entities.Account)13 ExternalId (com.google.gerrit.server.account.externalids.ExternalId)12 PersonIdent (org.eclipse.jgit.lib.PersonIdent)11 RepositoryNotFoundException (org.eclipse.jgit.errors.RepositoryNotFoundException)7 Project (com.google.gerrit.entities.Project)6 LightweightPluginDaemonTest (com.google.gerrit.acceptance.LightweightPluginDaemonTest)5 TestAccount (com.google.gerrit.acceptance.TestAccount)5 AccessSection (com.google.gerrit.entities.AccessSection)5 GroupReference (com.google.gerrit.entities.GroupReference)5 LabelType (com.google.gerrit.entities.LabelType)5