Search in sources :

Example 16 with TestKey

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

the class PublicKeyCheckerTest method trustValidPathLength1.

@Test
public void trustValidPathLength1() throws Exception {
    // A---Bx
    //  \
    //   \---C---D
    //        \
    //         \---Ex
    //
    // D and E trust C to be a valid introducer of depth 2.
    TestKey ka = add(keyA());
    TestKey kb = add(keyB());
    TestKey kc = add(keyC());
    TestKey kd = add(keyD());
    add(keyE());
    save();
    PublicKeyChecker checker = newChecker(1, kd);
    assertProblems(checker, ka, "No path to a trusted key", notTrusted(kb), notTrusted(kc));
}
Also used : TestKey(com.google.gerrit.gpg.testutil.TestKey) Test(org.junit.Test)

Example 17 with TestKey

use of com.google.gerrit.gpg.testutil.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();
    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, key);
    key = PGPPublicKey.removeCertification(key, "foo:myId");
    keyRing = PGPPublicKeyRing.insertPublicKey(keyRing, key);
    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.testutil.TestKey) PGPPublicKey(org.bouncycastle.openpgp.PGPPublicKey) Test(org.junit.Test)

Example 18 with TestKey

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

the class PublicKeyStoreTest method assertKeys.

private void assertKeys(long keyId, TestKey... expected) throws Exception {
    Set<String> expectedStrings = new TreeSet<>();
    for (TestKey k : expected) {
        expectedStrings.add(keyToString(k.getPublicKey()));
    }
    PGPPublicKeyRingCollection actual = store.get(keyId);
    Set<String> actualStrings = new TreeSet<>();
    for (PGPPublicKeyRing k : actual) {
        actualStrings.add(keyToString(k.getPublicKey()));
    }
    assertEquals(expectedStrings, actualStrings);
}
Also used : PGPPublicKeyRing(org.bouncycastle.openpgp.PGPPublicKeyRing) TestKey(com.google.gerrit.gpg.testutil.TestKey) PGPPublicKeyRingCollection(org.bouncycastle.openpgp.PGPPublicKeyRingCollection) TreeSet(java.util.TreeSet) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) PublicKeyStore.keyIdToString(com.google.gerrit.gpg.PublicKeyStore.keyIdToString)

Example 19 with TestKey

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

the class PublicKeyStoreTest method remove.

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

Example 20 with TestKey

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

the class AccountIT method assertKeys.

private void assertKeys(Iterable<TestKey> expectedKeys) throws Exception {
    // Check via API.
    FluentIterable<TestKey> expected = FluentIterable.from(expectedKeys);
    Map<String, GpgKeyInfo> keyMap = gApi.accounts().self().listGpgKeys();
    assertThat(keyMap.keySet()).named("keys returned by listGpgKeys()").containsExactlyElementsIn(expected.transform(TestKey::getKeyIdString));
    for (TestKey key : expected) {
        assertKeyEquals(key, gApi.accounts().self().gpgKey(key.getKeyIdString()).get());
        assertKeyEquals(key, gApi.accounts().self().gpgKey(Fingerprint.toString(key.getPublicKey().getFingerprint())).get());
        assertKeyMapContains(key, keyMap);
    }
    // Check raw external IDs.
    Account.Id currAccountId = atrScope.get().getUser().getAccountId();
    Iterable<String> expectedFps = expected.transform(k -> BaseEncoding.base16().encode(k.getPublicKey().getFingerprint()));
    Iterable<String> actualFps = externalIds.byAccount(currAccountId, SCHEME_GPGKEY).stream().map(e -> e.key().id()).collect(toSet());
    assertThat(actualFps).named("external IDs in database").containsExactlyElementsIn(expectedFps);
    // Check raw stored keys.
    for (TestKey key : expected) {
        getOnlyKeyFromStore(key);
    }
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) AllUsersName(com.google.gerrit.server.config.AllUsersName) IGNORE_LABEL(com.google.gerrit.server.StarredChangesUtil.IGNORE_LABEL) Arrays(java.util.Arrays) SshMode(com.google.gerrit.testutil.SshMode) GlobalCapability(com.google.gerrit.common.data.GlobalCapability) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) TestAccount(com.google.gerrit.acceptance.TestAccount) REGISTERED_USERS(com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevWalk(org.eclipse.jgit.revwalk.RevWalk) Config(org.eclipse.jgit.lib.Config) FluentIterable(com.google.common.collect.FluentIterable) GpgKeyInfo(com.google.gerrit.extensions.common.GpgKeyInfo) Map(java.util.Map) WatchConfig(com.google.gerrit.server.account.WatchConfig) EnumSet(java.util.EnumSet) TestKeys.allValidKeys(com.google.gerrit.gpg.testutil.TestKeys.allValidKeys) GitUtil.deleteRef(com.google.gerrit.acceptance.GitUtil.deleteRef) Set(java.util.Set) RefUpdate(org.eclipse.jgit.lib.RefUpdate) PGPPublicKey(org.bouncycastle.openpgp.PGPPublicKey) ExternalIds(com.google.gerrit.server.account.externalids.ExternalIds) RefNames(com.google.gerrit.reviewdb.client.RefNames) PushResult(org.eclipse.jgit.transport.PushResult) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) ExternalIdsUpdate(com.google.gerrit.server.account.externalids.ExternalIdsUpdate) GitUtil.fetch(com.google.gerrit.acceptance.GitUtil.fetch) Iterables(com.google.common.collect.Iterables) RevCommit(org.eclipse.jgit.revwalk.RevCommit) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Fingerprint(com.google.gerrit.gpg.Fingerprint) ArrayList(java.util.ArrayList) AccountByEmailCache(com.google.gerrit.server.account.AccountByEmailCache) EmailInput(com.google.gerrit.extensions.api.accounts.EmailInput) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) Before(org.junit.Before) MagicBranch(com.google.gerrit.server.util.MagicBranch) TestRepository(org.eclipse.jgit.junit.TestRepository) BaseEncoding(com.google.common.io.BaseEncoding) Test(org.junit.Test) ANONYMOUS_USERS(com.google.gerrit.server.group.SystemGroupBackend.ANONYMOUS_USERS) TestKeys.validKeyWithoutExpiration(com.google.gerrit.gpg.testutil.TestKeys.validKeyWithoutExpiration) AccountIndexedListener(com.google.gerrit.extensions.events.AccountIndexedListener) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) DynamicSet(com.google.gerrit.extensions.registration.DynamicSet) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) ProjectConfig(com.google.gerrit.server.git.ProjectConfig) Assert(org.junit.Assert) Repository(org.eclipse.jgit.lib.Repository) TestKey(com.google.gerrit.gpg.testutil.TestKey) Inject(com.google.inject.Inject) REFS_GPG_KEYS(com.google.gerrit.gpg.PublicKeyStore.REFS_GPG_KEYS) ChangeRebuilderImpl(com.google.gerrit.server.notedb.rebuild.ChangeRebuilderImpl) AccountCreator(com.google.gerrit.acceptance.AccountCreator) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) DEFAULT_LABEL(com.google.gerrit.server.StarredChangesUtil.DEFAULT_LABEL) TestKeys.validKeyWithExpiration(com.google.gerrit.gpg.testutil.TestKeys.validKeyWithExpiration) Locale(java.util.Locale) After(org.junit.After) AuthException(com.google.gerrit.extensions.restapi.AuthException) Assert.fail(org.junit.Assert.fail) PGPPublicKeyRing(org.bouncycastle.openpgp.PGPPublicKeyRing) AtomicLongMap(com.google.common.util.concurrent.AtomicLongMap) Collectors.toSet(java.util.stream.Collectors.toSet) ImmutableSet(com.google.common.collect.ImmutableSet) Collection(java.util.Collection) Permission(com.google.gerrit.common.data.Permission) SCHEME_GPGKEY(com.google.gerrit.server.account.externalids.ExternalId.SCHEME_GPGKEY) NotifyType(com.google.gerrit.server.account.WatchConfig.NotifyType) TestKeys.validKeyWithSecondUserId(com.google.gerrit.gpg.testutil.TestKeys.validKeyWithSecondUserId) List(java.util.List) AddReviewerInput(com.google.gerrit.extensions.api.changes.AddReviewerInput) Ref(org.eclipse.jgit.lib.Ref) ConfigSuite(com.google.gerrit.testutil.ConfigSuite) RegistrationHandle(com.google.gerrit.extensions.registration.RegistrationHandle) RefPattern(com.google.gerrit.server.project.RefPattern) Message(com.google.gerrit.testutil.FakeEmailSender.Message) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) PublicKeyStore(com.google.gerrit.gpg.PublicKeyStore) SshKeyInfo(com.google.gerrit.extensions.common.SshKeyInfo) ImmutableList(com.google.common.collect.ImmutableList) UseSsh(com.google.gerrit.acceptance.UseSsh) Account(com.google.gerrit.reviewdb.client.Account) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Truth.assert_(com.google.common.truth.Truth.assert_) Iterator(java.util.Iterator) Sandboxed(com.google.gerrit.acceptance.Sandboxed) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Truth.assertThat(com.google.common.truth.Truth.assertThat) TransportException(org.eclipse.jgit.api.errors.TransportException) ArmoredOutputStream(org.bouncycastle.bcpg.ArmoredOutputStream) Provider(com.google.inject.Provider) RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) StarsInput(com.google.gerrit.extensions.api.changes.StarsInput) PushCertificateIdent(org.eclipse.jgit.transport.PushCertificateIdent) TestAccount(com.google.gerrit.acceptance.TestAccount) Account(com.google.gerrit.reviewdb.client.Account) TestKey(com.google.gerrit.gpg.testutil.TestKey) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) GpgKeyInfo(com.google.gerrit.extensions.common.GpgKeyInfo)

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