mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2024-11-21 23:02:05 +01:00
Rename module to external-sop and make backend in tests configurable
This commit is contained in:
parent
28912618ea
commit
e602cc16cc
12 changed files with 80 additions and 30 deletions
|
@ -17,6 +17,9 @@ dependencies {
|
|||
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
|
||||
|
||||
api project(":sop-java")
|
||||
|
||||
api "org.slf4j:slf4j-api:$slf4jVersion"
|
||||
testImplementation "ch.qos.logback:logback-classic:$logbackVersion"
|
||||
}
|
||||
|
||||
test {
|
|
@ -2,12 +2,12 @@
|
|||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.binary;
|
||||
package sop.external;
|
||||
|
||||
import sop.SOP;
|
||||
import sop.binary.operation.BinaryExtractCert;
|
||||
import sop.binary.operation.BinaryGenerateKey;
|
||||
import sop.binary.operation.BinaryVersion;
|
||||
import sop.external.operation.ExtractCertExternal;
|
||||
import sop.external.operation.GenerateKeyExternal;
|
||||
import sop.external.operation.VersionExternal;
|
||||
import sop.operation.Armor;
|
||||
import sop.operation.Dearmor;
|
||||
import sop.operation.Decrypt;
|
||||
|
@ -21,27 +21,27 @@ import sop.operation.InlineSign;
|
|||
import sop.operation.InlineVerify;
|
||||
import sop.operation.Version;
|
||||
|
||||
public class BinarySop implements SOP {
|
||||
public class ExternalSOP implements SOP {
|
||||
|
||||
private final String binaryName;
|
||||
|
||||
public BinarySop(String binaryName) {
|
||||
public ExternalSOP(String binaryName) {
|
||||
this.binaryName = binaryName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version version() {
|
||||
return new BinaryVersion(binaryName);
|
||||
return new VersionExternal(binaryName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenerateKey generateKey() {
|
||||
return new BinaryGenerateKey(binaryName);
|
||||
return new GenerateKeyExternal(binaryName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExtractCert extractCert() {
|
||||
return new BinaryExtractCert(binaryName);
|
||||
return new ExtractCertExternal(binaryName);
|
||||
}
|
||||
|
||||
@Override
|
|
@ -2,7 +2,7 @@
|
|||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.binary.operation;
|
||||
package sop.external.operation;
|
||||
|
||||
import sop.Ready;
|
||||
import sop.exception.SOPGPException;
|
||||
|
@ -14,14 +14,14 @@ import java.io.OutputStream;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BinaryExtractCert implements ExtractCert {
|
||||
public class ExtractCertExternal implements ExtractCert {
|
||||
|
||||
private final String binary;
|
||||
private final Runtime runtime = Runtime.getRuntime();
|
||||
|
||||
private boolean noArmor;
|
||||
|
||||
public BinaryExtractCert(String binary) {
|
||||
public ExtractCertExternal(String binary) {
|
||||
this.binary = binary;
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.binary.operation;
|
||||
package sop.external.operation;
|
||||
|
||||
import sop.Ready;
|
||||
import sop.exception.SOPGPException;
|
||||
|
@ -14,7 +14,7 @@ import java.io.OutputStream;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BinaryGenerateKey implements GenerateKey {
|
||||
public class GenerateKeyExternal implements GenerateKey {
|
||||
|
||||
private final String binary;
|
||||
private boolean noArmor = false;
|
||||
|
@ -23,7 +23,7 @@ public class BinaryGenerateKey implements GenerateKey {
|
|||
|
||||
private final Runtime runtime = Runtime.getRuntime();
|
||||
|
||||
public BinaryGenerateKey(String binary) {
|
||||
public GenerateKeyExternal(String binary) {
|
||||
this.binary = binary;
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.binary.operation;
|
||||
package sop.external.operation;
|
||||
|
||||
import sop.operation.Version;
|
||||
|
||||
|
@ -10,12 +10,12 @@ import java.io.BufferedReader;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
public class BinaryVersion implements Version {
|
||||
public class VersionExternal implements Version {
|
||||
|
||||
private final Runtime runtime = Runtime.getRuntime();
|
||||
private final String binary;
|
||||
|
||||
public BinaryVersion(String binaryName) {
|
||||
public VersionExternal(String binaryName) {
|
||||
this.binary = binaryName;
|
||||
}
|
||||
|
|
@ -5,4 +5,4 @@
|
|||
/**
|
||||
* Bindings for SOP subcommands to a SOP binary.
|
||||
*/
|
||||
package sop.binary.operation;
|
||||
package sop.external.operation;
|
|
@ -5,4 +5,4 @@
|
|||
/**
|
||||
* Implementation of sop-java which delegates execution to a binary implementing the SOP command line interface.
|
||||
*/
|
||||
package sop.binary;
|
||||
package sop.external;
|
5
external-sop/src/main/resources/sop/external/.gitignore
vendored
Normal file
5
external-sop/src/main/resources/sop/external/.gitignore
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
# SPDX-FileCopyrightText: 2023 Paul Schaub <info@pgpainless.org>
|
||||
#
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
backend.local.properties
|
7
external-sop/src/main/resources/sop/external/backend.properties
vendored
Normal file
7
external-sop/src/main/resources/sop/external/backend.properties
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
# 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
|
|
@ -2,30 +2,63 @@
|
|||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.binary;
|
||||
package sop.external;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import sop.SOP;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@EnabledIf("sop.binary.BinarySopTest#sopBinaryInstalled")
|
||||
public class BinarySopTest {
|
||||
@EnabledIf("sop.external.ExternalSOPTest#externalSopInstalled")
|
||||
public class ExternalSOPTest {
|
||||
|
||||
private static final String BINARY = "/usr/bin/sqop";
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ExternalSOPTest.class);
|
||||
|
||||
private final SOP sop = new BinarySop(BINARY);
|
||||
private final SOP sop;
|
||||
|
||||
public static boolean sopBinaryInstalled() {
|
||||
return new File(BINARY).exists();
|
||||
public ExternalSOPTest() {
|
||||
String backend = readSopBackendFromProperties();
|
||||
sop = new ExternalSOP(backend);
|
||||
}
|
||||
|
||||
private static String readSopBackendFromProperties() {
|
||||
Properties properties = new Properties();
|
||||
try {
|
||||
InputStream resourceIn = ExternalSOPTest.class.getResourceAsStream("backend.local.properties");
|
||||
if (resourceIn == null) {
|
||||
LOGGER.info("Could not find backend.local.properties file. Try backend.properties instead.");
|
||||
resourceIn = ExternalSOPTest.class.getResourceAsStream("backend.properties");
|
||||
}
|
||||
if (resourceIn == null) {
|
||||
throw new FileNotFoundException("Could not find backend.properties file.");
|
||||
}
|
||||
|
||||
properties.load(resourceIn);
|
||||
String backend = properties.getProperty("sop.backend");
|
||||
return backend;
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean externalSopInstalled() {
|
||||
String binary = readSopBackendFromProperties();
|
||||
if (binary == null) {
|
||||
return false;
|
||||
}
|
||||
return new File(binary).exists();
|
||||
}
|
||||
|
||||
@Test
|
|
@ -6,5 +6,5 @@ rootProject.name = 'SOP-Java'
|
|||
|
||||
include 'sop-java',
|
||||
'sop-java-picocli',
|
||||
'binary-sop'
|
||||
'external-sop'
|
||||
|
||||
|
|
|
@ -8,10 +8,12 @@ allprojects {
|
|||
isSnapshot = true
|
||||
minAndroidSdk = 10
|
||||
javaSourceCompatibility = 1.8
|
||||
jsrVersion = '3.0.2'
|
||||
junitVersion = '5.8.2'
|
||||
junitSysExitVersion = '1.1.2'
|
||||
picocliVersion = '4.6.3'
|
||||
logbackVersion = '1.2.11'
|
||||
mockitoVersion = '4.5.1'
|
||||
jsrVersion = '3.0.2'
|
||||
picocliVersion = '4.6.3'
|
||||
slf4jVersion = '1.7.36'
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue