Search in sources :

Example 11 with AccountIndexedCounter

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

the class AccountIT method shouldAllowQueryByUserNameForInactiveUser.

@Test
public void shouldAllowQueryByUserNameForInactiveUser() throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        Account.Id activatableAccountId = accountOperations.newAccount().inactive().username("foo").create();
        accountIndexedCounter.assertReindexOf(activatableAccountId, 1);
    }
    gApi.changes().query("owner:foo").get();
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) TestAccount(com.google.gerrit.acceptance.TestAccount) Account(com.google.gerrit.entities.Account) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 12 with AccountIndexedCounter

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

the class AccountIT method deletePreferredEmail.

@Test
public void deletePreferredEmail() throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        String previous = gApi.accounts().self().get().email;
        String email = "foo.bar.baz@example.com";
        EmailInput input = new EmailInput();
        input.email = email;
        input.noConfirmation = true;
        input.preferred = true;
        gApi.accounts().self().addEmail(input);
        // Account is reindexed twice; once on adding the new email,
        // and then again on setting the email preferred.
        accountIndexedCounter.assertReindexOf(admin, 2);
        // The new preferred email is set
        assertThat(gApi.accounts().self().get().email).isEqualTo(email);
        accountIndexedCounter.clear();
        gApi.accounts().self().deleteEmail(input.email);
        accountIndexedCounter.assertReindexOf(admin);
        requestScopeOperations.resetCurrentApiUser();
        assertThat(getEmails()).containsExactly(previous);
        assertThat(gApi.accounts().self().get().email).isNull();
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) EmailInput(com.google.gerrit.extensions.api.accounts.EmailInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 13 with AccountIndexedCounter

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

the class AccountIT method sshKeys.

@Test
@UseSsh
public void sshKeys() throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        // The test account should initially have exactly one ssh key
        List<SshKeyInfo> info = gApi.accounts().self().listSshKeys();
        assertThat(info).hasSize(1);
        assertSequenceNumbers(info);
        SshKeyInfo key = info.get(0);
        KeyPair keyPair = sshKeys.getKeyPair(admin);
        String initial = TestSshKeys.publicKey(keyPair, admin.email());
        assertThat(key.sshPublicKey).isEqualTo(initial);
        accountIndexedCounter.assertNoReindex();
        // Add a new key
        sender.clear();
        String newKey = TestSshKeys.publicKey(SshSessionFactory.genSshKey(), admin.email());
        gApi.accounts().self().addSshKey(newKey);
        info = gApi.accounts().self().listSshKeys();
        assertThat(info).hasSize(2);
        assertSequenceNumbers(info);
        accountIndexedCounter.assertReindexOf(admin);
        assertThat(sender.getMessages()).hasSize(1);
        assertThat(sender.getMessages().get(0).body()).contains("new SSH keys have been added");
        // Add an existing key (the request succeeds, but the key isn't added again)
        sender.clear();
        gApi.accounts().self().addSshKey(initial);
        info = gApi.accounts().self().listSshKeys();
        assertThat(info).hasSize(2);
        assertSequenceNumbers(info);
        accountIndexedCounter.assertNoReindex();
        // TODO: Issue 10769: Adding an already existing key should not result in a notification email
        assertThat(sender.getMessages()).hasSize(1);
        assertThat(sender.getMessages().get(0).body()).contains("new SSH keys have been added");
        // Add another new key
        sender.clear();
        String newKey2 = TestSshKeys.publicKey(SshSessionFactory.genSshKey(), admin.email());
        gApi.accounts().self().addSshKey(newKey2);
        info = gApi.accounts().self().listSshKeys();
        assertThat(info).hasSize(3);
        assertSequenceNumbers(info);
        accountIndexedCounter.assertReindexOf(admin);
        assertThat(sender.getMessages()).hasSize(1);
        assertThat(sender.getMessages().get(0).body()).contains("new SSH keys have been added");
        // Delete second key
        sender.clear();
        gApi.accounts().self().deleteSshKey(2);
        info = gApi.accounts().self().listSshKeys();
        assertThat(info).hasSize(2);
        assertThat(info.get(0).seq).isEqualTo(1);
        assertThat(info.get(1).seq).isEqualTo(3);
        accountIndexedCounter.assertReindexOf(admin);
        assertThat(sender.getMessages()).hasSize(1);
        assertThat(sender.getMessages().get(0).body()).contains("SSH keys have been deleted");
        // Mark first key as invalid
        assertThat(info.get(0).valid).isTrue();
        authorizedKeys.markKeyInvalid(admin.id(), 1);
        info = gApi.accounts().self().listSshKeys();
        assertThat(info).hasSize(2);
        assertThat(info.get(0).seq).isEqualTo(1);
        assertThat(info.get(0).valid).isFalse();
        assertThat(info.get(1).seq).isEqualTo(3);
        accountIndexedCounter.assertReindexOf(admin);
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) KeyPair(java.security.KeyPair) SshKeyInfo(com.google.gerrit.extensions.common.SshKeyInfo) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test) UseSsh(com.google.gerrit.acceptance.UseSsh)

Example 14 with AccountIndexedCounter

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

the class AccountIT method reindexPermissions.

// reindex is tested by {@link AbstractQueryAccountsTest#reindex}
@Test
public void reindexPermissions() throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        // admin can reindex any account
        requestScopeOperations.setApiUser(admin.id());
        gApi.accounts().id(user.username()).index();
        accountIndexedCounter.assertReindexOf(user);
        // user can reindex own account
        requestScopeOperations.setApiUser(user.id());
        gApi.accounts().self().index();
        accountIndexedCounter.assertReindexOf(user);
        // user cannot reindex any account
        AuthException thrown = assertThrows(AuthException.class, () -> gApi.accounts().id(admin.username()).index());
        assertThat(thrown).hasMessageThat().contains("modify account not permitted");
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) AuthException(com.google.gerrit.extensions.restapi.AuthException) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 15 with AccountIndexedCounter

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

the class AccountIT method addExternalIdEmail.

private void addExternalIdEmail(TestAccount account, String email) throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        requireNonNull(email);
        accountsUpdateProvider.get().update("Add Email", account.id(), u -> u.addExternalId(externalIdFactory.createWithEmail(name("test"), email, account.id(), email)));
        accountIndexedCounter.assertReindexOf(account);
        requestScopeOperations.setApiUser(account.id());
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration)

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