Search in sources :

Example 46 with AccountIndexedCounter

use of com.google.gerrit.acceptance.AccountIndexedCounter in project gerrit by GerritCodeReview.

the class PushAccountIT method pushAccountConfigToUserBranchDeactivateOtherAccount.

@Test
public void pushAccountConfigToUserBranchDeactivateOtherAccount() throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        projectOperations.allProjectsForUpdate().add(allowCapability(GlobalCapability.ACCESS_DATABASE).group(REGISTERED_USERS)).update();
        TestAccount foo = accountCreator.create(name("foo"));
        assertThat(gApi.accounts().id(foo.id().get()).getActive()).isTrue();
        String userRef = RefNames.refsUsers(foo.id());
        accountIndexedCounter.clear();
        projectOperations.project(allUsers).forUpdate().add(allow(Permission.PUSH).ref(userRef).group(adminGroupUuid())).update();
        TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers);
        fetch(allUsersRepo, userRef + ":userRef");
        allUsersRepo.reset("userRef");
        Config ac = getAccountConfig(allUsersRepo);
        ac.setBoolean(AccountProperties.ACCOUNT, null, AccountProperties.KEY_ACTIVE, false);
        pushFactory.create(admin.newIdent(), allUsersRepo, "Update account config", AccountProperties.ACCOUNT_CONFIG, ac.toText()).to(userRef).assertOkStatus();
        accountIndexedCounter.assertReindexOf(foo);
        assertThat(gApi.accounts().id(foo.id().get()).getActive()).isFalse();
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) Config(org.eclipse.jgit.lib.Config) TestAccount(com.google.gerrit.acceptance.TestAccount) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 47 with AccountIndexedCounter

use of com.google.gerrit.acceptance.AccountIndexedCounter in project gerrit by GerritCodeReview.

the class PushAccountIT method pushAccountConfigToUserBranchIfPreferredEmailDoesNotExistAsExtId.

@Test
public void pushAccountConfigToUserBranchIfPreferredEmailDoesNotExistAsExtId() throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        TestAccount foo = accountCreator.create(name("foo"), name("foo") + "@example.com", "Foo", null);
        String userRef = RefNames.refsUsers(foo.id());
        accountIndexedCounter.clear();
        projectOperations.project(allUsers).forUpdate().add(allow(Permission.PUSH).ref(userRef).group(adminGroupUuid())).update();
        TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers, foo);
        fetch(allUsersRepo, userRef + ":userRef");
        allUsersRepo.reset("userRef");
        String email = "some.email@example.com";
        Config ac = getAccountConfig(allUsersRepo);
        ac.setString(AccountProperties.ACCOUNT, null, AccountProperties.KEY_PREFERRED_EMAIL, email);
        pushFactory.create(foo.newIdent(), allUsersRepo, "Update account config", AccountProperties.ACCOUNT_CONFIG, ac.toText()).to(userRef).assertOkStatus();
        accountIndexedCounter.assertReindexOf(foo);
        AccountInfo info = gApi.accounts().id(foo.id().get()).get();
        assertThat(info.email).isEqualTo(email);
        assertThat(info.name).isEqualTo(foo.fullName());
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) Config(org.eclipse.jgit.lib.Config) TestAccount(com.google.gerrit.acceptance.TestAccount) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

AccountIndexedCounter (com.google.gerrit.acceptance.AccountIndexedCounter)47 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)47 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)44 Test (org.junit.Test)44 PublicKeyStore.keyToString (com.google.gerrit.gpg.PublicKeyStore.keyToString)18 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)18 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)16 TestAccount (com.google.gerrit.acceptance.TestAccount)13 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)13 Config (org.eclipse.jgit.lib.Config)13 EmailInput (com.google.gerrit.extensions.api.accounts.EmailInput)7 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)5 TestKey (com.google.gerrit.gpg.testing.TestKey)5 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)4 Message (com.google.gerrit.testing.FakeEmailSender.Message)4 UseSsh (com.google.gerrit.acceptance.UseSsh)3 Account (com.google.gerrit.entities.Account)3 GpgKeyInfo (com.google.gerrit.extensions.common.GpgKeyInfo)3 SshKeyInfo (com.google.gerrit.extensions.common.SshKeyInfo)3 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)3