1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-30 08:12:06 +01:00

Improve tests

This commit is contained in:
Paul Schaub 2021-07-03 12:42:17 +02:00
parent 63c75f1f86
commit 84ff6ce015
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
2 changed files with 8 additions and 20 deletions

View file

@ -15,6 +15,8 @@
*/ */
package org.pgpainless.key.generation; package org.pgpainless.key.generation;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.security.InvalidAlgorithmParameterException; import java.security.InvalidAlgorithmParameterException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
@ -25,12 +27,12 @@ import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource; import org.junit.jupiter.params.provider.MethodSource;
import org.pgpainless.PGPainless; import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.KeyFlag; import org.pgpainless.algorithm.KeyFlag;
import org.pgpainless.algorithm.PublicKeyAlgorithm;
import org.pgpainless.implementation.ImplementationFactory; import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.generation.type.KeyType; import org.pgpainless.key.generation.type.KeyType;
import org.pgpainless.key.generation.type.eddsa.EdDSACurve; import org.pgpainless.key.generation.type.eddsa.EdDSACurve;
import org.pgpainless.key.generation.type.xdh.XDHSpec; import org.pgpainless.key.generation.type.xdh.XDHSpec;
import org.pgpainless.key.util.UserId; import org.pgpainless.key.util.UserId;
import org.pgpainless.util.ArmorUtils;
public class GenerateEllipticCurveKeyTest { public class GenerateEllipticCurveKeyTest {
@ -48,8 +50,7 @@ public class GenerateEllipticCurveKeyTest {
.withPrimaryUserId(UserId.onlyEmail("alice@wonderland.lit").toString()) .withPrimaryUserId(UserId.onlyEmail("alice@wonderland.lit").toString())
.withoutPassphrase() .withoutPassphrase()
.build(); .build();
// CHECKSTYLE:OFF
System.out.println(ArmorUtils.toAsciiArmoredString(keyRing)); assertEquals(PublicKeyAlgorithm.EDDSA.getAlgorithmId(), keyRing.getPublicKey().getAlgorithm());
// CHECKSTYLE:ON
} }
} }

View file

@ -18,14 +18,12 @@ package org.pgpainless.key.generation;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.security.InvalidAlgorithmParameterException; import java.security.InvalidAlgorithmParameterException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.Date; import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import org.bouncycastle.bcpg.ArmoredOutputStream;
import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKeyRing; import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRing;
@ -39,7 +37,7 @@ import org.pgpainless.key.generation.type.KeyType;
import org.pgpainless.key.generation.type.rsa.RsaLength; import org.pgpainless.key.generation.type.rsa.RsaLength;
import org.pgpainless.key.util.KeyRingUtils; import org.pgpainless.key.util.KeyRingUtils;
import org.pgpainless.key.util.UserId; import org.pgpainless.key.util.UserId;
import org.pgpainless.util.ArmoredOutputStreamFactory; import org.pgpainless.util.DateUtil;
public class GenerateKeyWithAdditionalUserIdTest { public class GenerateKeyWithAdditionalUserIdTest {
@ -47,8 +45,7 @@ public class GenerateKeyWithAdditionalUserIdTest {
@MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories") @MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories")
public void test(ImplementationFactory implementationFactory) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException { public void test(ImplementationFactory implementationFactory) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException {
ImplementationFactory.setFactoryImplementation(implementationFactory); ImplementationFactory.setFactoryImplementation(implementationFactory);
Date now = new Date(); Date expiration = new Date(DateUtil.now().getTime() + 60 * 1000);
Date expiration = new Date(now.getTime() + 1000 * 60);
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing() PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
.withPrimaryKey(KeySpec.getBuilder(KeyType.RSA(RsaLength._3072)) .withPrimaryKey(KeySpec.getBuilder(KeyType.RSA(RsaLength._3072))
.withKeyFlags(KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA, KeyFlag.ENCRYPT_COMMS) .withKeyFlags(KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA, KeyFlag.ENCRYPT_COMMS)
@ -70,15 +67,5 @@ public class GenerateKeyWithAdditionalUserIdTest {
assertEquals("additional2@user.id", userIds.next()); assertEquals("additional2@user.id", userIds.next());
assertEquals("trimThis@user.id", userIds.next()); assertEquals("trimThis@user.id", userIds.next());
assertFalse(userIds.hasNext()); assertFalse(userIds.hasNext());
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
ArmoredOutputStream armor = ArmoredOutputStreamFactory.get(byteOut);
secretKeys.encode(armor);
armor.close();
// echo this | gpg --list-packets
// CHECKSTYLE:OFF
System.out.println(byteOut.toString("UTF-8"));
// CHECKSTYLE:ON
} }
} }