use of com.google.gerrit.gpg.testing.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");
}
use of com.google.gerrit.gpg.testing.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");
}
use of com.google.gerrit.gpg.testing.TestKey in project gerrit by GerritCodeReview.
the class PublicKeyStoreTest method getSubkeyReturnsMasterKey.
@Test
public void getSubkeyReturnsMasterKey() throws Exception {
TestKey key1 = validKeyWithoutExpirationWithSubkeyWithExpiration();
PGPPublicKeyRing keyRing = key1.getPublicKeyRing();
store.add(keyRing);
assertEquals(RefUpdate.Result.NEW, store.save(newCommitBuilder()));
long masterKeyId = key1.getKeyId();
long subKeyId = 0;
for (PGPPublicKey key : keyRing) {
if (masterKeyId != subKeyId) {
subKeyId = key.getKeyID();
}
}
assertKeys(subKeyId, key1);
}
use of com.google.gerrit.gpg.testing.TestKey in project gerrit by GerritCodeReview.
the class PublicKeyStoreTest method get.
@Test
public void get() throws Exception {
TestKey key1 = validKeyWithoutExpiration();
tr.branch(REFS_GPG_KEYS).commit().add(keyObjectId(key1.getKeyId()).name(), key1.getPublicKeyArmored()).create();
TestKey key2 = validKeyWithExpiration();
tr.branch(REFS_GPG_KEYS).commit().add(keyObjectId(key2.getKeyId()).name(), key2.getPublicKeyArmored()).create();
assertKeys(key1.getKeyId(), key1);
assertKeys(key2.getKeyId(), key2);
}
use of com.google.gerrit.gpg.testing.TestKey in project gerrit by GerritCodeReview.
the class PublicKeyStoreTest method addThenRemove.
@Test
public void addThenRemove() throws Exception {
TestKey key1 = validKeyWithoutExpiration();
store.add(key1.getPublicKeyRing());
store.remove(key1.getPublicKey().getFingerprint());
assertEquals(RefUpdate.Result.NO_CHANGE, store.save(newCommitBuilder()));
assertKeys(key1.getKeyId());
}
Aggregations