mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-27 13:28:00 +01:00
Improve tests
This commit is contained in:
parent
63c75f1f86
commit
84ff6ce015
2 changed files with 8 additions and 20 deletions
|
@ -15,6 +15,8 @@
|
|||
*/
|
||||
package org.pgpainless.key.generation;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
@ -25,12 +27,12 @@ import org.junit.jupiter.params.ParameterizedTest;
|
|||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.pgpainless.PGPainless;
|
||||
import org.pgpainless.algorithm.KeyFlag;
|
||||
import org.pgpainless.algorithm.PublicKeyAlgorithm;
|
||||
import org.pgpainless.implementation.ImplementationFactory;
|
||||
import org.pgpainless.key.generation.type.KeyType;
|
||||
import org.pgpainless.key.generation.type.eddsa.EdDSACurve;
|
||||
import org.pgpainless.key.generation.type.xdh.XDHSpec;
|
||||
import org.pgpainless.key.util.UserId;
|
||||
import org.pgpainless.util.ArmorUtils;
|
||||
|
||||
public class GenerateEllipticCurveKeyTest {
|
||||
|
||||
|
@ -48,8 +50,7 @@ public class GenerateEllipticCurveKeyTest {
|
|||
.withPrimaryUserId(UserId.onlyEmail("alice@wonderland.lit").toString())
|
||||
.withoutPassphrase()
|
||||
.build();
|
||||
// CHECKSTYLE:OFF
|
||||
System.out.println(ArmorUtils.toAsciiArmoredString(keyRing));
|
||||
// CHECKSTYLE:ON
|
||||
|
||||
assertEquals(PublicKeyAlgorithm.EDDSA.getAlgorithmId(), keyRing.getPublicKey().getAlgorithm());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,14 +18,12 @@ package org.pgpainless.key.generation;
|
|||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.bouncycastle.bcpg.ArmoredOutputStream;
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||
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.util.KeyRingUtils;
|
||||
import org.pgpainless.key.util.UserId;
|
||||
import org.pgpainless.util.ArmoredOutputStreamFactory;
|
||||
import org.pgpainless.util.DateUtil;
|
||||
|
||||
public class GenerateKeyWithAdditionalUserIdTest {
|
||||
|
||||
|
@ -47,8 +45,7 @@ public class GenerateKeyWithAdditionalUserIdTest {
|
|||
@MethodSource("org.pgpainless.util.TestImplementationFactoryProvider#provideImplementationFactories")
|
||||
public void test(ImplementationFactory implementationFactory) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException {
|
||||
ImplementationFactory.setFactoryImplementation(implementationFactory);
|
||||
Date now = new Date();
|
||||
Date expiration = new Date(now.getTime() + 1000 * 60);
|
||||
Date expiration = new Date(DateUtil.now().getTime() + 60 * 1000);
|
||||
PGPSecretKeyRing secretKeys = PGPainless.generateKeyRing()
|
||||
.withPrimaryKey(KeySpec.getBuilder(KeyType.RSA(RsaLength._3072))
|
||||
.withKeyFlags(KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA, KeyFlag.ENCRYPT_COMMS)
|
||||
|
@ -62,7 +59,7 @@ public class GenerateKeyWithAdditionalUserIdTest {
|
|||
.build();
|
||||
PGPPublicKeyRing publicKeys = KeyRingUtils.publicKeyRingFrom(secretKeys);
|
||||
|
||||
JUtils.assertEquals(expiration.getTime(), PGPainless.inspectKeyRing(publicKeys).getPrimaryKeyExpirationDate().getTime(),2000);
|
||||
JUtils.assertEquals(expiration.getTime(), PGPainless.inspectKeyRing(publicKeys).getPrimaryKeyExpirationDate().getTime(), 2000);
|
||||
|
||||
Iterator<String> userIds = publicKeys.getPublicKey().getUserIDs();
|
||||
assertEquals("primary@user.id", userIds.next());
|
||||
|
@ -70,15 +67,5 @@ public class GenerateKeyWithAdditionalUserIdTest {
|
|||
assertEquals("additional2@user.id", userIds.next());
|
||||
assertEquals("trimThis@user.id", userIds.next());
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue