Bump cert-d-java to 0.2.1 and handle NoSuchElementExceptions

This commit is contained in:
Paul Schaub 2022-08-27 13:38:32 +02:00
parent 52a31cb541
commit 27ae686d52
4 changed files with 16 additions and 11 deletions

View file

@ -19,6 +19,7 @@ import pgp.certificate_store.exception.BadNameException;
import picocli.CommandLine;
import java.io.IOException;
import java.util.NoSuchElementException;
@CommandLine.Command(name = "get",
resourceBundle = "msg_get")
@ -57,6 +58,8 @@ public class Get implements Runnable {
Streams.pipeAll(record.getInputStream(), System.out);
}
} catch (NoSuchElementException e) {
LOGGER.debug("Certificate not found.", e);
} catch (IOException e) {
LOGGER.error("IO Error", e);
System.exit(-1);

View file

@ -27,11 +27,12 @@ import java.io.InputStream;
import java.nio.charset.Charset;
import java.security.InvalidAlgorithmParameterException;
import java.security.NoSuchAlgorithmException;
import java.util.NoSuchElementException;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class SetupTest {
@ -53,7 +54,7 @@ public class SetupTest {
@Test
public void testSetupGeneratesTrustRoot()
throws BadDataException, IOException {
assertNull(store.getTrustRoot());
assertThrows(NoSuchElementException.class, () -> store.getTrustRoot());
PGPCertDCli.main(new String[] {"setup"});
KeyMaterial trustRoot = store.getTrustRoot();
@ -68,7 +69,7 @@ public class SetupTest {
@Test
public void testSetupWithPassword()
throws BadDataException, IOException, PGPException {
assertNull(store.getTrustRoot());
assertThrows(NoSuchElementException.class, () -> store.getTrustRoot());
PGPCertDCli.main(new String[] {"setup", "--with-password", "sw0rdf1sh"});
KeyMaterial trustRoot = store.getTrustRoot();
@ -87,7 +88,7 @@ public class SetupTest {
public void testSetupImportFromStdin()
throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException,
BadDataException, IOException {
assertNull(store.getTrustRoot());
assertThrows(NoSuchElementException.class, () -> store.getTrustRoot());
PGPSecretKeyRing trustRoot = PGPainless.generateKeyRing()
.modernKeyRing("trust-root");
@ -108,7 +109,7 @@ public class SetupTest {
@Test
public void testSetupOverridesExistingTrustRoot()
throws BadDataException, IOException {
assertNull(store.getTrustRoot());
assertThrows(NoSuchElementException.class, () -> store.getTrustRoot());
PGPCertDCli.main(new String[] {"setup"});
KeyMaterial trustRoot = store.getTrustRoot();