Search in sources :

Example 51 with AccountState

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

the class AccountIT method updateNonExistingAccount.

@Test
public void updateNonExistingAccount() throws Exception {
    Account.Id nonExistingAccountId = Account.id(999999);
    AtomicBoolean consumerCalled = new AtomicBoolean();
    Optional<AccountState> accountState = accountsUpdateProvider.get().update("Update Non-Existing Account", nonExistingAccountId, a -> consumerCalled.set(true));
    assertThat(accountState).isEmpty();
    assertThat(consumerCalled.get()).isFalse();
}
Also used : TestAccount(com.google.gerrit.acceptance.TestAccount) Account(com.google.gerrit.entities.Account) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AccountState(com.google.gerrit.server.account.AccountState) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 52 with AccountState

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

the class AccountIT method checkMetaId.

@Test
public void checkMetaId() throws Exception {
    // metaId is set when account is loaded
    assertThat(accounts.get(admin.id()).get().account().metaId()).isEqualTo(getMetaId(admin.id()));
    // metaId is set when account is created
    AccountsUpdate au = accountsUpdateProvider.get();
    Account.Id accountId = Account.id(seq.nextAccountId());
    AccountState accountState = au.insert("Create Test Account", accountId, u -> {
    });
    assertThat(accountState.account().metaId()).isEqualTo(getMetaId(accountId));
    // metaId is set when account is updated
    Optional<AccountState> updatedAccountState = au.update("Set Full Name", accountId, u -> u.setFullName("foo"));
    assertThat(updatedAccountState).isPresent();
    Account updatedAccount = updatedAccountState.get().account();
    assertThat(accountState.account().metaId()).isNotEqualTo(updatedAccount.metaId());
    assertThat(updatedAccount.metaId()).isEqualTo(getMetaId(accountId));
}
Also used : TestAccount(com.google.gerrit.acceptance.TestAccount) Account(com.google.gerrit.entities.Account) AccountsUpdate(com.google.gerrit.server.account.AccountsUpdate) AccountState(com.google.gerrit.server.account.AccountState) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 53 with AccountState

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

the class AccountIT method externalIdBatchUpdates.

@Test
public void externalIdBatchUpdates() throws Exception {
    String extId1String = "foo:bar";
    String extId2String = "foo:baz";
    ExternalId extId1 = externalIdFactory.createWithEmail(externalIdKeyFactory.parse(extId1String), admin.id(), "1@foo.com");
    ExternalId extId2 = externalIdFactory.createWithEmail(externalIdKeyFactory.parse(extId2String), user.id(), "2@foo.com");
    ObjectId revBefore;
    try (Repository repo = repoManager.openRepository(allUsers)) {
        revBefore = repo.exactRef(RefNames.REFS_EXTERNAL_IDS).getObjectId();
    }
    AccountsUpdate.UpdateArguments ua1 = new AccountsUpdate.UpdateArguments("Add External ID", admin.id(), (a, u) -> u.addExternalId(extId1));
    AccountsUpdate.UpdateArguments ua2 = new AccountsUpdate.UpdateArguments("Add External ID", user.id(), (a, u) -> u.addExternalId(extId2));
    ImmutableList<Optional<AccountState>> accountStates = accountsUpdateProvider.get().updateBatch(ImmutableList.of(ua1, ua2));
    assertThat(accountStates).hasSize(2);
    assertThat(accountStates.get(0).get().externalIds()).contains(extId1);
    assertThat(accountStates.get(1).get().externalIds()).contains(extId2);
    assertThat(gApi.accounts().id(admin.id().get()).getExternalIds().stream().map(e -> e.identity).collect(toSet())).contains(extId1String);
    assertThat(gApi.accounts().id(user.id().get()).getExternalIds().stream().map(e -> e.identity).collect(toSet())).contains(extId2String);
    // Ensure that we only applied one single commit.
    try (Repository repo = repoManager.openRepository(allUsers);
        RevWalk rw = new RevWalk(repo)) {
        RevCommit after = rw.parseCommit(repo.exactRef(RefNames.REFS_EXTERNAL_IDS).getObjectId());
        assertThat(after.getParent(0).toObjectId()).isEqualTo(revBefore);
    }
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) ExternalIdKeyFactory(com.google.gerrit.server.account.externalids.ExternalIdKeyFactory) KeyPair(java.security.KeyPair) Arrays(java.util.Arrays) OBJ_BLOB(org.eclipse.jgit.lib.Constants.OBJ_BLOB) GlobalCapability(com.google.gerrit.common.data.GlobalCapability) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) TestAccount(com.google.gerrit.acceptance.TestAccount) TestProjectUpdate.deny(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.deny) REGISTERED_USERS(com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevWalk(org.eclipse.jgit.revwalk.RevWalk) Config(org.eclipse.jgit.lib.Config) TestKey(com.google.gerrit.gpg.testing.TestKey) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) FluentIterable(com.google.common.collect.FluentIterable) GpgKeyInfo(com.google.gerrit.extensions.common.GpgKeyInfo) Map(java.util.Map) RetryHelper(com.google.gerrit.server.update.RetryHelper) GroupOperations(com.google.gerrit.acceptance.testsuite.group.GroupOperations) TestProjectUpdate.allow(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allow) DeleteDraftCommentsInput(com.google.gerrit.extensions.api.accounts.DeleteDraftCommentsInput) DeletedDraftCommentInfo(com.google.gerrit.extensions.api.accounts.DeletedDraftCommentInfo) GitUtil.deleteRef(com.google.gerrit.acceptance.GitUtil.deleteRef) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) AccessSection(com.google.gerrit.entities.AccessSection) ConsistencyCheckInfo(com.google.gerrit.extensions.api.config.ConsistencyCheckInfo) Set(java.util.Set) RefUpdate(org.eclipse.jgit.lib.RefUpdate) PGPPublicKey(org.bouncycastle.openpgp.PGPPublicKey) TestKeys.validKeyWithoutExpiration(com.google.gerrit.gpg.testing.TestKeys.validKeyWithoutExpiration) BranchNameKey(com.google.gerrit.entities.BranchNameKey) ExternalIds(com.google.gerrit.server.account.externalids.ExternalIds) RequestScopeOperations(com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations) PersonIdent(org.eclipse.jgit.lib.PersonIdent) UseClockStep(com.google.gerrit.acceptance.UseClockStep) AccountProperties(com.google.gerrit.server.account.AccountProperties) Emails(com.google.gerrit.server.account.Emails) PushResult(org.eclipse.jgit.transport.PushResult) PluginSetContext(com.google.gerrit.server.plugincontext.PluginSetContext) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) GitUtil.fetch(com.google.gerrit.acceptance.GitUtil.fetch) Mockito.mock(org.mockito.Mockito.mock) EmailInfo(com.google.gerrit.extensions.common.EmailInfo) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate) ClientProtocolException(org.apache.http.client.ClientProtocolException) Iterables(com.google.common.collect.Iterables) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) RevCommit(org.eclipse.jgit.revwalk.RevCommit) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) AccountOperations(com.google.gerrit.acceptance.testsuite.account.AccountOperations) Fingerprint(com.google.gerrit.gpg.Fingerprint) ArrayList(java.util.ArrayList) AccountInput(com.google.gerrit.extensions.api.accounts.AccountInput) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) TestKeys.validKeyWithExpiration(com.google.gerrit.gpg.testing.TestKeys.validKeyWithExpiration) Runnables(com.google.common.util.concurrent.Runnables) EmailInput(com.google.gerrit.extensions.api.accounts.EmailInput) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) Address(com.google.gerrit.entities.Address) ExtensionRegistry(com.google.gerrit.acceptance.ExtensionRegistry) Before(org.junit.Before) AccountGroup(com.google.gerrit.entities.AccountGroup) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk) ProjectCache.illegalState(com.google.gerrit.server.project.ProjectCache.illegalState) TestRepository(org.eclipse.jgit.junit.TestRepository) Sequences(com.google.gerrit.server.notedb.Sequences) BaseEncoding(com.google.common.io.BaseEncoding) ValidationException(com.google.gerrit.server.validators.ValidationException) StorageException(com.google.gerrit.exceptions.StorageException) AccountActivationListener(com.google.gerrit.extensions.events.AccountActivationListener) IOException(java.io.IOException) Test(org.junit.Test) ANONYMOUS_USERS(com.google.gerrit.server.group.SystemGroupBackend.ANONYMOUS_USERS) StalenessChecker(com.google.gerrit.server.index.account.StalenessChecker) Correspondence(com.google.common.truth.Correspondence) BasicCookieStore(org.apache.http.impl.client.BasicCookieStore) AccountApi(com.google.gerrit.extensions.api.accounts.AccountApi) CacheBasedWebSession(com.google.gerrit.httpd.CacheBasedWebSession) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) ExternalIdNotes(com.google.gerrit.server.account.externalids.ExternalIdNotes) Project(com.google.gerrit.entities.Project) HttpResponse(org.apache.http.HttpResponse) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) TimeUtil(com.google.gerrit.server.util.time.TimeUtil) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) AccountState(com.google.gerrit.server.account.AccountState) ObjectReader(org.eclipse.jgit.lib.ObjectReader) Repository(org.eclipse.jgit.lib.Repository) ObjectInserter(org.eclipse.jgit.lib.ObjectInserter) Date(java.util.Date) Inject(com.google.inject.Inject) REFS_GPG_KEYS(com.google.gerrit.gpg.PublicKeyStore.REFS_GPG_KEYS) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) AccountDetailInfo(com.google.gerrit.extensions.common.AccountDetailInfo) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) DEFAULT_LABEL(com.google.gerrit.server.StarredChangesUtil.DEFAULT_LABEL) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) ConsistencyProblemInfo(com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CheckAccountsInput(com.google.gerrit.extensions.api.config.ConsistencyCheckInput.CheckAccountsInput) Locale(java.util.Locale) After(org.junit.After) RefNames(com.google.gerrit.entities.RefNames) AuthException(com.google.gerrit.extensions.restapi.AuthException) PGPPublicKeyRing(org.bouncycastle.openpgp.PGPPublicKeyRing) AtomicLongMap(com.google.common.util.concurrent.AtomicLongMap) Collectors.toSet(java.util.stream.Collectors.toSet) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) ImmutableSet(com.google.common.collect.ImmutableSet) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) SshSessionFactory(com.google.gerrit.acceptance.testsuite.request.SshSessionFactory) Account(com.google.gerrit.entities.Account) SCHEME_GPGKEY(com.google.gerrit.server.account.externalids.ExternalId.SCHEME_GPGKEY) AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) Collectors(java.util.stream.Collectors) TestSshKeys(com.google.gerrit.acceptance.testsuite.account.TestSshKeys) GroupReference(com.google.gerrit.entities.GroupReference) List(java.util.List) Nullable(com.google.gerrit.common.Nullable) StopStrategies(com.github.rholder.retry.StopStrategies) HttpGet(org.apache.http.client.methods.HttpGet) Ref(org.eclipse.jgit.lib.Ref) ConfigSubject.assertThat(com.google.gerrit.truth.ConfigSubject.assertThat) Optional(java.util.Optional) AuthConfig(com.google.gerrit.server.config.AuthConfig) RefPattern(com.google.gerrit.server.project.RefPattern) AccountIndexer(com.google.gerrit.server.index.account.AccountIndexer) TestProjectUpdate.block(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.block) VersionedAuthorizedKeys(com.google.gerrit.server.account.VersionedAuthorizedKeys) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) PublicKeyStore(com.google.gerrit.gpg.PublicKeyStore) InternalAccountQuery(com.google.gerrit.server.query.account.InternalAccountQuery) SshKeyInfo(com.google.gerrit.extensions.common.SshKeyInfo) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) ConfigSuite(com.google.gerrit.testing.ConfigSuite) HashSet(java.util.HashSet) GitReferenceUpdatedListener(com.google.gerrit.extensions.events.GitReferenceUpdatedListener) GroupInfo(com.google.gerrit.extensions.common.GroupInfo) ImmutableList(com.google.common.collect.ImmutableList) UseSsh(com.google.gerrit.acceptance.UseSsh) ExceptionHook(com.google.gerrit.server.ExceptionHook) CommitBuilder(org.eclipse.jgit.lib.CommitBuilder) Objects.requireNonNull(java.util.Objects.requireNonNull) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ExternalIdFactory(com.google.gerrit.server.account.externalids.ExternalIdFactory) Change(com.google.gerrit.entities.Change) LockFailureException(com.google.gerrit.git.LockFailureException) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) ConsistencyCheckInput(com.google.gerrit.extensions.api.config.ConsistencyCheckInput) AccountActivationValidationListener(com.google.gerrit.server.validators.AccountActivationValidationListener) AccountsUpdate(com.google.gerrit.server.account.AccountsUpdate) TestProjectUpdate.allowCapability(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allowCapability) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) Iterator(java.util.Iterator) Sandboxed(com.google.gerrit.acceptance.Sandboxed) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Permission(com.google.gerrit.entities.Permission) HttpServletResponse(javax.servlet.http.HttpServletResponse) Truth.assertThat(com.google.common.truth.Truth.assertThat) Mockito.verify(org.mockito.Mockito.verify) ObjectId(org.eclipse.jgit.lib.ObjectId) TransportException(org.eclipse.jgit.api.errors.TransportException) TestProjectUpdate.permissionKey(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.permissionKey) ArmoredOutputStream(org.bouncycastle.bcpg.ArmoredOutputStream) Collectors.toList(java.util.stream.Collectors.toList) Provider(com.google.inject.Provider) Message(com.google.gerrit.testing.FakeEmailSender.Message) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) ServerInitiated(com.google.gerrit.server.ServerInitiated) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) NullAwareCorrespondence(com.google.gerrit.truth.NullAwareCorrespondence) DuplicateExternalIdKeyException(com.google.gerrit.server.account.externalids.DuplicateExternalIdKeyException) Git(org.eclipse.jgit.api.Git) TestKeys.allValidKeys(com.google.gerrit.gpg.testing.TestKeys.allValidKeys) TestKeys.validKeyWithSecondUserId(com.google.gerrit.gpg.testing.TestKeys.validKeyWithSecondUserId) PushCertificateIdent(org.eclipse.jgit.transport.PushCertificateIdent) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Action(com.google.gerrit.entities.PermissionRule.Action) GitReferenceUpdated(com.google.gerrit.server.extensions.events.GitReferenceUpdated) TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) Optional(java.util.Optional) ObjectId(org.eclipse.jgit.lib.ObjectId) AccountsUpdate(com.google.gerrit.server.account.AccountsUpdate) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 54 with AccountState

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

