From 2f85c9a8d0755b8a34ccabe3416935d571594e48 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Fri, 16 Oct 2020 13:18:07 +0200 Subject: [PATCH] Test if userId is present --- .../GenerateKeyWithAdditionalUserIdTest.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyWithAdditionalUserIdTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyWithAdditionalUserIdTest.java index 4d3f4a90..97931065 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyWithAdditionalUserIdTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyWithAdditionalUserIdTest.java @@ -1,17 +1,19 @@ package org.pgpainless.key.generation; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.security.InvalidAlgorithmParameterException; import java.security.NoSuchAlgorithmException; +import java.util.Iterator; import org.bouncycastle.bcpg.ArmoredOutputStream; import org.bouncycastle.openpgp.PGPException; import org.junit.Test; import org.pgpainless.PGPainless; import org.pgpainless.key.collection.PGPKeyRing; -import org.pgpainless.key.generation.type.KeyType; import org.pgpainless.key.generation.type.RSA_SIGN; import org.pgpainless.key.generation.type.length.RsaLength; @@ -28,11 +30,17 @@ public class GenerateKeyWithAdditionalUserIdTest { .withoutPassphrase() .build(); + Iterator userIds = keyRing.getPublicKeys().getPublicKey().getUserIDs(); + assertEquals("primary@user.id", userIds.next()); + assertEquals("additional@user.id", userIds.next()); + assertFalse(userIds.hasNext()); + ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); ArmoredOutputStream armor = new ArmoredOutputStream(byteOut); keyRing.getSecretKeys().encode(armor); armor.close(); + // echo this | gpg --list-packets System.out.println(byteOut.toString("UTF-8")); } }