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);
}
}
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);
}
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>");
}
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);
}
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));
}
Aggregations