mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2024-11-17 13:12:04 +01:00
Restructure external-sop tests into flexible test suite
This commit is contained in:
parent
0c8f6baf98
commit
0b96a5314f
15 changed files with 398 additions and 539 deletions
|
@ -14,7 +14,9 @@ repositories {
|
|||
|
||||
dependencies {
|
||||
testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
|
||||
testImplementation "org.junit.jupiter:junit-jupiter-params:$junitVersion"
|
||||
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
|
||||
testImplementation "com.google.code.gson:gson:2.10.1"
|
||||
|
||||
api project(":sop-java")
|
||||
|
||||
|
@ -30,4 +32,6 @@ dependencies {
|
|||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
// since we test external backends, we ignore test failures in this module
|
||||
ignoreFailures = true
|
||||
}
|
|
@ -2,5 +2,4 @@
|
|||
#
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
backend.local.properties
|
||||
backend.env
|
||||
config.json
|
|
@ -1,7 +0,0 @@
|
|||
# SPDX-FileCopyrightText: 2023 Paul Schaub <info@pgpainless.org>
|
||||
#
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
## Do not change this file. To overwrite the SOP backend used during testing,
|
||||
## simply create a file 'backend.local.properties' in this directory and override sop.backend in there.
|
||||
sop.backend=/path/to/backend
|
17
external-sop/src/main/resources/sop/external/config.json.example
vendored
Normal file
17
external-sop/src/main/resources/sop/external/config.json.example
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"backends": [
|
||||
{
|
||||
"name": "Example-SOP",
|
||||
"sop": "/usr/bin/example-sop"
|
||||
},
|
||||
{
|
||||
"name": "Awesome-SOP",
|
||||
"sop": "/usr/local/bin/awesome-sop",
|
||||
"env": [
|
||||
{
|
||||
"key": "myEnvironmentVariable", "value": "FooBar"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
|
@ -4,174 +4,78 @@
|
|||
|
||||
package sop.external;
|
||||
|
||||
import org.apache.maven.artifact.versioning.ComparableVersion;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import com.google.gson.Gson;
|
||||
import org.junit.jupiter.api.Named;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import sop.SOP;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assumptions.assumeFalse;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
public abstract class AbstractExternalSOPTest {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractExternalSOPTest.class);
|
||||
private static final List<Arguments> backends = new ArrayList<>();
|
||||
|
||||
private final SOP sop;
|
||||
static {
|
||||
TestSuite suite = readConfiguration();
|
||||
assumeTrue(suite != null);
|
||||
assumeFalse(suite.backends.isEmpty());
|
||||
|
||||
public AbstractExternalSOPTest() {
|
||||
String backend = readSopBackendFromProperties();
|
||||
assumeTrue(backend != null);
|
||||
Properties environment = readBackendEnvironment();
|
||||
sop = new ExternalSOP(backend, environment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the SOP backend.
|
||||
*
|
||||
* @return SOP backend
|
||||
*/
|
||||
public SOP getSop() {
|
||||
return sop;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return <pre>true</pre> iff the specified SOP backend binary is available and accessible.
|
||||
*
|
||||
* @return true if external SOP backend is usable
|
||||
*/
|
||||
public static boolean isExternalSopInstalled() {
|
||||
String binary = readSopBackendFromProperties();
|
||||
if (binary == null) {
|
||||
return false;
|
||||
}
|
||||
return new File(binary).exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Relational enum.
|
||||
*/
|
||||
public enum Is {
|
||||
/**
|
||||
* Less than.
|
||||
*/
|
||||
le("<"),
|
||||
/**
|
||||
* Less or equal than.
|
||||
*/
|
||||
leq("<="),
|
||||
/**
|
||||
* Equal.
|
||||
*/
|
||||
eq("=="),
|
||||
/**
|
||||
* Not equal.
|
||||
*/
|
||||
neq("!="),
|
||||
/**
|
||||
* Greater or equal than.
|
||||
*/
|
||||
geq(">="),
|
||||
/**
|
||||
* Greater than.
|
||||
*/
|
||||
ge(">"),
|
||||
;
|
||||
|
||||
private final String display;
|
||||
|
||||
Is(String display) {
|
||||
this.display = display;
|
||||
}
|
||||
|
||||
public String toDisplay() {
|
||||
return display;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ignore a test if the tested binary version matches a version criterion.
|
||||
* Example:
|
||||
* If the installed version of example-sop is 0.1.3, <pre>ignoreIf("example-sop", Is.le, "0.1.4")</pre> will
|
||||
* make the test be ignored.
|
||||
* <pre>ignoreIf("example-sop", Is.eq, "0.1.3")</pre> will skip the test as well.
|
||||
* <pre>ignoreIf("another-sop", Is.gt, "0.0.0")</pre> will not skip the test, since the binary name does not match.
|
||||
*
|
||||
* @param name name of the binary
|
||||
* @param is relation of the version
|
||||
* @param version the reference version
|
||||
*/
|
||||
public void ignoreIf(String name, Is is, String version) {
|
||||
String actualName = getSop().version().getName();
|
||||
String actualVersion = getSop().version().getVersion();
|
||||
|
||||
if (!name.matches(actualName)) {
|
||||
// Name mismatch, do not ignore
|
||||
return;
|
||||
}
|
||||
|
||||
ComparableVersion reference = new ComparableVersion(version);
|
||||
ComparableVersion actual = new ComparableVersion(actualVersion);
|
||||
|
||||
int res = actual.compareTo(reference);
|
||||
String msg = "Skip since installed " + name + " " + actual + " " + is.toDisplay() + " " + reference;
|
||||
switch (is) {
|
||||
case le:
|
||||
assumeFalse(res < 0, msg);
|
||||
break;
|
||||
case leq:
|
||||
assumeFalse(res <= 0, msg);
|
||||
case eq:
|
||||
assumeFalse(res == 0, msg);
|
||||
break;
|
||||
case neq:
|
||||
assumeFalse(res != 0, msg);
|
||||
break;
|
||||
case geq:
|
||||
assumeFalse(res >= 0, msg);
|
||||
break;
|
||||
case ge:
|
||||
assumeFalse(res > 0, msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static String readSopBackendFromProperties() {
|
||||
Properties properties = new Properties();
|
||||
try {
|
||||
InputStream resourceIn = AbstractExternalSOPTest.class.getResourceAsStream("backend.local.properties");
|
||||
if (resourceIn == null) {
|
||||
LOGGER.info("Could not find backend.local.properties file. Try backend.properties instead.");
|
||||
resourceIn = AbstractExternalSOPTest.class.getResourceAsStream("backend.properties");
|
||||
}
|
||||
if (resourceIn == null) {
|
||||
throw new FileNotFoundException("Could not find backend.properties file.");
|
||||
for (TestSubject subject : suite.backends) {
|
||||
if (!new File(subject.sop).exists()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
properties.load(resourceIn);
|
||||
return properties.getProperty("sop.backend");
|
||||
} catch (IOException e) {
|
||||
Properties env = new Properties();
|
||||
if (subject.env != null) {
|
||||
for (Var var : subject.env) {
|
||||
env.put(var.key, var.value);
|
||||
}
|
||||
}
|
||||
|
||||
SOP sop = new ExternalSOP(subject.sop, env);
|
||||
backends.add(Arguments.of(Named.of(subject.name, sop)));
|
||||
}
|
||||
}
|
||||
|
||||
public static Stream<Arguments> provideBackends() {
|
||||
return backends.stream();
|
||||
}
|
||||
|
||||
public static TestSuite readConfiguration() {
|
||||
Gson gson = new Gson();
|
||||
InputStream inputStream = AbstractExternalSOPTest.class.getResourceAsStream("config.json");
|
||||
if (inputStream == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
InputStreamReader reader = new InputStreamReader(inputStream);
|
||||
TestSuite suite = gson.fromJson(reader, TestSuite.class);
|
||||
return suite;
|
||||
}
|
||||
|
||||
protected static Properties readBackendEnvironment() {
|
||||
Properties properties = new Properties();
|
||||
try {
|
||||
InputStream resourceIn = AbstractExternalSOPTest.class.getResourceAsStream("backend.env");
|
||||
if (resourceIn == null) {
|
||||
LOGGER.info("Could not read backend.env file.");
|
||||
} else {
|
||||
properties.load(resourceIn);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return properties;
|
||||
// JSON DTOs
|
||||
|
||||
public static class TestSuite {
|
||||
List<TestSubject> backends;
|
||||
}
|
||||
|
||||
public static class TestSubject {
|
||||
String name;
|
||||
String sop;
|
||||
List<Var> env;
|
||||
}
|
||||
|
||||
public static class Var {
|
||||
String key;
|
||||
String value;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,9 @@
|
|||
|
||||
package sop.external;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import sop.SOP;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
@ -16,7 +17,6 @@ import static sop.external.JUtils.arrayStartsWith;
|
|||
import static sop.external.JUtils.assertArrayStartsWith;
|
||||
import static sop.external.JUtils.assertAsciiArmorEquals;
|
||||
|
||||
@EnabledIf("sop.external.AbstractExternalSOPTest#isExternalSopInstalled")
|
||||
public class ExternalArmorDearmorRoundTripTest extends AbstractExternalSOPTest {
|
||||
|
||||
private static final String BEGIN_PGP_PRIVATE_KEY_BLOCK = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n";
|
||||
|
@ -28,17 +28,18 @@ public class ExternalArmorDearmorRoundTripTest extends AbstractExternalSOPTest {
|
|||
private static final String BEGIN_PGP_SIGNATURE = "-----BEGIN PGP SIGNATURE-----\n";
|
||||
private static final byte[] BEGIN_PGP_SIGNATURE_BYTES = BEGIN_PGP_SIGNATURE.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
@Test
|
||||
public void dearmorArmorAliceKey() throws IOException {
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void dearmorArmorAliceKey(SOP sop) throws IOException {
|
||||
byte[] aliceKey = TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] dearmored = getSop().dearmor()
|
||||
byte[] dearmored = sop.dearmor()
|
||||
.data(aliceKey)
|
||||
.getBytes();
|
||||
|
||||
assertFalse(arrayStartsWith(dearmored, BEGIN_PGP_PRIVATE_KEY_BLOCK_BYTES));
|
||||
|
||||
byte[] armored = getSop().armor()
|
||||
byte[] armored = sop.armor()
|
||||
.data(dearmored)
|
||||
.getBytes();
|
||||
|
||||
|
@ -46,17 +47,18 @@ public class ExternalArmorDearmorRoundTripTest extends AbstractExternalSOPTest {
|
|||
assertAsciiArmorEquals(aliceKey, armored);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dearmorArmorAliceCert() throws IOException {
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void dearmorArmorAliceCert(SOP sop) throws IOException {
|
||||
byte[] aliceCert = TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] dearmored = getSop().dearmor()
|
||||
byte[] dearmored = sop.dearmor()
|
||||
.data(aliceCert)
|
||||
.getBytes();
|
||||
|
||||
assertFalse(arrayStartsWith(dearmored, BEGIN_PGP_PUBLIC_KEY_BLOCK_BYTES));
|
||||
|
||||
byte[] armored = getSop().armor()
|
||||
byte[] armored = sop.armor()
|
||||
.data(dearmored)
|
||||
.getBytes();
|
||||
|
||||
|
@ -64,17 +66,18 @@ public class ExternalArmorDearmorRoundTripTest extends AbstractExternalSOPTest {
|
|||
assertAsciiArmorEquals(aliceCert, armored);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dearmorArmorBobKey() throws IOException {
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void dearmorArmorBobKey(SOP sop) throws IOException {
|
||||
byte[] bobKey = TestData.BOB_KEY.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] dearmored = getSop().dearmor()
|
||||
byte[] dearmored = sop.dearmor()
|
||||
.data(bobKey)
|
||||
.getBytes();
|
||||
|
||||
assertFalse(arrayStartsWith(dearmored, BEGIN_PGP_PRIVATE_KEY_BLOCK_BYTES));
|
||||
|
||||
byte[] armored = getSop().armor()
|
||||
byte[] armored = sop.armor()
|
||||
.data(dearmored)
|
||||
.getBytes();
|
||||
|
||||
|
@ -82,17 +85,18 @@ public class ExternalArmorDearmorRoundTripTest extends AbstractExternalSOPTest {
|
|||
assertAsciiArmorEquals(bobKey, armored);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dearmorArmorBobCert() throws IOException {
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void dearmorArmorBobCert(SOP sop) throws IOException {
|
||||
byte[] bobCert = TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] dearmored = getSop().dearmor()
|
||||
byte[] dearmored = sop.dearmor()
|
||||
.data(bobCert)
|
||||
.getBytes();
|
||||
|
||||
assertFalse(arrayStartsWith(dearmored, BEGIN_PGP_PUBLIC_KEY_BLOCK_BYTES));
|
||||
|
||||
byte[] armored = getSop().armor()
|
||||
byte[] armored = sop.armor()
|
||||
.data(dearmored)
|
||||
.getBytes();
|
||||
|
||||
|
@ -100,17 +104,18 @@ public class ExternalArmorDearmorRoundTripTest extends AbstractExternalSOPTest {
|
|||
assertAsciiArmorEquals(bobCert, armored);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dearmorArmorCarolKey() throws IOException {
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void dearmorArmorCarolKey(SOP sop) throws IOException {
|
||||
byte[] carolKey = TestData.CAROL_KEY.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] dearmored = getSop().dearmor()
|
||||
byte[] dearmored = sop.dearmor()
|
||||
.data(carolKey)
|
||||
.getBytes();
|
||||
|
||||
assertFalse(arrayStartsWith(dearmored, BEGIN_PGP_PRIVATE_KEY_BLOCK_BYTES));
|
||||
|
||||
byte[] armored = getSop().armor()
|
||||
byte[] armored = sop.armor()
|
||||
.data(dearmored)
|
||||
.getBytes();
|
||||
|
||||
|
@ -118,17 +123,18 @@ public class ExternalArmorDearmorRoundTripTest extends AbstractExternalSOPTest {
|
|||
assertAsciiArmorEquals(carolKey, armored);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dearmorArmorCarolCert() throws IOException {
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void dearmorArmorCarolCert(SOP sop) throws IOException {
|
||||
byte[] carolCert = TestData.CAROL_CERT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] dearmored = getSop().dearmor()
|
||||
byte[] dearmored = sop.dearmor()
|
||||
.data(carolCert)
|
||||
.getBytes();
|
||||
|
||||
assertFalse(arrayStartsWith(dearmored, BEGIN_PGP_PUBLIC_KEY_BLOCK_BYTES));
|
||||
|
||||
byte[] armored = getSop().armor()
|
||||
byte[] armored = sop.armor()
|
||||
.data(dearmored)
|
||||
.getBytes();
|
||||
|
||||
|
@ -136,9 +142,9 @@ public class ExternalArmorDearmorRoundTripTest extends AbstractExternalSOPTest {
|
|||
assertAsciiArmorEquals(carolCert, armored);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dearmorArmorMessage() throws IOException {
|
||||
ignoreIf("sqop", Is.leq, "0.26.1"); // falsely reports Invalid Data Type
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void dearmorArmorMessage(SOP sop) throws IOException {
|
||||
byte[] message = ("-----BEGIN PGP MESSAGE-----\n" +
|
||||
"\n" +
|
||||
"wV4DR2b2udXyHrYSAQdAMZy9Iqb1IxszjI3v+TsfK//0lnJ9PKHDqVAB5ohp+RMw\n" +
|
||||
|
@ -147,13 +153,13 @@ public class ExternalArmorDearmorRoundTripTest extends AbstractExternalSOPTest {
|
|||
"CePQFpprprnGEzpE3flQLUc=\n" +
|
||||
"=ZiFR\n" +
|
||||
"-----END PGP MESSAGE-----\n").getBytes(StandardCharsets.UTF_8);
|
||||
byte[] dearmored = getSop().dearmor()
|
||||
byte[] dearmored = sop.dearmor()
|
||||
.data(message)
|
||||
.getBytes();
|
||||
|
||||
assertFalse(arrayStartsWith(dearmored, BEGIN_PGP_MESSAGE_BYTES));
|
||||
|
||||
byte[] armored = getSop().armor()
|
||||
byte[] armored = sop.armor()
|
||||
.data(dearmored)
|
||||
.getBytes();
|
||||
|
||||
|
@ -161,8 +167,9 @@ public class ExternalArmorDearmorRoundTripTest extends AbstractExternalSOPTest {
|
|||
assertAsciiArmorEquals(message, armored);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dearmorArmorSignature() throws IOException {
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void dearmorArmorSignature(SOP sop) throws IOException {
|
||||
byte[] signature = ("-----BEGIN PGP SIGNATURE-----\n" +
|
||||
"\n" +
|
||||
"wr0EABYKAG8FgmPBdRAJEPIxVQxPR+OORxQAAAAAAB4AIHNhbHRAbm90YXRpb25z\n" +
|
||||
|
@ -172,13 +179,13 @@ public class ExternalArmorDearmorRoundTripTest extends AbstractExternalSOPTest {
|
|||
"=GHvQ\n" +
|
||||
"-----END PGP SIGNATURE-----\n").getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] dearmored = getSop().dearmor()
|
||||
byte[] dearmored = sop.dearmor()
|
||||
.data(signature)
|
||||
.getBytes();
|
||||
|
||||
assertFalse(arrayStartsWith(dearmored, BEGIN_PGP_SIGNATURE_BYTES));
|
||||
|
||||
byte[] armored = getSop().armor()
|
||||
byte[] armored = sop.armor()
|
||||
.data(dearmored)
|
||||
.getBytes();
|
||||
|
||||
|
@ -186,23 +193,23 @@ public class ExternalArmorDearmorRoundTripTest extends AbstractExternalSOPTest {
|
|||
assertAsciiArmorEquals(signature, armored);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDearmoringTwiceIsIdempotent() throws IOException {
|
||||
ignoreIf("sqop", Is.eq, "0.27.2"); // IO error because: EOF
|
||||
|
||||
byte[] dearmored = getSop().dearmor()
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void testDearmoringTwiceIsIdempotent(SOP sop) throws IOException {
|
||||
byte[] dearmored = sop.dearmor()
|
||||
.data(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.getBytes();
|
||||
|
||||
byte[] dearmoredAgain = getSop().dearmor()
|
||||
byte[] dearmoredAgain = sop.dearmor()
|
||||
.data(dearmored)
|
||||
.getBytes();
|
||||
|
||||
assertArrayEquals(dearmored, dearmoredAgain);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArmoringTwiceIsIdempotent() throws IOException {
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void testArmoringTwiceIsIdempotent(SOP sop) throws IOException {
|
||||
byte[] armored = ("-----BEGIN PGP SIGNATURE-----\n" +
|
||||
"\n" +
|
||||
"wr0EABYKAG8FgmPBdRAJEPIxVQxPR+OORxQAAAAAAB4AIHNhbHRAbm90YXRpb25z\n" +
|
||||
|
@ -212,7 +219,7 @@ public class ExternalArmorDearmorRoundTripTest extends AbstractExternalSOPTest {
|
|||
"=GHvQ\n" +
|
||||
"-----END PGP SIGNATURE-----\n").getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] armoredAgain = getSop().armor()
|
||||
byte[] armoredAgain = sop.armor()
|
||||
.data(armored)
|
||||
.getBytes();
|
||||
|
||||
|
|
|
@ -4,10 +4,11 @@
|
|||
|
||||
package sop.external;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import sop.ByteArrayAndResult;
|
||||
import sop.DecryptionResult;
|
||||
import sop.SOP;
|
||||
import sop.SessionKey;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -16,7 +17,6 @@ import java.nio.charset.StandardCharsets;
|
|||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
@EnabledIf("sop.external.AbstractExternalSOPTest#isExternalSopInstalled")
|
||||
public class ExternalDecryptWithSessionKeyTest extends AbstractExternalSOPTest {
|
||||
|
||||
private static final String CIPHERTEXT = "-----BEGIN PGP MESSAGE-----\n" +
|
||||
|
@ -29,9 +29,10 @@ public class ExternalDecryptWithSessionKeyTest extends AbstractExternalSOPTest {
|
|||
"-----END PGP MESSAGE-----\n";
|
||||
private static final String SESSION_KEY = "9:ED682800F5FEA829A82E8B7DDF8CE9CF4BF9BB45024B017764462EE53101C36A";
|
||||
|
||||
@Test
|
||||
public void testDecryptAndExtractSessionKey() throws IOException {
|
||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = getSop().decrypt()
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void testDecryptAndExtractSessionKey(SOP sop) throws IOException {
|
||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
||||
.withKey(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.ciphertext(CIPHERTEXT.getBytes(StandardCharsets.UTF_8))
|
||||
.toByteArrayAndResult();
|
||||
|
@ -41,9 +42,10 @@ public class ExternalDecryptWithSessionKeyTest extends AbstractExternalSOPTest {
|
|||
assertArrayEquals("Hello, World!\n".getBytes(StandardCharsets.UTF_8), bytesAndResult.getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecryptWithSessionKey() throws IOException {
|
||||
byte[] decrypted = getSop().decrypt()
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void testDecryptWithSessionKey(SOP sop) throws IOException {
|
||||
byte[] decrypted = sop.decrypt()
|
||||
.withSessionKey(SessionKey.fromString(SESSION_KEY))
|
||||
.ciphertext(CIPHERTEXT.getBytes(StandardCharsets.UTF_8))
|
||||
.toByteArrayAndResult()
|
||||
|
|
|
@ -4,8 +4,9 @@
|
|||
|
||||
package sop.external;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import sop.SOP;
|
||||
import sop.Verification;
|
||||
import sop.enums.SignAs;
|
||||
import sop.exception.SOPGPException;
|
||||
|
@ -20,23 +21,23 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
|||
import static sop.external.JUtils.assertArrayStartsWith;
|
||||
import static sop.external.JUtils.assertSignedBy;
|
||||
|
||||
@EnabledIf("sop.external.AbstractExternalSOPTest#isExternalSopInstalled")
|
||||
public class ExternalDetachedSignVerifyRoundTripTest extends AbstractExternalSOPTest {
|
||||
|
||||
private static final String BEGIN_PGP_SIGNATURE = "-----BEGIN PGP SIGNATURE-----\n";
|
||||
private static final byte[] BEGIN_PGP_SIGNATURE_BYTES = BEGIN_PGP_SIGNATURE.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
@Test
|
||||
public void signVerifyWithAliceKey() throws IOException {
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void signVerifyWithAliceKey(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] signature = getSop().detachedSign()
|
||||
byte[] signature = sop.detachedSign()
|
||||
.key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.data(message)
|
||||
.toByteArrayAndResult()
|
||||
.getBytes();
|
||||
|
||||
List<Verification> verificationList = getSop().detachedVerify()
|
||||
List<Verification> verificationList = sop.detachedVerify()
|
||||
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signatures(signature)
|
||||
.data(message);
|
||||
|
@ -45,18 +46,19 @@ public class ExternalDetachedSignVerifyRoundTripTest extends AbstractExternalSOP
|
|||
assertSignedBy(verificationList, TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void signVerifyTextModeWithAliceKey() throws IOException {
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void signVerifyTextModeWithAliceKey(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] signature = getSop().detachedSign()
|
||||
byte[] signature = sop.detachedSign()
|
||||
.key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.mode(SignAs.Text)
|
||||
.data(message)
|
||||
.toByteArrayAndResult()
|
||||
.getBytes();
|
||||
|
||||
List<Verification> verificationList = getSop().detachedVerify()
|
||||
List<Verification> verificationList = sop.detachedVerify()
|
||||
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signatures(signature)
|
||||
.data(message);
|
||||
|
@ -65,12 +67,13 @@ public class ExternalDetachedSignVerifyRoundTripTest extends AbstractExternalSOP
|
|||
assertSignedBy(verificationList, TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyKnownMessageWithAliceCert() throws IOException {
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void verifyKnownMessageWithAliceCert(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] signature = TestData.ALICE_DETACHED_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
List<Verification> verificationList = getSop().detachedVerify()
|
||||
List<Verification> verificationList = sop.detachedVerify()
|
||||
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signatures(signature)
|
||||
.data(message);
|
||||
|
@ -79,17 +82,18 @@ public class ExternalDetachedSignVerifyRoundTripTest extends AbstractExternalSOP
|
|||
assertSignedBy(verificationList, TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT, TestData.ALICE_DETACHED_SIGNED_MESSAGE_DATE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void signVerifyWithBobKey() throws IOException {
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void signVerifyWithBobKey(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] signature = getSop().detachedSign()
|
||||
byte[] signature = sop.detachedSign()
|
||||
.key(TestData.BOB_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.data(message)
|
||||
.toByteArrayAndResult()
|
||||
.getBytes();
|
||||
|
||||
List<Verification> verificationList = getSop().detachedVerify()
|
||||
List<Verification> verificationList = sop.detachedVerify()
|
||||
.cert(TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signatures(signature)
|
||||
.data(message);
|
||||
|
@ -98,17 +102,18 @@ public class ExternalDetachedSignVerifyRoundTripTest extends AbstractExternalSOP
|
|||
assertSignedBy(verificationList, TestData.BOB_SIGNING_FINGERPRINT, TestData.BOB_PRIMARY_FINGERPRINT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void signVerifyWithCarolKey() throws IOException {
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void signVerifyWithCarolKey(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] signature = getSop().detachedSign()
|
||||
byte[] signature = sop.detachedSign()
|
||||
.key(TestData.CAROL_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.data(message)
|
||||
.toByteArrayAndResult()
|
||||
.getBytes();
|
||||
|
||||
List<Verification> verificationList = getSop().detachedVerify()
|
||||
List<Verification> verificationList = sop.detachedVerify()
|
||||
.cert(TestData.CAROL_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signatures(signature)
|
||||
.data(message);
|
||||
|
@ -117,11 +122,12 @@ public class ExternalDetachedSignVerifyRoundTripTest extends AbstractExternalSOP
|
|||
assertSignedBy(verificationList, TestData.CAROL_SIGNING_FINGERPRINT, TestData.CAROL_PRIMARY_FINGERPRINT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void signVerifyWithEncryptedKey() throws IOException {
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void signVerifyWithEncryptedKey(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] signature = getSop().detachedSign()
|
||||
byte[] signature = sop.detachedSign()
|
||||
.key(TestData.PASSWORD_PROTECTED_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.withKeyPassword(TestData.PASSWORD)
|
||||
.data(message)
|
||||
|
@ -130,7 +136,7 @@ public class ExternalDetachedSignVerifyRoundTripTest extends AbstractExternalSOP
|
|||
|
||||
assertArrayStartsWith(signature, BEGIN_PGP_SIGNATURE_BYTES);
|
||||
|
||||
List<Verification> verificationList = getSop().detachedVerify()
|
||||
List<Verification> verificationList = sop.detachedVerify()
|
||||
.cert(TestData.PASSWORD_PROTECTED_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signatures(signature)
|
||||
.data(message);
|
||||
|
@ -138,22 +144,23 @@ public class ExternalDetachedSignVerifyRoundTripTest extends AbstractExternalSOP
|
|||
assertFalse(verificationList.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void signArmorVerifyWithBobKey() throws IOException {
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void signArmorVerifyWithBobKey(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] signature = getSop().detachedSign()
|
||||
byte[] signature = sop.detachedSign()
|
||||
.key(TestData.BOB_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.noArmor()
|
||||
.data(message)
|
||||
.toByteArrayAndResult()
|
||||
.getBytes();
|
||||
|
||||
byte[] armored = getSop().armor()
|
||||
byte[] armored = sop.armor()
|
||||
.data(signature)
|
||||
.getBytes();
|
||||
|
||||
List<Verification> verificationList = getSop().detachedVerify()
|
||||
List<Verification> verificationList = sop.detachedVerify()
|
||||
.cert(TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signatures(armored)
|
||||
.data(message);
|
||||
|
@ -162,32 +169,30 @@ public class ExternalDetachedSignVerifyRoundTripTest extends AbstractExternalSOP
|
|||
assertSignedBy(verificationList, TestData.BOB_SIGNING_FINGERPRINT, TestData.BOB_PRIMARY_FINGERPRINT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyNotAfterThrowsNoSignature() {
|
||||
ignoreIf("sqop", Is.leq, "0.27.2"); // returns 1 instead of 3 (NO_SIGNATURE)
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void verifyNotAfterThrowsNoSignature(SOP sop) {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] signature = TestData.ALICE_DETACHED_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8);
|
||||
Date signatureDate = TestData.ALICE_DETACHED_SIGNED_MESSAGE_DATE;
|
||||
Date beforeSignature = new Date(signatureDate.getTime() - 1000); // 1 sec before sig
|
||||
|
||||
assertThrows(SOPGPException.NoSignature.class, () -> getSop().detachedVerify()
|
||||
assertThrows(SOPGPException.NoSignature.class, () -> sop.detachedVerify()
|
||||
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.notAfter(beforeSignature)
|
||||
.signatures(signature)
|
||||
.data(message));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyNotBeforeThrowsNoSignature() {
|
||||
ignoreIf("sqop", Is.leq, "0.27.2"); // returns 1 instead of 3 (NO_SIGNATURE)
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void verifyNotBeforeThrowsNoSignature(SOP sop) {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] signature = TestData.ALICE_DETACHED_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8);
|
||||
Date signatureDate = TestData.ALICE_DETACHED_SIGNED_MESSAGE_DATE;
|
||||
Date afterSignature = new Date(signatureDate.getTime() + 1000); // 1 sec after sig
|
||||
|
||||
assertThrows(SOPGPException.NoSignature.class, () -> getSop().detachedVerify()
|
||||
assertThrows(SOPGPException.NoSignature.class, () -> sop.detachedVerify()
|
||||
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.notBefore(afterSignature)
|
||||
.signatures(signature)
|
||||
|
@ -195,24 +200,24 @@ public class ExternalDetachedSignVerifyRoundTripTest extends AbstractExternalSOP
|
|||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void signVerifyWithEncryptedKeyWithoutPassphraseFails() {
|
||||
ignoreIf("sqop", Is.leq, "0.27.2"); // does not return exit code 67 for encrypted keys without passphrase
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void signVerifyWithEncryptedKeyWithoutPassphraseFails(SOP sop) {
|
||||
assertThrows(SOPGPException.KeyIsProtected.class, () ->
|
||||
getSop().detachedSign()
|
||||
sop.detachedSign()
|
||||
.key(TestData.PASSWORD_PROTECTED_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.data(TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8))
|
||||
.toByteArrayAndResult()
|
||||
.getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void signWithProtectedKeyAndMultiplePassphrasesTest()
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void signWithProtectedKeyAndMultiplePassphrasesTest(SOP sop)
|
||||
throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] signature = getSop().sign()
|
||||
byte[] signature = sop.sign()
|
||||
.key(TestData.PASSWORD_PROTECTED_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.withKeyPassword("wrong")
|
||||
.withKeyPassword(TestData.PASSWORD) // correct
|
||||
|
@ -221,22 +226,20 @@ public class ExternalDetachedSignVerifyRoundTripTest extends AbstractExternalSOP
|
|||
.toByteArrayAndResult()
|
||||
.getBytes();
|
||||
|
||||
assertFalse(getSop().verify()
|
||||
assertFalse(sop.verify()
|
||||
.cert(TestData.PASSWORD_PROTECTED_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signatures(signature)
|
||||
.data(message)
|
||||
.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyMissingCertCausesMissingArg() {
|
||||
ignoreIf("sqop", Is.leq, "0.27.3");
|
||||
ignoreIf("PGPainless-SOP", Is.geq, "0.0.0"); // PGPainless uses picocli which throws
|
||||
// UNSUPPORTED_OPTION for missing arg
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void verifyMissingCertCausesMissingArg(SOP sop) {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
assertThrows(SOPGPException.MissingArg.class, () ->
|
||||
getSop().verify()
|
||||
sop.verify()
|
||||
.signatures(TestData.ALICE_DETACHED_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8))
|
||||
.data(message));
|
||||
}
|
||||
|
|
|
@ -4,10 +4,11 @@
|
|||
|
||||
package sop.external;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import sop.ByteArrayAndResult;
|
||||
import sop.DecryptionResult;
|
||||
import sop.SOP;
|
||||
import sop.Verification;
|
||||
import sop.enums.EncryptAs;
|
||||
import sop.exception.SOPGPException;
|
||||
|
@ -25,18 +26,18 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@EnabledIf("sop.external.AbstractExternalSOPTest#isExternalSopInstalled")
|
||||
public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest {
|
||||
|
||||
@Test
|
||||
public void encryptDecryptRoundTripPasswordTest() throws IOException {
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void encryptDecryptRoundTripPasswordTest(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] ciphertext = getSop().encrypt()
|
||||
byte[] ciphertext = sop.encrypt()
|
||||
.withPassword("sw0rdf1sh")
|
||||
.plaintext(message)
|
||||
.getBytes();
|
||||
|
||||
byte[] plaintext = getSop().decrypt()
|
||||
byte[] plaintext = sop.decrypt()
|
||||
.withPassword("sw0rdf1sh")
|
||||
.ciphertext(ciphertext)
|
||||
.toByteArrayAndResult()
|
||||
|
@ -45,15 +46,16 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest
|
|||
assertArrayEquals(message, plaintext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void encryptDecryptRoundTripAliceTest() throws IOException {
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void encryptDecryptRoundTripAliceTest(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] ciphertext = getSop().encrypt()
|
||||
byte[] ciphertext = sop.encrypt()
|
||||
.withCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.plaintext(message)
|
||||
.getBytes();
|
||||
|
||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = getSop().decrypt()
|
||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
||||
.withKey(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.ciphertext(ciphertext)
|
||||
.toByteArrayAndResult();
|
||||
|
@ -65,15 +67,16 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest
|
|||
assertNotNull(result.getSessionKey().get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void encryptDecryptRoundTripBobTest() throws IOException {
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void encryptDecryptRoundTripBobTest(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] ciphertext = getSop().encrypt()
|
||||
byte[] ciphertext = sop.encrypt()
|
||||
.withCert(TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.plaintext(message)
|
||||
.getBytes();
|
||||
|
||||
byte[] plaintext = getSop().decrypt()
|
||||
byte[] plaintext = sop.decrypt()
|
||||
.withKey(TestData.BOB_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.ciphertext(ciphertext)
|
||||
.toByteArrayAndResult()
|
||||
|
@ -82,17 +85,16 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest
|
|||
assertArrayEquals(message, plaintext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void encryptDecryptRoundTripCarolTest() throws IOException {
|
||||
ignoreIf("sqop", Is.geq, "0.0.0"); // sqop reports cert not encryption capable
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void encryptDecryptRoundTripCarolTest(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] ciphertext = getSop().encrypt()
|
||||
byte[] ciphertext = sop.encrypt()
|
||||
.withCert(TestData.CAROL_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.plaintext(message)
|
||||
.getBytes();
|
||||
|
||||
byte[] plaintext = getSop().decrypt()
|
||||
byte[] plaintext = sop.decrypt()
|
||||
.withKey(TestData.CAROL_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.ciphertext(ciphertext)
|
||||
.toByteArrayAndResult()
|
||||
|
@ -101,22 +103,21 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest
|
|||
assertArrayEquals(message, plaintext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void encryptNoArmorThenArmorThenDecryptRoundTrip() throws IOException {
|
||||
ignoreIf("sqop", Is.leq, "0.26.1"); // Invalid data type
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void encryptNoArmorThenArmorThenDecryptRoundTrip(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] ciphertext = getSop().encrypt()
|
||||
byte[] ciphertext = sop.encrypt()
|
||||
.withCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.noArmor()
|
||||
.plaintext(message)
|
||||
.getBytes();
|
||||
|
||||
byte[] armored = getSop().armor()
|
||||
byte[] armored = sop.armor()
|
||||
.data(ciphertext)
|
||||
.getBytes();
|
||||
|
||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = getSop().decrypt()
|
||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
||||
.withKey(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.ciphertext(armored)
|
||||
.toByteArrayAndResult();
|
||||
|
@ -125,16 +126,17 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest
|
|||
assertArrayEquals(message, plaintext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void encryptSignDecryptVerifyRoundTripAliceTest() throws IOException {
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void encryptSignDecryptVerifyRoundTripAliceTest(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] ciphertext = getSop().encrypt()
|
||||
byte[] ciphertext = sop.encrypt()
|
||||
.withCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signWith(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.plaintext(message)
|
||||
.getBytes();
|
||||
|
||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = getSop().decrypt()
|
||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
||||
.withKey(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.verifyWithCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.ciphertext(ciphertext)
|
||||
|
@ -150,17 +152,18 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest
|
|||
assertTrue(verificationList.get(0).toString().contains("EB85BB5FA33A75E15E944E63F231550C4F47E38E EB85BB5FA33A75E15E944E63F231550C4F47E38E"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void encryptSignAsTextDecryptVerifyRoundTripAliceTest() throws IOException {
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void encryptSignAsTextDecryptVerifyRoundTripAliceTest(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] ciphertext = getSop().encrypt()
|
||||
byte[] ciphertext = sop.encrypt()
|
||||
.withCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signWith(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.mode(EncryptAs.Text)
|
||||
.plaintext(message)
|
||||
.getBytes();
|
||||
|
||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = getSop().decrypt()
|
||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
||||
.withKey(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.verifyWithCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.ciphertext(ciphertext)
|
||||
|
@ -176,29 +179,28 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest
|
|||
assertTrue(verificationList.get(0).toString().contains("EB85BB5FA33A75E15E944E63F231550C4F47E38E EB85BB5FA33A75E15E944E63F231550C4F47E38E"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void encryptSignDecryptVerifyRoundTripWithFreshEncryptedKeyTest() throws IOException {
|
||||
ignoreIf("sqop", Is.leq, "0.26.1");
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void encryptSignDecryptVerifyRoundTripWithFreshEncryptedKeyTest(SOP sop) throws IOException {
|
||||
byte[] keyPassword = "sw0rdf1sh".getBytes(StandardCharsets.UTF_8);
|
||||
byte[] key = getSop().generateKey()
|
||||
byte[] key = sop.generateKey()
|
||||
.withKeyPassword(keyPassword)
|
||||
.userId("Alice <alice@openpgp.org>")
|
||||
.generate()
|
||||
.getBytes();
|
||||
byte[] cert = getSop().extractCert()
|
||||
byte[] cert = sop.extractCert()
|
||||
.key(key)
|
||||
.getBytes();
|
||||
|
||||
byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8);
|
||||
byte[] ciphertext = getSop().encrypt()
|
||||
byte[] ciphertext = sop.encrypt()
|
||||
.withCert(cert)
|
||||
.signWith(key)
|
||||
.withKeyPassword(keyPassword)
|
||||
.plaintext(message)
|
||||
.getBytes();
|
||||
|
||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = getSop().decrypt()
|
||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
||||
.withKey(key)
|
||||
.withKeyPassword(keyPassword)
|
||||
.verifyWithCert(cert)
|
||||
|
@ -209,11 +211,9 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest
|
|||
assertArrayEquals(message, bytesAndResult.getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decryptVerifyNotAfterTest() {
|
||||
ignoreIf("PGPainless-SOP", Is.le, "1.4.2"); // does not recognize --verify-not-after
|
||||
ignoreIf("sqop", Is.leq, "0.27.2"); // does not throw NoSignature
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void decryptVerifyNotAfterTest(SOP sop) {
|
||||
byte[] message = ("-----BEGIN PGP MESSAGE-----\n" +
|
||||
"\n" +
|
||||
"wV4DR2b2udXyHrYSAQdAwlOwwyxFDJta5+H9abgSj8jum9v7etUc9usdrElESmow\n" +
|
||||
|
@ -231,7 +231,7 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest
|
|||
Date beforeSignature = new Date(signatureDate.getTime() - 1000); // 1 sec before signing date
|
||||
|
||||
assertThrows(SOPGPException.NoSignature.class, () -> {
|
||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = getSop().decrypt()
|
||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
||||
.withKey(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.verifyWithCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.verifyNotAfter(beforeSignature)
|
||||
|
@ -244,11 +244,9 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest
|
|||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decryptVerifyNotBeforeTest() {
|
||||
ignoreIf("PGPainless-SOP", Is.le, "1.4.2"); // does not recognize --verify-not-after
|
||||
ignoreIf("sqop", Is.leq, "0.27.2"); // does not throw NoSignature
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void decryptVerifyNotBeforeTest(SOP sop) {
|
||||
byte[] message = ("-----BEGIN PGP MESSAGE-----\n" +
|
||||
"\n" +
|
||||
"wV4DR2b2udXyHrYSAQdAwlOwwyxFDJta5+H9abgSj8jum9v7etUc9usdrElESmow\n" +
|
||||
|
@ -266,7 +264,7 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest
|
|||
Date afterSignature = new Date(signatureDate.getTime() + 1000); // 1 sec after signing date
|
||||
|
||||
assertThrows(SOPGPException.NoSignature.class, () -> {
|
||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = getSop().decrypt()
|
||||
ByteArrayAndResult<DecryptionResult> bytesAndResult = sop.decrypt()
|
||||
.withKey(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.verifyWithCert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.verifyNotBefore(afterSignature)
|
||||
|
@ -279,12 +277,12 @@ public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest
|
|||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void missingArgsTest() throws IOException {
|
||||
ignoreIf("sqop", Is.leq, "0.27.3");
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void missingArgsTest(SOP sop) {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
assertThrows(SOPGPException.MissingArg.class, () -> getSop().encrypt()
|
||||
assertThrows(SOPGPException.MissingArg.class, () -> sop.encrypt()
|
||||
.plaintext(message)
|
||||
.getBytes());
|
||||
}
|
||||
|
|
|
@ -4,8 +4,9 @@
|
|||
|
||||
package sop.external;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import sop.SOP;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -16,58 +17,59 @@ import static sop.external.JUtils.arrayStartsWith;
|
|||
import static sop.external.JUtils.assertArrayStartsWith;
|
||||
import static sop.external.JUtils.assertAsciiArmorEquals;
|
||||
|
||||
@EnabledIf("sop.external.AbstractExternalSOPTest#isExternalSopInstalled")
|
||||
public class ExternalExtractCertTest extends AbstractExternalSOPTest {
|
||||
|
||||
private static final String BEGIN_PGP_PUBLIC_KEY_BLOCK = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n";
|
||||
private static final byte[] BEGIN_PGP_PUBLIC_KEY_BLOCK_BYTES = BEGIN_PGP_PUBLIC_KEY_BLOCK.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
@Test
|
||||
public void extractArmoredCertFromArmoredKeyTest() throws IOException {
|
||||
InputStream keyIn = getSop().generateKey()
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void extractArmoredCertFromArmoredKeyTest(SOP sop) throws IOException {
|
||||
InputStream keyIn = sop.generateKey()
|
||||
.userId("Alice <alice@openpgp.org>")
|
||||
.generate()
|
||||
.getInputStream();
|
||||
|
||||
byte[] cert = getSop().extractCert().key(keyIn).getBytes();
|
||||
byte[] cert = sop.extractCert().key(keyIn).getBytes();
|
||||
assertArrayStartsWith(cert, BEGIN_PGP_PUBLIC_KEY_BLOCK_BYTES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractAliceCertFromAliceKeyTest() throws IOException {
|
||||
ignoreIf("PGPainless-SOP", Is.geq, "0.0.0"); // PGPainless uses old CTB
|
||||
byte[] armoredCert = getSop().extractCert()
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void extractAliceCertFromAliceKeyTest(SOP sop) throws IOException {
|
||||
byte[] armoredCert = sop.extractCert()
|
||||
.key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.getBytes();
|
||||
assertAsciiArmorEquals(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8), armoredCert);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractBobsCertFromBobsKeyTest() throws IOException {
|
||||
ignoreIf("PGPainless-SOP", Is.geq, "0.0.0"); // PGPainless uses old CTB
|
||||
byte[] armoredCert = getSop().extractCert()
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void extractBobsCertFromBobsKeyTest(SOP sop) throws IOException {
|
||||
byte[] armoredCert = sop.extractCert()
|
||||
.key(TestData.BOB_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.getBytes();
|
||||
assertAsciiArmorEquals(TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8), armoredCert);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractCarolsCertFromCarolsKeyTest() throws IOException {
|
||||
ignoreIf("PGPainless-SOP", Is.geq, "0.0.0"); // PGPainless uses old CTB
|
||||
byte[] armoredCert = getSop().extractCert()
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void extractCarolsCertFromCarolsKeyTest(SOP sop) throws IOException {
|
||||
byte[] armoredCert = sop.extractCert()
|
||||
.key(TestData.CAROL_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.getBytes();
|
||||
assertAsciiArmorEquals(TestData.CAROL_CERT.getBytes(StandardCharsets.UTF_8), armoredCert);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractUnarmoredCertFromArmoredKeyTest() throws IOException {
|
||||
InputStream keyIn = getSop().generateKey()
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void extractUnarmoredCertFromArmoredKeyTest(SOP sop) throws IOException {
|
||||
InputStream keyIn = sop.generateKey()
|
||||
.userId("Alice <alice@openpgp.org>")
|
||||
.generate()
|
||||
.getInputStream();
|
||||
|
||||
byte[] cert = getSop().extractCert()
|
||||
byte[] cert = sop.extractCert()
|
||||
.noArmor()
|
||||
.key(keyIn)
|
||||
.getBytes();
|
||||
|
@ -75,30 +77,32 @@ public class ExternalExtractCertTest extends AbstractExternalSOPTest {
|
|||
assertFalse(arrayStartsWith(cert, BEGIN_PGP_PUBLIC_KEY_BLOCK_BYTES));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractArmoredCertFromUnarmoredKeyTest() throws IOException {
|
||||
InputStream keyIn = getSop().generateKey()
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void extractArmoredCertFromUnarmoredKeyTest(SOP sop) throws IOException {
|
||||
InputStream keyIn = sop.generateKey()
|
||||
.userId("Alice <alice@openpgp.org>")
|
||||
.noArmor()
|
||||
.generate()
|
||||
.getInputStream();
|
||||
|
||||
byte[] cert = getSop().extractCert()
|
||||
byte[] cert = sop.extractCert()
|
||||
.key(keyIn)
|
||||
.getBytes();
|
||||
|
||||
assertArrayStartsWith(cert, BEGIN_PGP_PUBLIC_KEY_BLOCK_BYTES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractUnarmoredCertFromUnarmoredKeyTest() throws IOException {
|
||||
InputStream keyIn = getSop().generateKey()
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void extractUnarmoredCertFromUnarmoredKeyTest(SOP sop) throws IOException {
|
||||
InputStream keyIn = sop.generateKey()
|
||||
.noArmor()
|
||||
.userId("Alice <alice@openpgp.org>")
|
||||
.generate()
|
||||
.getInputStream();
|
||||
|
||||
byte[] cert = getSop().extractCert()
|
||||
byte[] cert = sop.extractCert()
|
||||
.noArmor()
|
||||
.key(keyIn)
|
||||
.getBytes();
|
||||
|
|
|
@ -4,8 +4,9 @@
|
|||
|
||||
package sop.external;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import sop.SOP;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
|
@ -14,16 +15,16 @@ import java.nio.charset.StandardCharsets;
|
|||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static sop.external.JUtils.assertArrayStartsWith;
|
||||
|
||||
@EnabledIf("sop.external.AbstractExternalSOPTest#isExternalSopInstalled")
|
||||
public class ExternalGenerateKeyTest extends AbstractExternalSOPTest {
|
||||
|
||||
private static final Charset UTF8 = StandardCharsets.UTF_8;
|
||||
private static final String BEGIN_PGP_PRIVATE_KEY_BLOCK = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n";
|
||||
byte[] BEGIN_PGP_PRIVATE_KEY_BLOCK_BYTES = BEGIN_PGP_PRIVATE_KEY_BLOCK.getBytes(UTF8);
|
||||
|
||||
@Test
|
||||
public void generateKeyTest() throws IOException {
|
||||
byte[] key = getSop().generateKey()
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void generateKeyTest(SOP sop) throws IOException {
|
||||
byte[] key = sop.generateKey()
|
||||
.userId("Alice <alice@openpgp.org>")
|
||||
.generate()
|
||||
.getBytes();
|
||||
|
@ -31,9 +32,10 @@ public class ExternalGenerateKeyTest extends AbstractExternalSOPTest {
|
|||
assertArrayStartsWith(key, BEGIN_PGP_PRIVATE_KEY_BLOCK_BYTES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateKeyNoArmor() throws IOException {
|
||||
byte[] key = getSop().generateKey()
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void generateKeyNoArmor(SOP sop) throws IOException {
|
||||
byte[] key = sop.generateKey()
|
||||
.userId("Alice <alice@openpgp.org>")
|
||||
.noArmor()
|
||||
.generate()
|
||||
|
@ -42,9 +44,10 @@ public class ExternalGenerateKeyTest extends AbstractExternalSOPTest {
|
|||
assertFalse(JUtils.arrayStartsWith(key, BEGIN_PGP_PRIVATE_KEY_BLOCK_BYTES));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateKeyWithMultipleUserIdsTest() throws IOException {
|
||||
byte[] key = getSop().generateKey()
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void generateKeyWithMultipleUserIdsTest(SOP sop) throws IOException {
|
||||
byte[] key = sop.generateKey()
|
||||
.userId("Alice <alice@openpgp.org>")
|
||||
.userId("Bob <bob@openpgp.org>")
|
||||
.generate()
|
||||
|
@ -53,23 +56,20 @@ public class ExternalGenerateKeyTest extends AbstractExternalSOPTest {
|
|||
assertArrayStartsWith(key, BEGIN_PGP_PRIVATE_KEY_BLOCK_BYTES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateKeyWithoutUserIdTest() throws IOException {
|
||||
ignoreIf("pgpainless-cli", Is.le, "1.3.15");
|
||||
|
||||
byte[] key = getSop().generateKey()
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void generateKeyWithoutUserIdTest(SOP sop) throws IOException {
|
||||
byte[] key = sop.generateKey()
|
||||
.generate()
|
||||
.getBytes();
|
||||
|
||||
assertArrayStartsWith(key, BEGIN_PGP_PRIVATE_KEY_BLOCK_BYTES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateKeyWithPasswordTest() throws IOException {
|
||||
ignoreIf("sqop", Is.le, "0.27.0");
|
||||
ignoreIf("pgpainless-cli", Is.le, "1.3.0");
|
||||
|
||||
byte[] key = getSop().generateKey()
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void generateKeyWithPasswordTest(SOP sop) throws IOException {
|
||||
byte[] key = sop.generateKey()
|
||||
.userId("Alice <alice@openpgp.org>")
|
||||
.withKeyPassword("sw0rdf1sh")
|
||||
.generate()
|
||||
|
@ -78,14 +78,10 @@ public class ExternalGenerateKeyTest extends AbstractExternalSOPTest {
|
|||
assertArrayStartsWith(key, BEGIN_PGP_PRIVATE_KEY_BLOCK_BYTES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateKeyWithMultipleUserIdsAndPassword() throws IOException {
|
||||
ignoreIf("sqop", Is.le, "0.27.0");
|
||||
ignoreIf("PGPainless-SOP", Is.le, "1.3.15");
|
||||
ignoreIf("PGPainless-SOP", Is.eq, "1.4.0");
|
||||
ignoreIf("PGPainless-SOP", Is.eq, "1.4.1");
|
||||
|
||||
byte[] key = getSop().generateKey()
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void generateKeyWithMultipleUserIdsAndPassword(SOP sop) throws IOException {
|
||||
byte[] key = sop.generateKey()
|
||||
.userId("Alice <alice@openpgp.org>")
|
||||
.userId("Bob <bob@openpgp.org>")
|
||||
.withKeyPassword("sw0rdf1sh")
|
||||
|
|
|
@ -4,9 +4,10 @@
|
|||
|
||||
package sop.external;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import sop.ByteArrayAndResult;
|
||||
import sop.SOP;
|
||||
import sop.Signatures;
|
||||
import sop.Verification;
|
||||
|
||||
|
@ -19,23 +20,21 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
|
|||
import static sop.external.JUtils.arrayStartsWith;
|
||||
import static sop.external.JUtils.assertArrayStartsWith;
|
||||
|
||||
@EnabledIf("sop.external.AbstractExternalSOPTest#isExternalSopInstalled")
|
||||
public class ExternalInlineSignDetachVerifyRoundTripTest extends AbstractExternalSOPTest {
|
||||
|
||||
private static final byte[] BEGIN_PGP_SIGNATURE = "-----BEGIN PGP SIGNATURE-----\n".getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
@Test
|
||||
public void inlineSignThenDetachThenDetachedVerifyTest() throws IOException {
|
||||
ignoreIf("sqop", Is.leq, "0.26.1"); // inline-sign not supported
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void inlineSignThenDetachThenDetachedVerifyTest(SOP sop) throws IOException {
|
||||
byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] inlineSigned = getSop().inlineSign()
|
||||
byte[] inlineSigned = sop.inlineSign()
|
||||
.key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.data(message)
|
||||
.getBytes();
|
||||
|
||||
ByteArrayAndResult<Signatures> bytesAndResult = getSop().inlineDetach()
|
||||
ByteArrayAndResult<Signatures> bytesAndResult = sop.inlineDetach()
|
||||
.message(inlineSigned)
|
||||
.toByteArrayAndResult();
|
||||
|
||||
|
@ -45,7 +44,7 @@ public class ExternalInlineSignDetachVerifyRoundTripTest extends AbstractExterna
|
|||
byte[] signatures = bytesAndResult.getResult()
|
||||
.getBytes();
|
||||
|
||||
List<Verification> verifications = getSop().detachedVerify()
|
||||
List<Verification> verifications = sop.detachedVerify()
|
||||
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signatures(signatures)
|
||||
.data(plaintext);
|
||||
|
@ -53,18 +52,17 @@ public class ExternalInlineSignDetachVerifyRoundTripTest extends AbstractExterna
|
|||
assertFalse(verifications.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inlineSignThenDetachNoArmorThenArmorThenDetachedVerifyTest() throws IOException {
|
||||
ignoreIf("sqop", Is.leq, "0.26.1"); // inline-sign not supported
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void inlineSignThenDetachNoArmorThenArmorThenDetachedVerifyTest(SOP sop) throws IOException {
|
||||
byte[] message = "Hello, World!\n".getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] inlineSigned = getSop().inlineSign()
|
||||
byte[] inlineSigned = sop.inlineSign()
|
||||
.key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.data(message)
|
||||
.getBytes();
|
||||
|
||||
ByteArrayAndResult<Signatures> bytesAndResult = getSop().inlineDetach()
|
||||
ByteArrayAndResult<Signatures> bytesAndResult = sop.inlineDetach()
|
||||
.noArmor()
|
||||
.message(inlineSigned)
|
||||
.toByteArrayAndResult();
|
||||
|
@ -76,12 +74,12 @@ public class ExternalInlineSignDetachVerifyRoundTripTest extends AbstractExterna
|
|||
.getBytes();
|
||||
assertFalse(arrayStartsWith(signatures, BEGIN_PGP_SIGNATURE));
|
||||
|
||||
byte[] armored = getSop().armor()
|
||||
byte[] armored = sop.armor()
|
||||
.data(signatures)
|
||||
.getBytes();
|
||||
assertArrayStartsWith(armored, BEGIN_PGP_SIGNATURE);
|
||||
|
||||
List<Verification> verifications = getSop().detachedVerify()
|
||||
List<Verification> verifications = sop.detachedVerify()
|
||||
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.signatures(armored)
|
||||
.data(plaintext);
|
||||
|
|
|
@ -4,9 +4,10 @@
|
|||
|
||||
package sop.external;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import sop.ByteArrayAndResult;
|
||||
import sop.SOP;
|
||||
import sop.Verification;
|
||||
import sop.enums.InlineSignAs;
|
||||
import sop.exception.SOPGPException;
|
||||
|
@ -21,7 +22,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
|
|||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static sop.external.JUtils.assertSignedBy;
|
||||
|
||||
@EnabledIf("sop.external.AbstractExternalSOPTest#isExternalSopInstalled")
|
||||
public class ExternalInlineSignVerifyTest extends AbstractExternalSOPTest {
|
||||
|
||||
private static final String BEGIN_PGP_MESSAGE = "-----BEGIN PGP MESSAGE-----\n";
|
||||
|
@ -29,20 +29,19 @@ public class ExternalInlineSignVerifyTest extends AbstractExternalSOPTest {
|
|||
private static final String BEGIN_PGP_SIGNED_MESSAGE = "-----BEGIN PGP SIGNED MESSAGE-----\n";
|
||||
private static final byte[] BEGIN_PGP_SIGNED_MESSAGE_BYTES = BEGIN_PGP_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
@Test
|
||||
public void inlineSignVerifyAlice() throws IOException {
|
||||
ignoreIf("sqop", Is.leq, "0.26.1"); // inline-sign not supported
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void inlineSignVerifyAlice(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] inlineSigned = getSop().inlineSign()
|
||||
byte[] inlineSigned = sop.inlineSign()
|
||||
.key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.data(message)
|
||||
.getBytes();
|
||||
|
||||
JUtils.assertArrayStartsWith(inlineSigned, BEGIN_PGP_MESSAGE_BYTES);
|
||||
|
||||
ByteArrayAndResult<List<Verification>> bytesAndResult = getSop().inlineVerify()
|
||||
ByteArrayAndResult<List<Verification>> bytesAndResult = sop.inlineVerify()
|
||||
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.data(inlineSigned)
|
||||
.toByteArrayAndResult();
|
||||
|
@ -52,13 +51,12 @@ public class ExternalInlineSignVerifyTest extends AbstractExternalSOPTest {
|
|||
assertSignedBy(verificationList, TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inlineSignVerifyAliceNoArmor() throws IOException {
|
||||
ignoreIf("sqop", Is.leq, "0.26.1"); // inline-sign not supported
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void inlineSignVerifyAliceNoArmor(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] inlineSigned = getSop().inlineSign()
|
||||
byte[] inlineSigned = sop.inlineSign()
|
||||
.key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.noArmor()
|
||||
.data(message)
|
||||
|
@ -66,7 +64,7 @@ public class ExternalInlineSignVerifyTest extends AbstractExternalSOPTest {
|
|||
|
||||
assertFalse(JUtils.arrayStartsWith(inlineSigned, BEGIN_PGP_MESSAGE_BYTES));
|
||||
|
||||
ByteArrayAndResult<List<Verification>> bytesAndResult = getSop().inlineVerify()
|
||||
ByteArrayAndResult<List<Verification>> bytesAndResult = sop.inlineVerify()
|
||||
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.data(inlineSigned)
|
||||
.toByteArrayAndResult();
|
||||
|
@ -76,13 +74,12 @@ public class ExternalInlineSignVerifyTest extends AbstractExternalSOPTest {
|
|||
assertSignedBy(verificationList, TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearsignVerifyAlice() throws IOException {
|
||||
ignoreIf("sqop", Is.leq, "0.26.1"); // inline-sign not supported
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void clearsignVerifyAlice(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] clearsigned = getSop().inlineSign()
|
||||
byte[] clearsigned = sop.inlineSign()
|
||||
.key(TestData.ALICE_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.mode(InlineSignAs.clearsigned)
|
||||
.data(message)
|
||||
|
@ -90,7 +87,7 @@ public class ExternalInlineSignVerifyTest extends AbstractExternalSOPTest {
|
|||
|
||||
JUtils.assertArrayStartsWith(clearsigned, BEGIN_PGP_SIGNED_MESSAGE_BYTES);
|
||||
|
||||
ByteArrayAndResult<List<Verification>> bytesAndResult = getSop().inlineVerify()
|
||||
ByteArrayAndResult<List<Verification>> bytesAndResult = sop.inlineVerify()
|
||||
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.data(clearsigned)
|
||||
.toByteArrayAndResult();
|
||||
|
@ -100,15 +97,13 @@ public class ExternalInlineSignVerifyTest extends AbstractExternalSOPTest {
|
|||
assertSignedBy(verificationList, TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inlineVerifyCompareSignatureDate() throws IOException {
|
||||
ignoreIf("sqop", Is.leq, "0.26.1"); // inline-sign not supported
|
||||
ignoreIf("sqop", Is.leq, "0.27.2"); // returns 1 instead of 3 (NO_SIGNATURE)
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void inlineVerifyCompareSignatureDate(SOP sop) throws IOException {
|
||||
byte[] message = TestData.ALICE_INLINE_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8);
|
||||
Date signatureDate = TestData.ALICE_INLINE_SIGNED_MESSAGE_DATE;
|
||||
|
||||
ByteArrayAndResult<List<Verification>> bytesAndResult = getSop().inlineVerify()
|
||||
ByteArrayAndResult<List<Verification>> bytesAndResult = sop.inlineVerify()
|
||||
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.data(message)
|
||||
.toByteArrayAndResult();
|
||||
|
@ -116,52 +111,47 @@ public class ExternalInlineSignVerifyTest extends AbstractExternalSOPTest {
|
|||
assertSignedBy(verificationList, TestData.ALICE_SIGNING_FINGERPRINT, TestData.ALICE_PRIMARY_FINGERPRINT, signatureDate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertNotBeforeThrowsNoSignature() {
|
||||
ignoreIf("sqop", Is.leq, "0.26.1"); // inline-sign not supported
|
||||
ignoreIf("sqop", Is.leq, "0.27.2"); // returns 1 instead of 3 (NO_SIGNATURE)
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void assertNotBeforeThrowsNoSignature(SOP sop) {
|
||||
byte[] message = TestData.ALICE_INLINE_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8);
|
||||
Date signatureDate = TestData.ALICE_INLINE_SIGNED_MESSAGE_DATE;
|
||||
Date afterSignature = new Date(signatureDate.getTime() + 1000); // 1 sec before sig
|
||||
|
||||
assertThrows(SOPGPException.NoSignature.class, () -> getSop().inlineVerify()
|
||||
assertThrows(SOPGPException.NoSignature.class, () -> sop.inlineVerify()
|
||||
.notBefore(afterSignature)
|
||||
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.data(message)
|
||||
.toByteArrayAndResult());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertNotAfterThrowsNoSignature() {
|
||||
ignoreIf("sqop", Is.leq, "0.26.1"); // inline-sign not supported
|
||||
ignoreIf("sqop", Is.leq, "0.27.2"); // returns 1 instead of 3 (NO_SIGNATURE)
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void assertNotAfterThrowsNoSignature(SOP sop) {
|
||||
byte[] message = TestData.ALICE_INLINE_SIGNED_MESSAGE.getBytes(StandardCharsets.UTF_8);
|
||||
Date signatureDate = TestData.ALICE_INLINE_SIGNED_MESSAGE_DATE;
|
||||
Date beforeSignature = new Date(signatureDate.getTime() - 1000); // 1 sec before sig
|
||||
|
||||
assertThrows(SOPGPException.NoSignature.class, () -> getSop().inlineVerify()
|
||||
assertThrows(SOPGPException.NoSignature.class, () -> sop.inlineVerify()
|
||||
.notAfter(beforeSignature)
|
||||
.cert(TestData.ALICE_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.data(message)
|
||||
.toByteArrayAndResult());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inlineSignVerifyBob() throws IOException {
|
||||
ignoreIf("sqop", Is.leq, "0.26.1"); // inline-sign not supported
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void inlineSignVerifyBob(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] inlineSigned = getSop().inlineSign()
|
||||
byte[] inlineSigned = sop.inlineSign()
|
||||
.key(TestData.BOB_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.data(message)
|
||||
.getBytes();
|
||||
|
||||
JUtils.assertArrayStartsWith(inlineSigned, BEGIN_PGP_MESSAGE_BYTES);
|
||||
|
||||
ByteArrayAndResult<List<Verification>> bytesAndResult = getSop().inlineVerify()
|
||||
ByteArrayAndResult<List<Verification>> bytesAndResult = sop.inlineVerify()
|
||||
.cert(TestData.BOB_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.data(inlineSigned)
|
||||
.toByteArrayAndResult();
|
||||
|
@ -171,20 +161,19 @@ public class ExternalInlineSignVerifyTest extends AbstractExternalSOPTest {
|
|||
assertSignedBy(verificationList, TestData.BOB_SIGNING_FINGERPRINT, TestData.BOB_PRIMARY_FINGERPRINT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inlineSignVerifyCarol() throws IOException {
|
||||
ignoreIf("sqop", Is.leq, "0.26.1"); // inline-sign not supported
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void inlineSignVerifyCarol(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] inlineSigned = getSop().inlineSign()
|
||||
byte[] inlineSigned = sop.inlineSign()
|
||||
.key(TestData.CAROL_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.data(message)
|
||||
.getBytes();
|
||||
|
||||
JUtils.assertArrayStartsWith(inlineSigned, BEGIN_PGP_MESSAGE_BYTES);
|
||||
|
||||
ByteArrayAndResult<List<Verification>> bytesAndResult = getSop().inlineVerify()
|
||||
ByteArrayAndResult<List<Verification>> bytesAndResult = sop.inlineVerify()
|
||||
.cert(TestData.CAROL_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.data(inlineSigned)
|
||||
.toByteArrayAndResult();
|
||||
|
@ -194,20 +183,19 @@ public class ExternalInlineSignVerifyTest extends AbstractExternalSOPTest {
|
|||
assertSignedBy(verificationList, TestData.CAROL_SIGNING_FINGERPRINT, TestData.CAROL_PRIMARY_FINGERPRINT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inlineSignVerifyProtectedKey() throws IOException {
|
||||
ignoreIf("sqop", Is.leq, "0.26.1"); // inline-sign not supported
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void inlineSignVerifyProtectedKey(SOP sop) throws IOException {
|
||||
byte[] message = TestData.PLAINTEXT.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] inlineSigned = getSop().inlineSign()
|
||||
byte[] inlineSigned = sop.inlineSign()
|
||||
.withKeyPassword(TestData.PASSWORD)
|
||||
.key(TestData.PASSWORD_PROTECTED_KEY.getBytes(StandardCharsets.UTF_8))
|
||||
.mode(InlineSignAs.binary)
|
||||
.data(message)
|
||||
.getBytes();
|
||||
|
||||
ByteArrayAndResult<List<Verification>> bytesAndResult = getSop().inlineVerify()
|
||||
ByteArrayAndResult<List<Verification>> bytesAndResult = sop.inlineVerify()
|
||||
.cert(TestData.PASSWORD_PROTECTED_CERT.getBytes(StandardCharsets.UTF_8))
|
||||
.data(inlineSigned)
|
||||
.toByteArrayAndResult();
|
||||
|
|
|
@ -4,38 +4,42 @@
|
|||
|
||||
package sop.external;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import sop.SOP;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@EnabledIf("sop.external.AbstractExternalSOPTest#isExternalSopInstalled")
|
||||
public class ExternalVersionTest extends AbstractExternalSOPTest {
|
||||
|
||||
@Test
|
||||
public void versionNameTest() {
|
||||
String name = getSop().version().getName();
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void versionNameTest(SOP sop) {
|
||||
String name = sop.version().getName();
|
||||
assertNotNull(name);
|
||||
assertFalse(name.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void versionVersionTest() {
|
||||
String version = getSop().version().getVersion();
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void versionVersionTest(SOP sop) {
|
||||
String version = sop.version().getVersion();
|
||||
assertTrue(version.matches("\\d+(\\.\\d+)*\\S*"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void backendVersionTest() {
|
||||
String backend = getSop().version().getBackendVersion();
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void backendVersionTest(SOP sop) {
|
||||
String backend = sop.version().getBackendVersion();
|
||||
assertFalse(backend.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extendedVersionTest() {
|
||||
String extended = getSop().version().getExtendedVersion();
|
||||
@ParameterizedTest
|
||||
@MethodSource("sop.external.AbstractExternalSOPTest#provideBackends")
|
||||
public void extendedVersionTest(SOP sop) {
|
||||
String extended = sop.version().getExtendedVersion();
|
||||
assertFalse(extended.isEmpty());
|
||||
}
|
||||
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.external;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import sop.exception.SOPGPException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
@EnabledIf("sop.external.AbstractExternalSOPTest#isExternalSopInstalled")
|
||||
public class UnsupportedSubcommandTest extends AbstractExternalSOPTest {
|
||||
|
||||
private final UnsupportedSubcommandExternal unsupportedSubcommand;
|
||||
|
||||
public UnsupportedSubcommandTest() {
|
||||
String backend = readSopBackendFromProperties();
|
||||
assumeTrue(backend != null);
|
||||
Properties environment = readBackendEnvironment();
|
||||
unsupportedSubcommand = new UnsupportedSubcommandExternal(backend, environment);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsupportedSubcommand() {
|
||||
// "sop unsupported" returns error code UNSUPPORTED_SUBCOMMAND
|
||||
assertThrows(SOPGPException.UnsupportedSubcommand.class,
|
||||
unsupportedSubcommand::executeUnsupportedSubcommand);
|
||||
}
|
||||
|
||||
private static class UnsupportedSubcommandExternal {
|
||||
|
||||
private final Runtime runtime = Runtime.getRuntime();
|
||||
private final String binary;
|
||||
private final Properties environment;
|
||||
|
||||
UnsupportedSubcommandExternal(String binaryName, Properties environment) {
|
||||
this.binary = binaryName;
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
public void executeUnsupportedSubcommand() {
|
||||
String[] command = new String[] {binary, "unsupported"}; // ~$ sop unsupported
|
||||
String[] env = ExternalSOP.propertiesToEnv(environment).toArray(new String[0]);
|
||||
try {
|
||||
Process process = runtime.exec(command, env);
|
||||
ExternalSOP.finish(process);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue