use of com.google.gerrit.gpg.testing.TestKey in project gerrit by GerritCodeReview.
the class AccountIT method listGpgKeys.
@Test
public void listGpgKeys() throws Exception {
AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
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());
}
accountIndexedCounter.clear();
gApi.accounts().self().putGpgKeys(toAdd, ImmutableList.of());
assertKeys(keys);
accountIndexedCounter.assertReindexOf(admin);
}
}
use of com.google.gerrit.gpg.testing.TestKey in project gerrit by GerritCodeReview.
the class AccountIT method addAndRemoveGpgKeys.
@Test
public void addAndRemoveGpgKeys() throws Exception {
AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
for (TestKey key : allValidKeys()) {
addExternalIdEmail(admin, PushCertificateIdent.parse(key.getFirstUserId()).getEmailAddress());
}
accountIndexedCounter.clear();
TestKey key1 = validKeyWithoutExpiration();
TestKey key2 = validKeyWithExpiration();
TestKey key5 = validKeyWithSecondUserId();
Map<String, GpgKeyInfo> infos = gApi.accounts().self().putGpgKeys(ImmutableList.of(key1.getPublicKeyArmored(), key2.getPublicKeyArmored()), ImmutableList.of(key5.getKeyIdString()));
assertThat(infos.keySet()).containsExactly(key1.getKeyIdString(), key2.getKeyIdString());
assertKeys(key1, key2);
accountIndexedCounter.assertReindexOf(admin);
infos = gApi.accounts().self().putGpgKeys(ImmutableList.of(key5.getPublicKeyArmored()), ImmutableList.of(key1.getKeyIdString()));
assertThat(infos.keySet()).containsExactly(key1.getKeyIdString(), key5.getKeyIdString());
assertKeyMapContains(key5, infos);
assertThat(infos.get(key1.getKeyIdString()).key).isNull();
assertKeys(key2, key5);
accountIndexedCounter.assertReindexOf(admin);
BadRequestException thrown = assertThrows(BadRequestException.class, () -> gApi.accounts().self().putGpgKeys(ImmutableList.of(key2.getPublicKeyArmored()), ImmutableList.of(key2.getKeyIdString())));
assertThat(thrown).hasMessageThat().contains("Cannot both add and delete key: " + keyToString(key2.getPublicKey()));
}
}
use of com.google.gerrit.gpg.testing.TestKey in project gerrit by GerritCodeReview.
the class AccountsRestApiBindingsIT method gpgKeyEndpoints.
@Test
@GerritConfig(name = "receive.enableSignedPush", value = "true")
public void gpgKeyEndpoints() throws Exception {
TestKey key = validKeyWithoutExpiration();
String id = key.getKeyIdString();
// email that is hard-coded in the test GPG key
String email = "test1@example.com";
accountsUpdateProvider.get().update("Add Email", admin.id(), u -> u.addExternalId(externalIdFactory.createWithEmail(name("test"), email, admin.id(), email)));
requestScopeOperations.setApiUser(admin.id());
gApi.accounts().self().putGpgKeys(ImmutableList.of(key.getPublicKeyArmored()), ImmutableList.of());
execute(adminRestSession, GPG_KEY_ENDPOINTS, "self", id);
}
use of com.google.gerrit.gpg.testing.TestKey in project gerrit by GerritCodeReview.
the class GerritPublicKeyCheckerTest method noExternalIds.
@Test
public void noExternalIds() throws Exception {
accountsUpdateProvider.get().update("Delete External IDs", user.getAccountId(), (a, u) -> u.deleteExternalIds(a.externalIds()));
reloadUser();
TestKey key = validKeyWithSecondUserId();
GerritPublicKeyChecker checker = (GerritPublicKeyChecker) checkerFactory.create(user, store).disableTrust();
assertProblems(checker.check(key.getPublicKey()), Status.BAD, "No identities found for user; check http://test/settings#Identities");
checker = (GerritPublicKeyChecker) checkerFactory.create().setStore(store).disableTrust();
assertProblems(checker.check(key.getPublicKey()), Status.BAD, "Key is not associated with any users");
insertExtId(externalIdFactory.create(checker.toExtIdKey(key.getPublicKey()), user.getAccountId()));
assertProblems(checker.check(key.getPublicKey()), Status.BAD, "No identities found for user");
}
use of com.google.gerrit.gpg.testing.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");
}
Aggregations