mirror of
https://codeberg.org/PGPainless/wkd-java.git
synced 2025-09-09 03:09:39 +02:00
Refactoring and dynamic test suite
This commit is contained in:
parent
38ef283313
commit
3af16baa20
23 changed files with 287 additions and 162 deletions
|
@ -10,6 +10,7 @@ group 'org.pgpainless'
|
|||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
@ -20,7 +21,7 @@ dependencies {
|
|||
testImplementation 'com.ginsberg:junit5-system-exit:1.1.2'
|
||||
testImplementation 'org.mockito:mockito-core:4.3.1'
|
||||
|
||||
implementation("org.pgpainless:pgpainless-cert-d:0.1.0")
|
||||
implementation("org.pgpainless:pgpainless-cert-d:0.1.1")
|
||||
implementation project(':wkd-java')
|
||||
implementation "info.picocli:picocli:4.6.3"
|
||||
|
||||
|
|
|
@ -12,14 +12,14 @@ import org.pgpainless.certificate_store.CertificateFactory;
|
|||
import org.pgpainless.key.info.KeyRingInfo;
|
||||
import pgp.certificate_store.Certificate;
|
||||
import pgp.wkd.CertificateAndUserIds;
|
||||
import pgp.wkd.CertificateReader;
|
||||
import pgp.wkd.discovery.CertificateParser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CertificateReaderImpl implements CertificateReader {
|
||||
public class CertificateParserImpl implements CertificateParser {
|
||||
@Override
|
||||
public List<CertificateAndUserIds> read(InputStream inputStream) throws IOException {
|
||||
List<CertificateAndUserIds> certificatesAndUserIds = new ArrayList<>();
|
|
@ -1,21 +1,21 @@
|
|||
package pgp.wkd.cli;
|
||||
|
||||
import pgp.wkd.AbstractDiscover;
|
||||
import pgp.wkd.CertificateReader;
|
||||
import pgp.wkd.HttpUrlConnectionWKDFetcher;
|
||||
import pgp.wkd.WKDFetcher;
|
||||
import pgp.wkd.discovery.CertificateDiscoveryImplementation;
|
||||
import pgp.wkd.discovery.CertificateParser;
|
||||
import pgp.wkd.discovery.HttpUrlConnectionCertificateFetcher;
|
||||
import pgp.wkd.discovery.CertificateFetcher;
|
||||
|
||||
public class DiscoverImpl extends AbstractDiscover {
|
||||
public class DiscoverImpl extends CertificateDiscoveryImplementation {
|
||||
|
||||
public DiscoverImpl() {
|
||||
super(new CertificateReaderImpl(), new HttpUrlConnectionWKDFetcher());
|
||||
super(new CertificateParserImpl(), new HttpUrlConnectionCertificateFetcher());
|
||||
}
|
||||
|
||||
public DiscoverImpl(WKDFetcher fetcher) {
|
||||
super(new CertificateReaderImpl(), fetcher);
|
||||
public DiscoverImpl(CertificateFetcher fetcher) {
|
||||
super(new CertificateParserImpl(), fetcher);
|
||||
}
|
||||
|
||||
public DiscoverImpl(CertificateReader certificateReader, WKDFetcher fetcher) {
|
||||
super(certificateReader, fetcher);
|
||||
public DiscoverImpl(CertificateParser certificateParser, CertificateFetcher fetcher) {
|
||||
super(certificateParser, fetcher);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,13 +7,13 @@ package pgp.wkd.cli.command;
|
|||
import org.bouncycastle.bcpg.ArmoredOutputStream;
|
||||
import org.bouncycastle.util.io.Streams;
|
||||
import pgp.certificate_store.Certificate;
|
||||
import pgp.wkd.Discover;
|
||||
import pgp.wkd.HttpUrlConnectionWKDFetcher;
|
||||
import pgp.wkd.discovery.CertificateDiscoverer;
|
||||
import pgp.wkd.discovery.HttpUrlConnectionCertificateFetcher;
|
||||
import pgp.wkd.MalformedUserIdException;
|
||||
import pgp.wkd.WKDAddress;
|
||||
import pgp.wkd.WKDAddressHelper;
|
||||
import pgp.wkd.WKDDiscoveryResult;
|
||||
import pgp.wkd.WKDFetcher;
|
||||
import pgp.wkd.discovery.DiscoveryResult;
|
||||
import pgp.wkd.discovery.CertificateFetcher;
|
||||
import pgp.wkd.cli.CertNotFetchableException;
|
||||
import pgp.wkd.cli.DiscoverImpl;
|
||||
import picocli.CommandLine;
|
||||
|
@ -42,14 +42,14 @@ public class Fetch implements Runnable {
|
|||
boolean armor = false;
|
||||
|
||||
// TODO: Better way to inject fetcher implementation
|
||||
public static WKDFetcher fetcher = new HttpUrlConnectionWKDFetcher();
|
||||
public static CertificateFetcher fetcher = new HttpUrlConnectionCertificateFetcher();
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Discover discover = new DiscoverImpl(fetcher);
|
||||
CertificateDiscoverer certificateDiscoverer = new DiscoverImpl(fetcher);
|
||||
|
||||
WKDAddress address = addressFromUserId(userId);
|
||||
WKDDiscoveryResult result = discover.discover(address);
|
||||
DiscoveryResult result = certificateDiscoverer.discover(address);
|
||||
|
||||
if (!result.isSuccessful()) {
|
||||
throw new CertNotFetchableException("Cannot fetch cert.");
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
|
||||
package pgp.wkd.cli.test_suite;
|
||||
|
||||
import pgp.wkd.DiscoveryMethod;
|
||||
import pgp.wkd.discovery.DiscoveryMethod;
|
||||
import pgp.wkd.WKDAddress;
|
||||
import pgp.wkd.WKDFetcher;
|
||||
import pgp.wkd.discovery.CertificateFetcher;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
@ -15,17 +15,17 @@ import java.io.InputStream;
|
|||
import java.net.URI;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class DirectoryBasedWkdFetcher implements WKDFetcher {
|
||||
public class DirectoryBasedCertificateFetcher implements CertificateFetcher {
|
||||
|
||||
// The directory containing the .well-known subdirectory
|
||||
private final Path rootPath;
|
||||
|
||||
public DirectoryBasedWkdFetcher(Path rootPath) {
|
||||
public DirectoryBasedCertificateFetcher(Path rootPath) {
|
||||
this.rootPath = rootPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream fetch(WKDAddress address, DiscoveryMethod method) throws IOException {
|
||||
public InputStream fetchCertificate(WKDAddress address, DiscoveryMethod method) throws IOException {
|
||||
URI uri = address.getUri(method);
|
||||
String path = uri.getPath();
|
||||
File file = rootPath.resolve(path.substring(1)).toFile(); // get rid of leading slash at start of path
|
|
@ -5,7 +5,9 @@
|
|||
package pgp.wkd.cli.test_suite;
|
||||
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.DynamicTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestFactory;
|
||||
import org.junit.platform.commons.logging.Logger;
|
||||
import org.junit.platform.commons.logging.LoggerFactory;
|
||||
import pgp.wkd.cli.WKDCLI;
|
||||
|
@ -17,6 +19,7 @@ import pgp.wkd.test_suite.TestSuiteGenerator;
|
|||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
@ -39,24 +42,29 @@ public class TestSuiteTestRunner {
|
|||
suite = generator.generateTestSuiteInDirectory(tempFile, TestSuiteGenerator.Method.direct);
|
||||
|
||||
// Fetch certificates from a local directory instead of the internetzzz.
|
||||
Fetch.fetcher = new DirectoryBasedWkdFetcher(tempPath);
|
||||
Fetch.fetcher = new DirectoryBasedCertificateFetcher(tempPath);
|
||||
}
|
||||
|
||||
@Test
|
||||
void runTestsAgainstTestSuite() {
|
||||
for (TestCase testCase : suite.getTestCases()) {
|
||||
LOGGER.info(() -> "Execute Test Case '" + testCase.getTestTitle() + "'");
|
||||
String mail = testCase.getLookupMailAddress();
|
||||
@TestFactory
|
||||
public Iterable<DynamicTest> testsFromTestSuite() {
|
||||
return suite.getTestCases()
|
||||
.stream()
|
||||
.map(testCase -> DynamicTest.dynamicTest(
|
||||
testCase.getTestTitle(),
|
||||
() -> {
|
||||
String mail = testCase.getLookupMailAddress();
|
||||
|
||||
int exitCode = WKDCLI.execute(new String[] {
|
||||
"fetch", "--armor", mail
|
||||
});
|
||||
int exitCode = WKDCLI.execute(new String[] {
|
||||
"fetch", "--armor", mail
|
||||
});
|
||||
|
||||
if (testCase.isExpectSuccess()) {
|
||||
assertEquals(0, exitCode, testCase.getTestDescription());
|
||||
} else {
|
||||
assertNotEquals(0, exitCode, testCase.getTestDescription());
|
||||
}
|
||||
}
|
||||
if (testCase.isExpectSuccess()) {
|
||||
assertEquals(0, exitCode, testCase.getTestDescription());
|
||||
} else {
|
||||
assertNotEquals(0, exitCode, testCase.getTestDescription());
|
||||
}
|
||||
}
|
||||
))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue