Search in sources :

Example 26 with TestKey

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

the class AccountIT method listGpgKeys.

@Test
public void listGpgKeys() throws Exception {
    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());
    }
    gApi.accounts().self().putGpgKeys(toAdd, ImmutableList.<String>of());
    assertKeys(keys);
    accountIndexedCounter.assertReindexOf(admin);
}
Also used : TestKey(com.google.gerrit.gpg.testutil.TestKey) 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.testutil.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.testutil.TestKey) Test(org.junit.Test)

Example 28 with TestKey

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

the class GerritPublicKeyCheckerTest method noExternalIds.

@Test
public void noExternalIds() throws Exception {
    ExternalIdsUpdate externalIdsUpdate = externalIdsUpdateFactory.create();
    externalIdsUpdate.deleteAll(user.getAccountId());
    reloadUser();
    TestKey key = validKeyWithSecondUserId();
    PublicKeyChecker checker = checkerFactory.create(user, store).disableTrust();
    assertProblems(checker.check(key.getPublicKey()), Status.BAD, "No identities found for user; check http://test/#/settings/web-identities");
    checker = checkerFactory.create().setStore(store).disableTrust();
    assertProblems(checker.check(key.getPublicKey()), Status.BAD, "Key is not associated with any users");
    externalIdsUpdate.insert(ExternalId.create(toExtIdKey(key.getPublicKey()), user.getAccountId()));
    reloadUser();
    assertProblems(checker.check(key.getPublicKey()), Status.BAD, "No identities found for user");
}
Also used : TestKey(com.google.gerrit.gpg.testutil.TestKey) ExternalIdsUpdate(com.google.gerrit.server.account.externalids.ExternalIdsUpdate) Test(org.junit.Test)

Example 29 with TestKey

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

the class GerritPublicKeyCheckerTest method checkWithValidKeyButWrongExpectedUserInChecker.

@Test
public void checkWithValidKeyButWrongExpectedUserInChecker() throws Exception {
    // A---Bx
    //  \
    //   \---C---D
    //        \
    //         \---Ex
    //
    // The server ultimately trusts B and D.
    // D and E trust C to be a valid introducer of depth 2.
    IdentifiedUser userB = addUser("userB");
    TestKey keyA = add(keyA(), user);
    TestKey keyB = add(keyB(), userB);
    add(keyC(), addUser("userC"));
    add(keyD(), addUser("userD"));
    add(keyE(), addUser("userE"));
    // Checker for A, checking B.
    PublicKeyChecker checkerA = checkerFactory.create(user, store);
    assertProblems(checkerA.check(keyB.getPublicKey()), Status.BAD, "Key is expired", "Key must contain a valid certification for one of the following" + " identities:\n" + "  gerrit:user\n" + "  mailto:testa@example.com\n" + "  testa@example.com\n" + "  username:user");
    // Checker for B, checking A.
    PublicKeyChecker checkerB = checkerFactory.create(userB, store);
    assertProblems(checkerB.check(keyA.getPublicKey()), Status.BAD, "Key must contain a valid certification for one of the following" + " identities:\n" + "  gerrit:userB\n" + "  mailto:testb@example.com\n" + "  testb@example.com\n" + "  username:userB");
}
Also used : TestKey(com.google.gerrit.gpg.testutil.TestKey) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) Test(org.junit.Test)

Example 30 with TestKey

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

the class GerritPublicKeyCheckerTest method checkTrustChainUsingCheckerWithoutExpectedKey.

@Test
public void checkTrustChainUsingCheckerWithoutExpectedKey() throws Exception {
    // A---Bx
    //  \
    //   \---C---D
    //        \
    //         \---Ex
    //
    // The server ultimately trusts B and D.
    // D and E trust C to be a valid introducer of depth 2.
    TestKey keyA = add(keyA(), user);
    TestKey keyB = add(keyB(), addUser("userB"));
    TestKey keyC = add(keyC(), addUser("userC"));
    TestKey keyD = add(keyD(), addUser("userD"));
    TestKey keyE = add(keyE(), addUser("userE"));
    // This checker can check any key, so the only problems come from issues
    // with the keys themselves, not having invalid user IDs.
    PublicKeyChecker checker = checkerFactory.create().setStore(store);
    assertNoProblems(checker.check(keyA.getPublicKey()));
    assertProblems(checker.check(keyB.getPublicKey()), Status.BAD, "Key is expired");
    assertNoProblems(checker.check(keyC.getPublicKey()));
    assertNoProblems(checker.check(keyD.getPublicKey()));
    assertProblems(checker.check(keyE.getPublicKey()), Status.BAD, "Key is expired", "No path to a trusted key");
}
Also used : TestKey(com.google.gerrit.gpg.testutil.TestKey) Test(org.junit.Test)

Aggregations

TestKey (com.google.gerrit.gpg.testutil.TestKey)40 Test (org.junit.Test)37 PublicKeyStore.keyToString (com.google.gerrit.gpg.PublicKeyStore.keyToString)10 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)7 PGPPublicKeyRing (org.bouncycastle.openpgp.PGPPublicKeyRing)5 PGPPublicKey (org.bouncycastle.openpgp.PGPPublicKey)4 GpgKeyInfo (com.google.gerrit.extensions.common.GpgKeyInfo)3 PushCertificate (org.eclipse.jgit.transport.PushCertificate)3 PublicKeyStore.keyIdToString (com.google.gerrit.gpg.PublicKeyStore.keyIdToString)2 SimpleDateFormat (java.text.SimpleDateFormat)2 RevWalk (org.eclipse.jgit.revwalk.RevWalk)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 FluentIterable (com.google.common.collect.FluentIterable)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables (com.google.common.collect.Iterables)1 BaseEncoding (com.google.common.io.BaseEncoding)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 Truth.assert_ (com.google.common.truth.Truth.assert_)1 AtomicLongMap (com.google.common.util.concurrent.AtomicLongMap)1