1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-26 14:22:05 +01:00

Add regression test for #351

This commit is contained in:
Paul Schaub 2022-12-15 12:30:30 +01:00
parent 3b2d0795f7
commit ab6b6ca2e7

View file

@ -6,15 +6,20 @@ package org.pgpainless.sop;
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 static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException; import java.io.IOException;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPSecretKey;
import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.pgpainless.PGPainless; import org.pgpainless.PGPainless;
import org.pgpainless.key.info.KeyRingInfo; import org.pgpainless.key.info.KeyRingInfo;
import org.pgpainless.key.protection.UnlockSecretKey;
import org.pgpainless.util.Passphrase;
import sop.SOP; import sop.SOP;
public class GenerateKeyTest { public class GenerateKeyTest {
@ -67,4 +72,24 @@ public class GenerateKeyTest {
assertFalse(new String(bytes).startsWith("-----BEGIN PGP PRIVATE KEY BLOCK-----")); assertFalse(new String(bytes).startsWith("-----BEGIN PGP PRIVATE KEY BLOCK-----"));
} }
@Test
public void protectedMultiUserIdKey() throws IOException, PGPException {
byte[] bytes = sop.generateKey()
.userId("Alice")
.userId("Bob")
.withKeyPassword("sw0rdf1sh")
.generate()
.getBytes();
PGPSecretKeyRing secretKey = PGPainless.readKeyRing().secretKeyRing(bytes);
KeyRingInfo info = PGPainless.inspectKeyRing(secretKey);
assertTrue(info.getUserIds().contains("Alice"));
assertTrue(info.getUserIds().contains("Bob"));
for (PGPSecretKey key : secretKey) {
assertNotNull(UnlockSecretKey.unlockSecretKey(key, Passphrase.fromPassword("sw0rdf1sh")));
}
}
} }