mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2025-09-08 09:49:44 +02:00
Compare commits
2 commits
7c4b4a4ddb
...
589dcacd91
Author | SHA1 | Date | |
---|---|---|---|
589dcacd91 | |||
34e38f3661 |
2 changed files with 111 additions and 0 deletions
|
@ -9,6 +9,7 @@ import org.junit.jupiter.api.condition.EnabledIf;
|
|||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import sop.Profile;
|
||||
import sop.SOP;
|
||||
import sop.exception.SOPGPException;
|
||||
import sop.testsuite.JUtils;
|
||||
|
@ -16,9 +17,11 @@ import sop.testsuite.TestData;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
@EnabledIf("sop.testsuite.operation.AbstractSOPTest#hasBackends")
|
||||
public class GenerateKeyTest extends AbstractSOPTest {
|
||||
|
@ -118,4 +121,30 @@ public class GenerateKeyTest extends AbstractSOPTest {
|
|||
sop.encrypt().withCert(signingOnlyCert)
|
||||
.plaintext(TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8)));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void generateKeyWithSupportedProfiles(SOP sop) throws IOException {
|
||||
List<Profile> profiles = sop.listProfiles()
|
||||
.generateKey();
|
||||
|
||||
for (Profile profile : profiles) {
|
||||
generateKeyWithProfile(sop, profile.getName());
|
||||
}
|
||||
}
|
||||
|
||||
private void generateKeyWithProfile(SOP sop, String profile) throws IOException {
|
||||
byte[] key;
|
||||
try {
|
||||
key = sop.generateKey()
|
||||
.profile(profile)
|
||||
.userId("Alice <alice@pgpainless.org>")
|
||||
.generate()
|
||||
.getBytes();
|
||||
} catch (SOPGPException.UnsupportedProfile e) {
|
||||
key = null;
|
||||
}
|
||||
assumeTrue(key != null, "'generate-key' does not support profile '" + profile + "'.");
|
||||
JUtils.assertArrayStartsWith(key, TestData.BEGIN_PGP_PRIVATE_KEY_BLOCK);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
package sop.testsuite.operation;
|
||||
|
||||
import kotlin.collections.ArraysKt;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
@ -43,6 +44,52 @@ public class MergeCertsTest extends AbstractSOPTest {
|
|||
assertArrayEquals(cert, merged);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void testMergeWithItselfArmored(SOP sop) throws IOException {
|
||||
byte[] key = sop.generateKey()
|
||||
.noArmor()
|
||||
.userId("Alice <alice@pgpainless.org>")
|
||||
.generate()
|
||||
.getBytes();
|
||||
|
||||
byte[] cert = sop.extractCert()
|
||||
.key(key)
|
||||
.getBytes();
|
||||
|
||||
byte[] merged = sop.mergeCerts()
|
||||
.updates(cert)
|
||||
.baseCertificates(cert)
|
||||
.getBytes();
|
||||
|
||||
assertArrayEquals(cert, merged);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void testMergeWithItselfViaBase(SOP sop) throws IOException {
|
||||
byte[] key = sop.generateKey()
|
||||
.noArmor()
|
||||
.userId("Alice <alice@pgpainless.org>")
|
||||
.generate()
|
||||
.getBytes();
|
||||
|
||||
byte[] cert = sop.extractCert()
|
||||
.noArmor()
|
||||
.key(key)
|
||||
.getBytes();
|
||||
|
||||
byte[] certs = ArraysKt.plus(cert, cert);
|
||||
|
||||
byte[] merged = sop.mergeCerts()
|
||||
.noArmor()
|
||||
.updates(cert)
|
||||
.baseCertificates(certs)
|
||||
.getBytes();
|
||||
|
||||
assertArrayEquals(cert, merged);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void testApplyBaseToUpdate(SOP sop) throws IOException {
|
||||
|
@ -98,4 +145,39 @@ public class MergeCertsTest extends AbstractSOPTest {
|
|||
|
||||
assertArrayEquals(update, merged);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void testApplyUpdateToMissingBaseDoesNothing(SOP sop) throws IOException {
|
||||
byte[] aliceKey = sop.generateKey()
|
||||
.noArmor()
|
||||
.userId("Alice <alice@pgpainless.org>")
|
||||
.generate()
|
||||
.getBytes();
|
||||
|
||||
byte[] aliceCert = sop.extractCert()
|
||||
.noArmor()
|
||||
.key(aliceKey)
|
||||
.getBytes();
|
||||
|
||||
byte[] bobKey = sop.generateKey()
|
||||
.noArmor()
|
||||
.userId("Bob <bob@pgpainless.org>")
|
||||
.generate()
|
||||
.getBytes();
|
||||
|
||||
byte[] bobCert = sop.extractCert()
|
||||
.noArmor()
|
||||
.key(bobKey)
|
||||
.getBytes();
|
||||
|
||||
byte[] merged = sop.mergeCerts()
|
||||
.noArmor()
|
||||
.updates(bobCert)
|
||||
.baseCertificates(aliceCert)
|
||||
.getBytes();
|
||||
|
||||
assertArrayEquals(aliceCert, merged);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue