Search in sources :

Example 21 with TestKey

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

the class AccountIT method addGpgKey.

@Test
public void addGpgKey() throws Exception {
    TestKey key = validKeyWithoutExpiration();
    String id = key.getKeyIdString();
    addExternalIdEmail(admin, "test1@example.com");
    assertKeyMapContains(key, addGpgKey(key.getPublicKeyArmored()));
    assertKeys(key);
    setApiUser(user);
    exception.expect(ResourceNotFoundException.class);
    exception.expectMessage(id);
    gApi.accounts().self().gpgKey(id).get();
}
Also used : TestKey(com.google.gerrit.gpg.testutil.TestKey) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 22 with TestKey

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

the class AccountIT method addOtherUsersGpgKey_Conflict.

@Test
public void addOtherUsersGpgKey_Conflict() throws Exception {
    // Both users have a matching external ID for this key.
    addExternalIdEmail(admin, "test5@example.com");
    externalIdsUpdate.insert(ExternalId.create("foo", "myId", user.getId()));
    accountCache.evict(user.getId());
    accountIndexedCounter.assertReindexOf(user);
    TestKey key = validKeyWithSecondUserId();
    addGpgKey(key.getPublicKeyArmored());
    setApiUser(user);
    exception.expect(ResourceConflictException.class);
    exception.expectMessage("GPG key already associated with another account");
    addGpgKey(key.getPublicKeyArmored());
}
Also used : TestKey(com.google.gerrit.gpg.testutil.TestKey) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 23 with TestKey

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

the class AccountIT method deleteGpgKey.

@Test
public void deleteGpgKey() throws Exception {
    TestKey key = validKeyWithoutExpiration();
    String id = key.getKeyIdString();
    addExternalIdEmail(admin, "test1@example.com");
    addGpgKey(key.getPublicKeyArmored());
    assertKeys(key);
    gApi.accounts().self().gpgKey(id).delete();
    accountIndexedCounter.assertReindexOf(admin);
    assertKeys();
    exception.expect(ResourceNotFoundException.class);
    exception.expectMessage(id);
    gApi.accounts().self().gpgKey(id).get();
}
Also used : TestKey(com.google.gerrit.gpg.testutil.TestKey) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 24 with TestKey

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

the class AccountIT method reAddExistingGpgKey.

@Test
public void reAddExistingGpgKey() throws Exception {
    addExternalIdEmail(admin, "test5@example.com");
    TestKey key = validKeyWithSecondUserId();
    String id = key.getKeyIdString();
    PGPPublicKey pk = key.getPublicKey();
    GpgKeyInfo info = addGpgKey(armor(pk)).get(id);
    assertThat(info.userIds).hasSize(2);
    assertIteratorSize(2, getOnlyKeyFromStore(key).getUserIDs());
    pk = PGPPublicKey.removeCertification(pk, "foo:myId");
    info = addGpgKey(armor(pk)).get(id);
    assertThat(info.userIds).hasSize(1);
    assertIteratorSize(1, getOnlyKeyFromStore(key).getUserIDs());
}
Also used : TestKey(com.google.gerrit.gpg.testutil.TestKey) PGPPublicKey(org.bouncycastle.openpgp.PGPPublicKey) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) GpgKeyInfo(com.google.gerrit.extensions.common.GpgKeyInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 25 with TestKey

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

the class AccountIT method addAndRemoveGpgKeys.

@Test
public void addAndRemoveGpgKeys() throws Exception {
    for (TestKey key : allValidKeys()) {
        addExternalIdEmail(admin, PushCertificateIdent.parse(key.getFirstUserId()).getEmailAddress());
    }
    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);
    exception.expect(BadRequestException.class);
    exception.expectMessage("Cannot both add and delete key: " + keyToString(key2.getPublicKey()));
    infos = gApi.accounts().self().putGpgKeys(ImmutableList.of(key2.getPublicKeyArmored()), ImmutableList.of(key2.getKeyIdString()));
}
Also used : TestKey(com.google.gerrit.gpg.testutil.TestKey) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) GpgKeyInfo(com.google.gerrit.extensions.common.GpgKeyInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

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