the class AccountIT method validateAccountActivation.

@Test
public void validateAccountActivation() throws Exception {
    Account.Id activatableAccountId = accountOperations.newAccount().inactive().preferredEmail("foo@activatable.com").create();
    Account.Id deactivatableAccountId = accountOperations.newAccount().preferredEmail("foo@deactivatable.com").create();
    AccountActivationValidationListener validationListener = new AccountActivationValidationListener() {

        @Override
        public void validateActivation(AccountState account) throws ValidationException {
            String preferredEmail = account.account().preferredEmail();
            if (preferredEmail == null || !preferredEmail.endsWith("@activatable.com")) {
                throw new ValidationException("not allowed to active account");
            }
        }

        @Override
        public void validateDeactivation(AccountState account) throws ValidationException {
            String preferredEmail = account.account().preferredEmail();
            if (preferredEmail == null || !preferredEmail.endsWith("@deactivatable.com")) {
                throw new ValidationException("not allowed to deactive account");
            }
        }
    };
    AccountActivationListener listener = mock(AccountActivationListener.class);
    try (Registration registration = extensionRegistry.newRegistration().add(validationListener).add(listener)) {
        /* Test account that can be activated, but not deactivated */
        // Deactivate account that is already inactive
        ResourceConflictException thrown = assertThrows(ResourceConflictException.class, () -> gApi.accounts().id(activatableAccountId.get()).setActive(false));
        assertThat(thrown).hasMessageThat().isEqualTo("account not active");
        assertThat(accountOperations.account(activatableAccountId).get().active()).isFalse();
        verifyNoInteractions(listener);
        // Activate account that can be activated
        gApi.accounts().id(activatableAccountId.get()).setActive(true);
        assertThat(accountOperations.account(activatableAccountId).get().active()).isTrue();
        verify(listener).onAccountActivated(activatableAccountId.get());
        verifyNoMoreInteractions(listener);
        // Activate account that is already active
        gApi.accounts().id(activatableAccountId.get()).setActive(true);
        assertThat(accountOperations.account(activatableAccountId).get().active()).isTrue();
        verifyNoMoreInteractions(listener);
        // Try deactivating account that cannot be deactivated
        thrown = assertThrows(ResourceConflictException.class, () -> gApi.accounts().id(activatableAccountId.get()).setActive(false));
        assertThat(thrown).hasMessageThat().isEqualTo("not allowed to deactive account");
        assertThat(accountOperations.account(activatableAccountId).get().active()).isTrue();
        verifyNoMoreInteractions(listener);
        /* Test account that can be deactivated, but not activated */
        // Activate account that is already inactive
        gApi.accounts().id(deactivatableAccountId.get()).setActive(true);
        assertThat(accountOperations.account(deactivatableAccountId).get().active()).isTrue();
        verifyNoMoreInteractions(listener);
        // Deactivate account that can be deactivated
        gApi.accounts().id(deactivatableAccountId.get()).setActive(false);
        assertThat(accountOperations.account(deactivatableAccountId).get().active()).isFalse();
        verify(listener).onAccountDeactivated(deactivatableAccountId.get());
        verifyNoMoreInteractions(listener);
        // Deactivate account that is already inactive
        thrown = assertThrows(ResourceConflictException.class, () -> gApi.accounts().id(deactivatableAccountId.get()).setActive(false));
        assertThat(thrown).hasMessageThat().isEqualTo("account not active");
        assertThat(accountOperations.account(deactivatableAccountId).get().active()).isFalse();
        verifyNoMoreInteractions(listener);
        // Try activating account that cannot be activated
        thrown = assertThrows(ResourceConflictException.class, () -> gApi.accounts().id(deactivatableAccountId.get()).setActive(true));
        assertThat(thrown).hasMessageThat().isEqualTo("not allowed to active account");
        assertThat(accountOperations.account(deactivatableAccountId).get().active()).isFalse();
        verifyNoMoreInteractions(listener);
    }
}
Also used : TestAccount(com.google.gerrit.acceptance.TestAccount) Account(com.google.gerrit.entities.Account) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) ValidationException(com.google.gerrit.server.validators.ValidationException) AccountActivationListener(com.google.gerrit.extensions.events.AccountActivationListener) AccountActivationValidationListener(com.google.gerrit.server.validators.AccountActivationValidationListener) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) AccountState(com.google.gerrit.server.account.AccountState) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 55 with AccountState

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

