Search in sources :

Example 6 with TestKey

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

the class PublicKeyStoreTest method saveAppendsToExistingList.

@Test
public void saveAppendsToExistingList() throws Exception {
    TestKey key1 = validKeyWithoutExpiration();
    TestKey key2 = validKeyWithExpiration();
    tr.branch(REFS_GPG_KEYS).commit().add(keyObjectId(key1.getKeyId()).name(), key2.getPublicKeyArmored()).create();
    store.add(key1.getPublicKeyRing());
    assertEquals(RefUpdate.Result.FAST_FORWARD, store.save(newCommitBuilder()));
    assertKeys(key1.getKeyId(), key1, key2);
    try (ObjectReader reader = tr.getRepository().newObjectReader();
        RevWalk rw = new RevWalk(reader)) {
        NoteMap notes = NoteMap.read(reader, tr.getRevWalk().parseCommit(tr.getRepository().exactRef(REFS_GPG_KEYS).getObjectId()));
        String contents = new String(reader.open(notes.get(keyObjectId(key1.getKeyId()))).getBytes(), UTF_8);
        String header = "-----BEGIN PGP PUBLIC KEY BLOCK-----";
        int i1 = contents.indexOf(header);
        assertTrue(i1 >= 0);
        int i2 = contents.indexOf(header, i1 + header.length());
        assertTrue(i2 >= 0);
    }
}
Also used : TestKey(com.google.gerrit.gpg.testing.TestKey) ObjectReader(org.eclipse.jgit.lib.ObjectReader) NoteMap(org.eclipse.jgit.notes.NoteMap) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) PublicKeyStore.keyIdToString(com.google.gerrit.gpg.PublicKeyStore.keyIdToString) RevWalk(org.eclipse.jgit.revwalk.RevWalk) Test(org.junit.Test)

Example 7 with TestKey

use of com.google.gerrit.gpg.testing.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.testing.TestKey) Test(org.junit.Test)

Example 8 with TestKey

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

the class PublicKeyStoreTest method updateExisting.

@Test
public void updateExisting() throws Exception {
    TestKey key5 = validKeyWithSecondUserId();
    PGPPublicKeyRing keyRing = key5.getPublicKeyRing();
    PGPPublicKey key = keyRing.getPublicKey();
    PGPPublicKey subKey = keyRing.getPublicKey(Iterators.get(keyRing.getPublicKeys(), 1).getKeyID());
    store.add(keyRing);
    assertEquals(RefUpdate.Result.NEW, store.save(newCommitBuilder()));
    assertUserIds(store.get(key5.getKeyId()).iterator().next(), "Testuser Five <test5@example.com>", "foo:myId");
    keyRing = PGPPublicKeyRing.removePublicKey(keyRing, subKey);
    keyRing = PGPPublicKeyRing.removePublicKey(keyRing, key);
    key = PGPPublicKey.removeCertification(key, "foo:myId");
    keyRing = PGPPublicKeyRing.insertPublicKey(keyRing, key);
    keyRing = PGPPublicKeyRing.insertPublicKey(keyRing, subKey);
    store.add(keyRing);
    assertEquals(RefUpdate.Result.FAST_FORWARD, store.save(newCommitBuilder()));
    Iterator<PGPPublicKeyRing> keyRings = store.get(key.getKeyID()).iterator();
    keyRing = keyRings.next();
    assertFalse(keyRings.hasNext());
    assertUserIds(keyRing, "Testuser Five <test5@example.com>");
}
Also used : PGPPublicKeyRing(org.bouncycastle.openpgp.PGPPublicKeyRing) TestKey(com.google.gerrit.gpg.testing.TestKey) PGPPublicKey(org.bouncycastle.openpgp.PGPPublicKey) Test(org.junit.Test)

Example 9 with TestKey

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

the class PublicKeyStoreTest method save.

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

Example 10 with TestKey

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