Search in sources :

Example 26 with TestKey

use of com.google.gerrit.gpg.testing.TestKey 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 27 with TestKey

use of com.google.gerrit.gpg.testing.TestKey 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 28 with TestKey

use of com.google.gerrit.gpg.testing.TestKey in project gerrit by GerritCodeReview.

the class AccountsRestApiBindingsIT method gpgKeyEndpoints.

@Test
@GerritConfig(name = "receive.enableSignedPush", value = "true")
public void gpgKeyEndpoints() throws Exception {
    TestKey key = validKeyWithoutExpiration();
    String id = key.getKeyIdString();
    // email that is hard-coded in the test GPG key
    String email = "test1@example.com";
    accountsUpdateProvider.get().update("Add Email", admin.id(), u -> u.addExternalId(externalIdFactory.createWithEmail(name("test"), email, admin.id(), email)));
    requestScopeOperations.setApiUser(admin.id());
    gApi.accounts().self().putGpgKeys(ImmutableList.of(key.getPublicKeyArmored()), ImmutableList.of());
    execute(adminRestSession, GPG_KEY_ENDPOINTS, "self", id);
}
Also used : TestKey(com.google.gerrit.gpg.testing.TestKey) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 29 with TestKey

use of com.google.gerrit.gpg.testing.TestKey in project gerrit by GerritCodeReview.

the class GerritPublicKeyCheckerTest method noExternalIds.

@Test
public void noExternalIds() throws Exception {
    accountsUpdateProvider.get().update("Delete External IDs", user.getAccountId(), (a, u) -> u.deleteExternalIds(a.externalIds()));
    reloadUser();
    TestKey key = validKeyWithSecondUserId();
    GerritPublicKeyChecker checker = (GerritPublicKeyChecker) checkerFactory.create(user, store).disableTrust();
    assertProblems(checker.check(key.getPublicKey()), Status.BAD, "No identities found for user; check http://test/settings#Identities");
    checker = (GerritPublicKeyChecker) checkerFactory.create().setStore(store).disableTrust();
    assertProblems(checker.check(key.getPublicKey()), Status.BAD, "Key is not associated with any users");
    insertExtId(externalIdFactory.create(checker.toExtIdKey(key.getPublicKey()), user.getAccountId()));
    assertProblems(checker.check(key.getPublicKey()), Status.BAD, "No identities found for user");
}
Also used : TestKey(com.google.gerrit.gpg.testing.TestKey) Test(org.junit.Test)

Example 30 with TestKey

use of com.google.gerrit.gpg.testing.TestKey in project gerrit by GerritCodeReview.

the class GerritPublicKeyCheckerTest method checkTrustChainWithExpiredKey.

@Test
public void checkTrustChainWithExpiredKey() throws Exception {
    // A---Bx
    // 
    // The server ultimately trusts B.
    TestKey keyA = add(keyA(), user);
    TestKey keyB = add(keyB(), addUser("userB"));
    PublicKeyChecker checker = checkerFactory.create(user, store);
    assertProblems(checker.check(keyA.getPublicKey()), Status.OK, "No path to a trusted key", "Certification by " + keyToString(keyB.getPublicKey()) + " is valid, but key is not trusted", "Key D24FE467 used for certification is not in store");
}
Also used : TestKey(com.google.gerrit.gpg.testing.TestKey) Test(org.junit.Test)

Aggregations

TestKey (com.google.gerrit.gpg.testing.TestKey)44 Test (org.junit.Test)41 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)9 PublicKeyStore.keyToString (com.google.gerrit.gpg.PublicKeyStore.keyToString)9 PGPPublicKeyRing (org.bouncycastle.openpgp.PGPPublicKeyRing)7 PGPPublicKey (org.bouncycastle.openpgp.PGPPublicKey)6 AccountIndexedCounter (com.google.gerrit.acceptance.AccountIndexedCounter)5 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)5 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)3 PushCertificate (org.eclipse.jgit.transport.PushCertificate)3 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)2 GpgKeyInfo (com.google.gerrit.extensions.common.GpgKeyInfo)2 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)2 PublicKeyStore.keyIdToString (com.google.gerrit.gpg.PublicKeyStore.keyIdToString)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 ObjectReader (org.eclipse.jgit.lib.ObjectReader)2 RevWalk (org.eclipse.jgit.revwalk.RevWalk)2 StopStrategies (com.github.rholder.retry.StopStrategies)1 FluentIterable (com.google.common.collect.FluentIterable)1