Search in sources :

Example 11 with TestKey

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

the class PublicKeyStoreTest method removeNonexisting.

@Test
public void removeNonexisting() throws Exception {
    TestKey key1 = validKeyWithoutExpiration();
    store.add(key1.getPublicKeyRing());
    assertEquals(RefUpdate.Result.NEW, store.save(newCommitBuilder()));
    TestKey key2 = validKeyWithExpiration();
    store.remove(key2.getPublicKey().getFingerprint());
    assertEquals(RefUpdate.Result.NO_CHANGE, store.save(newCommitBuilder()));
    assertKeys(key1.getKeyId(), key1);
}
Also used : TestKey(com.google.gerrit.gpg.testutil.TestKey) Test(org.junit.Test)

Example 12 with TestKey

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

the class PushCertificateCheckerTest method invalidKey.

@Test
public void invalidKey() throws Exception {
    TestKey key3 = expiredKey();
    PushCertificate cert = newSignedCert(validNonce(), key3);
    assertProblems(cert, "Invalid public key " + keyToString(key3.getPublicKey()) + ":\n  Key is expired");
}
Also used : TestKey(com.google.gerrit.gpg.testutil.TestKey) PushCertificate(org.eclipse.jgit.transport.PushCertificate) Test(org.junit.Test)

Example 13 with TestKey

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

the class PublicKeyCheckerTest method trustCycle.

@Test
public void trustCycle() throws Exception {
    // F---G---F, in a cycle.
    TestKey kf = add(keyF());
    TestKey kg = add(keyG());
    save();
    PublicKeyChecker checker = newChecker(10, keyA());
    assertProblems(checker, kf, "No path to a trusted key", notTrusted(kg));
    assertProblems(checker, kg, "No path to a trusted key", notTrusted(kf));
}
Also used : TestKey(com.google.gerrit.gpg.testutil.TestKey) Test(org.junit.Test)

Example 14 with TestKey

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

the class PublicKeyCheckerTest method revokedKeyDueToCompromiseRevokesKeyRetroactively.

@Test
public void revokedKeyDueToCompromiseRevokesKeyRetroactively() throws Exception {
    TestKey k = add(revokedCompromisedKey());
    add(validKeyWithoutExpiration());
    save();
    String problem = "Key is revoked (key material has been compromised): test6 compromised";
    assertProblems(k, problem);
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    PublicKeyChecker checker = new PublicKeyChecker().setStore(store).setEffectiveTime(df.parse("2010-01-01 12:00:00"));
    assertProblems(checker, k, problem);
}
Also used : TestKey(com.google.gerrit.gpg.testutil.TestKey) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 15 with TestKey

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

the class PublicKeyCheckerTest method trustInsufficientDepthInSignature.

@Test
public void trustInsufficientDepthInSignature() throws Exception {
    // H---I---J, but J is only trusted to length 1.
    TestKey kh = add(keyH());
    TestKey ki = add(keyI());
    add(keyJ());
    save();
    PublicKeyChecker checker = newChecker(10, keyJ());
    // J trusts I to a depth of 1, so I itself is valid, but I's certification
    // of K is not valid.
    assertNoProblems(checker, ki);
    assertProblems(checker, kh, "No path to a trusted key", notTrusted(ki));
}
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