Search in sources :

Example 31 with AccountIndexedCounter

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

the class AccountIT method listGpgKeys.

@Test
public void listGpgKeys() throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        List<TestKey> keys = allValidKeys();
        List<String> toAdd = new ArrayList<>(keys.size());
        for (TestKey key : keys) {
            addExternalIdEmail(admin, PushCertificateIdent.parse(key.getFirstUserId()).getEmailAddress());
            toAdd.add(key.getPublicKeyArmored());
        }
        accountIndexedCounter.clear();
        gApi.accounts().self().putGpgKeys(toAdd, ImmutableList.of());
        assertKeys(keys);
        accountIndexedCounter.assertReindexOf(admin);
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) TestKey(com.google.gerrit.gpg.testing.TestKey) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) ArrayList(java.util.ArrayList) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 32 with AccountIndexedCounter

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

the class AccountIT method addAndRemoveGpgKeys.

@Test
public void addAndRemoveGpgKeys() throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        for (TestKey key : allValidKeys()) {
            addExternalIdEmail(admin, PushCertificateIdent.parse(key.getFirstUserId()).getEmailAddress());
        }
        accountIndexedCounter.clear();
        TestKey key1 = validKeyWithoutExpiration();
        TestKey key2 = validKeyWithExpiration();
        TestKey key5 = validKeyWithSecondUserId();
        Map<String, GpgKeyInfo> infos = gApi.accounts().self().putGpgKeys(ImmutableList.of(key1.getPublicKeyArmored(), key2.getPublicKeyArmored()), ImmutableList.of(key5.getKeyIdString()));
        assertThat(infos.keySet()).containsExactly(key1.getKeyIdString(), key2.getKeyIdString());
        assertKeys(key1, key2);
        accountIndexedCounter.assertReindexOf(admin);
        infos = gApi.accounts().self().putGpgKeys(ImmutableList.of(key5.getPublicKeyArmored()), ImmutableList.of(key1.getKeyIdString()));
        assertThat(infos.keySet()).containsExactly(key1.getKeyIdString(), key5.getKeyIdString());
        assertKeyMapContains(key5, infos);
        assertThat(infos.get(key1.getKeyIdString()).key).isNull();
        assertKeys(key2, key5);
        accountIndexedCounter.assertReindexOf(admin);
        BadRequestException thrown = assertThrows(BadRequestException.class, () -> gApi.accounts().self().putGpgKeys(ImmutableList.of(key2.getPublicKeyArmored()), ImmutableList.of(key2.getKeyIdString())));
        assertThat(thrown).hasMessageThat().contains("Cannot both add and delete key: " + keyToString(key2.getPublicKey()));
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) TestKey(com.google.gerrit.gpg.testing.TestKey) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) GpgKeyInfo(com.google.gerrit.extensions.common.GpgKeyInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 33 with AccountIndexedCounter

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

the class AccountIT method get.

@Test
public void get() throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        AccountInfo info = gApi.accounts().id("admin").get();
        assertThat(info.name).isEqualTo("Administrator");
        assertThat(info.email).isEqualTo("admin@example.com");
        assertThat(info.username).isEqualTo("admin");
        accountIndexedCounter.assertNoReindex();
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 34 with AccountIndexedCounter

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

the class AccountIT method addGpgKey.

private Map<String, GpgKeyInfo> addGpgKey(TestAccount account, String armored) throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        Map<String, GpgKeyInfo> gpgKeys = gApi.accounts().id(account.username()).putGpgKeys(ImmutableList.of(armored), ImmutableList.<String>of());
        accountIndexedCounter.assertReindexOf(gApi.accounts().id(account.username()).get());
        return gpgKeys;
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) GpgKeyInfo(com.google.gerrit.extensions.common.GpgKeyInfo)

Example 35 with AccountIndexedCounter

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

the class AccountIT method createByAccountCreator.

private Account.Id createByAccountCreator(int expectedAccountReindexCalls) throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        String name = "foo";
        TestAccount foo = accountCreator.create(name);
        AccountInfo info = gApi.accounts().id(foo.id().get()).get();
        assertThat(info.username).isEqualTo(name);
        assertThat(info.name).isEqualTo(name);
        accountIndexedCounter.assertReindexOf(foo, expectedAccountReindexCalls);
        assertUserBranch(foo.id(), name, null);
        return foo.id();
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) TestAccount(com.google.gerrit.acceptance.TestAccount) AccountInfo(com.google.gerrit.extensions.common.AccountInfo)

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