Search in sources :

Example 1 with MetaDataUpdate

use of com.google.gerrit.server.git.meta.MetaDataUpdate 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)

Example 2 with MetaDataUpdate

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

the class AbstractGroupTest method createMetaDataUpdate.

protected MetaDataUpdate createMetaDataUpdate(PersonIdent authorIdent) {
    MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, allUsersName, allUsersRepo);
    md.getCommitBuilder().setAuthor(authorIdent);
    // Committer is always the server identity.
    md.getCommitBuilder().setCommitter(serverIdent);
    return md;
}
Also used : MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate)

Example 3 with MetaDataUpdate

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

the class GroupConfigTest method timestampOfAuthorMatchesSpecifiedUpdatedOnOfUpdatedGroup.

@Test
// Instants
@SuppressWarnings("JdkObsolete")
public void timestampOfAuthorMatchesSpecifiedUpdatedOnOfUpdatedGroup() throws Exception {
    Instant authorTimestamp = toInstant(LocalDate.of(2017, Month.DECEMBER, 13).atTime(15, 5, 27));
    Instant updatedOn = toInstant(LocalDate.of(2016, Month.MARCH, 11).atTime(23, 49, 11));
    createArbitraryGroup(groupUuid);
    GroupDelta groupDelta = GroupDelta.builder().setName(AccountGroup.nameKey("Another name")).setUpdatedOn(updatedOn).build();
    GroupConfig groupConfig = GroupConfig.loadForGroup(projectName, repository, groupUuid);
    groupConfig.setGroupDelta(groupDelta, auditLogFormatter);
    PersonIdent authorIdent = new PersonIdent("Jane", "Jane@gerritcodereview.com", Date.from(authorTimestamp), timeZone);
    try (MetaDataUpdate metaDataUpdate = createMetaDataUpdate()) {
        metaDataUpdate.getCommitBuilder().setAuthor(authorIdent);
        groupConfig.commit(metaDataUpdate);
    }
    RevCommit revCommit = getLatestCommitForGroup(groupUuid);
    assertThat(revCommit.getAuthorIdent().getWhen().getTime()).isEqualTo(updatedOn.toEpochMilli());
    assertThat(revCommit.getAuthorIdent().getTimeZone().getRawOffset()).isEqualTo(timeZone.getRawOffset());
}
Also used : PersonIdent(org.eclipse.jgit.lib.PersonIdent) Instant(java.time.Instant) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 4 with MetaDataUpdate

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

the class GroupConfigTest method nameOfNewGroupMustNotBeEmpty.

@Test
public void nameOfNewGroupMustNotBeEmpty() throws Exception {
    InternalGroupCreation groupCreation = getPrefilledGroupCreationBuilder().setNameKey(AccountGroup.nameKey("")).build();
    GroupConfig groupConfig = GroupConfig.createForNewGroup(projectName, repository, groupCreation);
    try (MetaDataUpdate metaDataUpdate = createMetaDataUpdate()) {
        Throwable thrown = assertThrows(Throwable.class, () -> groupConfig.commit(metaDataUpdate));
        assertThat(thrown.getCause(), instanceOf(ConfigInvalidException.class));
        assertThat(thrown).hasMessageThat().contains("Name of the group " + groupUuid);
    }
}
Also used : ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate) Test(org.junit.Test)

Example 5 with MetaDataUpdate

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

the class GroupConfigTest method idOfNewGroupMustNotBeNegative.

@Test
public void idOfNewGroupMustNotBeNegative() throws Exception {
    InternalGroupCreation groupCreation = getPrefilledGroupCreationBuilder().setId(AccountGroup.id(-2)).build();
    GroupConfig groupConfig = GroupConfig.createForNewGroup(projectName, repository, groupCreation);
    try (MetaDataUpdate metaDataUpdate = createMetaDataUpdate()) {
        Throwable thrown = assertThrows(Throwable.class, () -> groupConfig.commit(metaDataUpdate));
        assertThat(thrown.getCause(), instanceOf(ConfigInvalidException.class));
        assertThat(thrown).hasMessageThat().contains("ID of the group " + groupUuid);
    }
}
Also used : ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate) Test(org.junit.Test)

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