the class AbstractDaemonTest method verifyNoAccountDetailsInChangeNotes.

/**
 * Verify that NoteDB commits do not persist user-sensitive information, by running checks for all
 * commits in {@link RefNames#changeMetaRef} for all changes, created during the test.
 *
 * <p>These tests prevent regression, assuming appropriate test coverage for new features. The
 * verification is disabled by default and can be enabled using {@link VerifyNoPiiInChangeNotes}
 * annotation either on test class or method.
 */
protected void verifyNoAccountDetailsInChangeNotes() throws RestApiException, IOException {
    List<ChangeInfo> allChanges = gApi.changes().query().get();
    List<AccountState> allAccounts = accounts.all();
    for (ChangeInfo change : allChanges) {
        try (Repository repo = repoManager.openRepository(Project.nameKey(change.project))) {
            String metaRefName = RefNames.changeMetaRef(Change.Id.tryParse(change._number.toString()).get());
            ObjectId metaTip = repo.getRefDatabase().exactRef(metaRefName).getObjectId();
            ChangeNotesRevWalk revWalk = ChangeNotesCommit.newRevWalk(repo);
            revWalk.reset();
            revWalk.markStart(revWalk.parseCommit(metaTip));
            ChangeNotesCommit commit;
            while ((commit = revWalk.next()) != null) {
                String fullMessage = commit.getFullMessage();
                for (AccountState accountState : allAccounts) {
                    Account account = accountState.account();
                    assertThat(fullMessage).doesNotContain(account.getName());
                    if (account.fullName() != null) {
                        assertThat(fullMessage).doesNotContain(account.fullName());
                    }
                    if (account.displayName() != null) {
                        assertThat(fullMessage).doesNotContain(account.displayName());
                    }
                    if (account.preferredEmail() != null) {
                        assertThat(fullMessage).doesNotContain(account.preferredEmail());
                    }
                    if (accountState.userName().isPresent()) {
                        assertThat(fullMessage).doesNotContain(accountState.userName().get());
                    }
                    List<String> allEmails = accountState.externalIds().stream().map(ExternalId::email).filter(Objects::nonNull).collect(toImmutableList());
                    for (String email : allEmails) {
                        assertThat(fullMessage).doesNotContain(email);
                    }
                }
            }
        }
    }
}
Also used : Account(com.google.gerrit.entities.Account) TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ObjectId(org.eclipse.jgit.lib.ObjectId) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) ChangeNotesRevWalk(com.google.gerrit.server.notedb.ChangeNotesCommit.ChangeNotesRevWalk) AccountState(com.google.gerrit.server.account.AccountState) IdString(com.google.gerrit.extensions.restapi.IdString) ChangeNotesCommit(com.google.gerrit.server.notedb.ChangeNotesCommit)

Aggregations

AccountState (com.google.gerrit.server.account.AccountState)63 Account (com.google.gerrit.entities.Account)37 ExternalId (com.google.gerrit.server.account.externalids.ExternalId)18 IOException (java.io.IOException)17 Test (org.junit.Test)16 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)15 Inject (com.google.inject.Inject)15 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)14 AuthException (com.google.gerrit.extensions.restapi.AuthException)12 ArrayList (java.util.ArrayList)12 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)11 HashSet (java.util.HashSet)11 List (java.util.List)11 ImmutableSet (com.google.common.collect.ImmutableSet)10 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)10 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)10 AccountsUpdate (com.google.gerrit.server.account.AccountsUpdate)10 TestAccount (com.google.gerrit.acceptance.TestAccount)9 Nullable (com.google.gerrit.common.Nullable)9 StorageException (com.google.gerrit.exceptions.StorageException)9