mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2025-09-08 17:59:43 +02:00
Test key generation with supported profiles
This commit is contained in:
parent
77106942d1
commit
4ef5444e78
1 changed files with 29 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.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.Arguments;
|
import org.junit.jupiter.params.provider.Arguments;
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
|
import sop.Profile;
|
||||||
import sop.SOP;
|
import sop.SOP;
|
||||||
import sop.exception.SOPGPException;
|
import sop.exception.SOPGPException;
|
||||||
import sop.testsuite.JUtils;
|
import sop.testsuite.JUtils;
|
||||||
|
@ -16,9 +17,11 @@ import sop.testsuite.TestData;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.List;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||||
|
|
||||||
@EnabledIf("sop.testsuite.operation.AbstractSOPTest#hasBackends")
|
@EnabledIf("sop.testsuite.operation.AbstractSOPTest#hasBackends")
|
||||||
public class GenerateKeyTest extends AbstractSOPTest {
|
public class GenerateKeyTest extends AbstractSOPTest {
|
||||||
|
@ -118,4 +121,30 @@ public class GenerateKeyTest extends AbstractSOPTest {
|
||||||
sop.encrypt().withCert(signingOnlyCert)
|
sop.encrypt().withCert(signingOnlyCert)
|
||||||
.plaintext(TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8)));
|
.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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue