mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2024-11-29 18:42:08 +01:00
Reference exit codes directly in junit tests
This commit is contained in:
parent
0c24c2301d
commit
61ab35ad52
11 changed files with 72 additions and 63 deletions
|
@ -14,6 +14,7 @@ import java.util.List;
|
||||||
import com.ginsberg.junit.exit.ExpectSystemExitWithStatus;
|
import com.ginsberg.junit.exit.ExpectSystemExitWithStatus;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import sop.SOP;
|
import sop.SOP;
|
||||||
|
import sop.exception.SOPGPException;
|
||||||
import sop.operation.Armor;
|
import sop.operation.Armor;
|
||||||
import sop.operation.Dearmor;
|
import sop.operation.Dearmor;
|
||||||
import sop.operation.Decrypt;
|
import sop.operation.Decrypt;
|
||||||
|
@ -30,7 +31,7 @@ import sop.operation.Version;
|
||||||
public class SOPTest {
|
public class SOPTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(69)
|
@ExpectSystemExitWithStatus(SOPGPException.UnsupportedSubcommand.EXIT_CODE)
|
||||||
public void assertExitOnInvalidSubcommand() {
|
public void assertExitOnInvalidSubcommand() {
|
||||||
SOP sop = mock(SOP.class);
|
SOP sop = mock(SOP.class);
|
||||||
SopCLI.setSopInstance(sop);
|
SopCLI.setSopInstance(sop);
|
||||||
|
@ -125,7 +126,8 @@ public class SOPTest {
|
||||||
|
|
||||||
for (String[] command : commands) {
|
for (String[] command : commands) {
|
||||||
int exit = SopCLI.execute(command);
|
int exit = SopCLI.execute(command);
|
||||||
assertEquals(69, exit, "Unexpected exit code for non-implemented command " + Arrays.toString(command) + ": " + exit);
|
assertEquals(SOPGPException.UnsupportedSubcommand.EXIT_CODE, exit,
|
||||||
|
"Unexpected exit code for non-implemented command " + Arrays.toString(command) + ": " + exit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,13 +62,13 @@ public class ArmorCmdTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(37)
|
@ExpectSystemExitWithStatus(SOPGPException.UnsupportedOption.EXIT_CODE)
|
||||||
public void assertThrowsForInvalidLabel() {
|
public void assertThrowsForInvalidLabel() {
|
||||||
SopCLI.main(new String[] {"armor", "--label", "Invalid"});
|
SopCLI.main(new String[] {"armor", "--label", "Invalid"});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(37)
|
@ExpectSystemExitWithStatus(SOPGPException.UnsupportedOption.EXIT_CODE)
|
||||||
public void ifLabelsUnsupportedExit37() throws SOPGPException.UnsupportedOption {
|
public void ifLabelsUnsupportedExit37() throws SOPGPException.UnsupportedOption {
|
||||||
when(armor.label(any())).thenThrow(new SOPGPException.UnsupportedOption("Custom Armor labels are not supported."));
|
when(armor.label(any())).thenThrow(new SOPGPException.UnsupportedOption("Custom Armor labels are not supported."));
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ public class ArmorCmdTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(41)
|
@ExpectSystemExitWithStatus(SOPGPException.BadData.EXIT_CODE)
|
||||||
public void ifBadDataExit41() throws SOPGPException.BadData, IOException {
|
public void ifBadDataExit41() throws SOPGPException.BadData, IOException {
|
||||||
when(armor.data((InputStream) any())).thenThrow(new SOPGPException.BadData(new IOException()));
|
when(armor.data((InputStream) any())).thenThrow(new SOPGPException.BadData(new IOException()));
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class DearmorCmdTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(41)
|
@ExpectSystemExitWithStatus(SOPGPException.BadData.EXIT_CODE)
|
||||||
public void assertBadDataCausesExit41() throws IOException, SOPGPException.BadData {
|
public void assertBadDataCausesExit41() throws IOException, SOPGPException.BadData {
|
||||||
when(dearmor.data((InputStream) any())).thenThrow(new SOPGPException.BadData(new IOException("invalid armor")));
|
when(dearmor.data((InputStream) any())).thenThrow(new SOPGPException.BadData(new IOException("invalid armor")));
|
||||||
SopCLI.main(new String[] {"dearmor"});
|
SopCLI.main(new String[] {"dearmor"});
|
||||||
|
|
|
@ -74,21 +74,21 @@ public class DecryptCmdTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(19)
|
@ExpectSystemExitWithStatus(SOPGPException.MissingArg.EXIT_CODE)
|
||||||
public void missingArgumentsExceptionCausesExit19() throws SOPGPException.MissingArg, SOPGPException.BadData, SOPGPException.CannotDecrypt, IOException {
|
public void missingArgumentsExceptionCausesExit19() throws SOPGPException.MissingArg, SOPGPException.BadData, SOPGPException.CannotDecrypt, IOException {
|
||||||
when(decrypt.ciphertext((InputStream) any())).thenThrow(new SOPGPException.MissingArg("Missing arguments."));
|
when(decrypt.ciphertext((InputStream) any())).thenThrow(new SOPGPException.MissingArg("Missing arguments."));
|
||||||
SopCLI.main(new String[] {"decrypt"});
|
SopCLI.main(new String[] {"decrypt"});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(41)
|
@ExpectSystemExitWithStatus(SOPGPException.BadData.EXIT_CODE)
|
||||||
public void badDataExceptionCausesExit41() throws SOPGPException.MissingArg, SOPGPException.BadData, SOPGPException.CannotDecrypt, IOException {
|
public void badDataExceptionCausesExit41() throws SOPGPException.MissingArg, SOPGPException.BadData, SOPGPException.CannotDecrypt, IOException {
|
||||||
when(decrypt.ciphertext((InputStream) any())).thenThrow(new SOPGPException.BadData(new IOException()));
|
when(decrypt.ciphertext((InputStream) any())).thenThrow(new SOPGPException.BadData(new IOException()));
|
||||||
SopCLI.main(new String[] {"decrypt"});
|
SopCLI.main(new String[] {"decrypt"});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(31)
|
@ExpectSystemExitWithStatus(SOPGPException.PasswordNotHumanReadable.EXIT_CODE)
|
||||||
public void assertNotHumanReadablePasswordCausesExit31() throws SOPGPException.PasswordNotHumanReadable,
|
public void assertNotHumanReadablePasswordCausesExit31() throws SOPGPException.PasswordNotHumanReadable,
|
||||||
SOPGPException.UnsupportedOption, IOException {
|
SOPGPException.UnsupportedOption, IOException {
|
||||||
File passwordFile = TestFileUtil.writeTempStringFile("pretendThisIsNotReadable");
|
File passwordFile = TestFileUtil.writeTempStringFile("pretendThisIsNotReadable");
|
||||||
|
@ -104,7 +104,7 @@ public class DecryptCmdTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(37)
|
@ExpectSystemExitWithStatus(SOPGPException.UnsupportedOption.EXIT_CODE)
|
||||||
public void assertUnsupportedWithPasswordCausesExit37() throws SOPGPException.PasswordNotHumanReadable, SOPGPException.UnsupportedOption, IOException {
|
public void assertUnsupportedWithPasswordCausesExit37() throws SOPGPException.PasswordNotHumanReadable, SOPGPException.UnsupportedOption, IOException {
|
||||||
File passwordFile = TestFileUtil.writeTempStringFile("swordfish");
|
File passwordFile = TestFileUtil.writeTempStringFile("swordfish");
|
||||||
when(decrypt.withPassword(any())).thenThrow(new SOPGPException.UnsupportedOption("Decrypting with password not supported."));
|
when(decrypt.withPassword(any())).thenThrow(new SOPGPException.UnsupportedOption("Decrypting with password not supported."));
|
||||||
|
@ -158,21 +158,21 @@ public class DecryptCmdTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(37)
|
@ExpectSystemExitWithStatus(SOPGPException.UnsupportedOption.EXIT_CODE)
|
||||||
public void assertUnsupportedNotAfterCausesExit37() throws SOPGPException.UnsupportedOption {
|
public void assertUnsupportedNotAfterCausesExit37() throws SOPGPException.UnsupportedOption {
|
||||||
when(decrypt.verifyNotAfter(any())).thenThrow(new SOPGPException.UnsupportedOption("Setting upper signature date boundary not supported."));
|
when(decrypt.verifyNotAfter(any())).thenThrow(new SOPGPException.UnsupportedOption("Setting upper signature date boundary not supported."));
|
||||||
SopCLI.main(new String[] {"decrypt", "--not-after", "now"});
|
SopCLI.main(new String[] {"decrypt", "--not-after", "now"});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(37)
|
@ExpectSystemExitWithStatus(SOPGPException.UnsupportedOption.EXIT_CODE)
|
||||||
public void assertUnsupportedNotBeforeCausesExit37() throws SOPGPException.UnsupportedOption {
|
public void assertUnsupportedNotBeforeCausesExit37() throws SOPGPException.UnsupportedOption {
|
||||||
when(decrypt.verifyNotBefore(any())).thenThrow(new SOPGPException.UnsupportedOption("Setting lower signature date boundary not supported."));
|
when(decrypt.verifyNotBefore(any())).thenThrow(new SOPGPException.UnsupportedOption("Setting lower signature date boundary not supported."));
|
||||||
SopCLI.main(new String[] {"decrypt", "--not-before", "now"});
|
SopCLI.main(new String[] {"decrypt", "--not-before", "now"});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(59)
|
@ExpectSystemExitWithStatus(SOPGPException.OutputExists.EXIT_CODE)
|
||||||
public void assertExistingSessionKeyOutFileCausesExit59() throws IOException {
|
public void assertExistingSessionKeyOutFileCausesExit59() throws IOException {
|
||||||
File tempFile = File.createTempFile("existing-session-key-", ".tmp");
|
File tempFile = File.createTempFile("existing-session-key-", ".tmp");
|
||||||
tempFile.deleteOnExit();
|
tempFile.deleteOnExit();
|
||||||
|
@ -180,7 +180,7 @@ public class DecryptCmdTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(37)
|
@ExpectSystemExitWithStatus(SOPGPException.UnsupportedOption.EXIT_CODE)
|
||||||
public void assertWhenSessionKeyCannotBeExtractedExit37() throws IOException {
|
public void assertWhenSessionKeyCannotBeExtractedExit37() throws IOException {
|
||||||
Path tempDir = Files.createTempDirectory("session-key-out-dir");
|
Path tempDir = Files.createTempDirectory("session-key-out-dir");
|
||||||
File tempFile = new File(tempDir.toFile(), "session-key");
|
File tempFile = new File(tempDir.toFile(), "session-key");
|
||||||
|
@ -222,14 +222,14 @@ public class DecryptCmdTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(29)
|
@ExpectSystemExitWithStatus(SOPGPException.CannotDecrypt.EXIT_CODE)
|
||||||
public void assertUnableToDecryptExceptionResultsInExit29() throws SOPGPException.CannotDecrypt, SOPGPException.MissingArg, SOPGPException.BadData, IOException {
|
public void assertUnableToDecryptExceptionResultsInExit29() throws SOPGPException.CannotDecrypt, SOPGPException.MissingArg, SOPGPException.BadData, IOException {
|
||||||
when(decrypt.ciphertext((InputStream) any())).thenThrow(new SOPGPException.CannotDecrypt());
|
when(decrypt.ciphertext((InputStream) any())).thenThrow(new SOPGPException.CannotDecrypt());
|
||||||
SopCLI.main(new String[] {"decrypt"});
|
SopCLI.main(new String[] {"decrypt"});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(3)
|
@ExpectSystemExitWithStatus(SOPGPException.NoSignature.EXIT_CODE)
|
||||||
public void assertNoSignatureExceptionCausesExit3() throws SOPGPException.CannotDecrypt, SOPGPException.MissingArg, SOPGPException.BadData, IOException {
|
public void assertNoSignatureExceptionCausesExit3() throws SOPGPException.CannotDecrypt, SOPGPException.MissingArg, SOPGPException.BadData, IOException {
|
||||||
when(decrypt.ciphertext((InputStream) any())).thenReturn(new ReadyWithResult<DecryptionResult>() {
|
when(decrypt.ciphertext((InputStream) any())).thenReturn(new ReadyWithResult<DecryptionResult>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -241,7 +241,7 @@ public class DecryptCmdTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(41)
|
@ExpectSystemExitWithStatus(SOPGPException.BadData.EXIT_CODE)
|
||||||
public void badDataInVerifyWithCausesExit41() throws IOException, SOPGPException.BadData {
|
public void badDataInVerifyWithCausesExit41() throws IOException, SOPGPException.BadData {
|
||||||
when(decrypt.verifyWithCert((InputStream) any())).thenThrow(new SOPGPException.BadData(new IOException()));
|
when(decrypt.verifyWithCert((InputStream) any())).thenThrow(new SOPGPException.BadData(new IOException()));
|
||||||
File tempFile = File.createTempFile("verify-with-", ".tmp");
|
File tempFile = File.createTempFile("verify-with-", ".tmp");
|
||||||
|
@ -249,13 +249,13 @@ public class DecryptCmdTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(61)
|
@ExpectSystemExitWithStatus(SOPGPException.MissingInput.EXIT_CODE)
|
||||||
public void unexistentCertFileCausesExit61() {
|
public void unexistentCertFileCausesExit61() {
|
||||||
SopCLI.main(new String[] {"decrypt", "--verify-with", "invalid"});
|
SopCLI.main(new String[] {"decrypt", "--verify-with", "invalid"});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(59)
|
@ExpectSystemExitWithStatus(SOPGPException.OutputExists.EXIT_CODE)
|
||||||
public void existingVerifyOutCausesExit59() throws IOException {
|
public void existingVerifyOutCausesExit59() throws IOException {
|
||||||
File certFile = File.createTempFile("existing-verify-out-cert", ".asc");
|
File certFile = File.createTempFile("existing-verify-out-cert", ".asc");
|
||||||
File existingVerifyOut = File.createTempFile("existing-verify-out", ".tmp");
|
File existingVerifyOut = File.createTempFile("existing-verify-out", ".tmp");
|
||||||
|
@ -315,7 +315,7 @@ public class DecryptCmdTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(41)
|
@ExpectSystemExitWithStatus(SOPGPException.BadData.EXIT_CODE)
|
||||||
public void assertBadDataInKeysResultsInExit41() throws SOPGPException.KeyIsProtected, SOPGPException.UnsupportedAsymmetricAlgo, SOPGPException.BadData, IOException {
|
public void assertBadDataInKeysResultsInExit41() throws SOPGPException.KeyIsProtected, SOPGPException.UnsupportedAsymmetricAlgo, SOPGPException.BadData, IOException {
|
||||||
when(decrypt.withKey((InputStream) any())).thenThrow(new SOPGPException.BadData(new IOException()));
|
when(decrypt.withKey((InputStream) any())).thenThrow(new SOPGPException.BadData(new IOException()));
|
||||||
File tempKeyFile = File.createTempFile("key-", ".tmp");
|
File tempKeyFile = File.createTempFile("key-", ".tmp");
|
||||||
|
@ -323,13 +323,13 @@ public class DecryptCmdTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(61)
|
@ExpectSystemExitWithStatus(SOPGPException.MissingInput.EXIT_CODE)
|
||||||
public void assertKeyFileNotFoundCausesExit61() {
|
public void assertKeyFileNotFoundCausesExit61() {
|
||||||
SopCLI.main(new String[] {"decrypt", "nonexistent-key"});
|
SopCLI.main(new String[] {"decrypt", "nonexistent-key"});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(67)
|
@ExpectSystemExitWithStatus(SOPGPException.KeyIsProtected.EXIT_CODE)
|
||||||
public void assertProtectedKeyCausesExit67() throws IOException, SOPGPException.KeyIsProtected, SOPGPException.UnsupportedAsymmetricAlgo, SOPGPException.BadData {
|
public void assertProtectedKeyCausesExit67() throws IOException, SOPGPException.KeyIsProtected, SOPGPException.UnsupportedAsymmetricAlgo, SOPGPException.BadData {
|
||||||
when(decrypt.withKey((InputStream) any())).thenThrow(new SOPGPException.KeyIsProtected());
|
when(decrypt.withKey((InputStream) any())).thenThrow(new SOPGPException.KeyIsProtected());
|
||||||
File tempKeyFile = File.createTempFile("key-", ".tmp");
|
File tempKeyFile = File.createTempFile("key-", ".tmp");
|
||||||
|
@ -337,7 +337,7 @@ public class DecryptCmdTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(13)
|
@ExpectSystemExitWithStatus(SOPGPException.UnsupportedAsymmetricAlgo.EXIT_CODE)
|
||||||
public void assertUnsupportedAlgorithmExceptionCausesExit13() throws SOPGPException.KeyIsProtected, SOPGPException.UnsupportedAsymmetricAlgo, SOPGPException.BadData, IOException {
|
public void assertUnsupportedAlgorithmExceptionCausesExit13() throws SOPGPException.KeyIsProtected, SOPGPException.UnsupportedAsymmetricAlgo, SOPGPException.BadData, IOException {
|
||||||
when(decrypt.withKey((InputStream) any())).thenThrow(new SOPGPException.UnsupportedAsymmetricAlgo("Unsupported asymmetric algorithm.", new IOException()));
|
when(decrypt.withKey((InputStream) any())).thenThrow(new SOPGPException.UnsupportedAsymmetricAlgo("Unsupported asymmetric algorithm.", new IOException()));
|
||||||
File tempKeyFile = File.createTempFile("key-", ".tmp");
|
File tempKeyFile = File.createTempFile("key-", ".tmp");
|
||||||
|
@ -345,19 +345,19 @@ public class DecryptCmdTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(61)
|
@ExpectSystemExitWithStatus(SOPGPException.MissingInput.EXIT_CODE)
|
||||||
public void assertMissingPassphraseFileCausesExit61() {
|
public void assertMissingPassphraseFileCausesExit61() {
|
||||||
SopCLI.main(new String[] {"decrypt", "--with-password", "missing"});
|
SopCLI.main(new String[] {"decrypt", "--with-password", "missing"});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(61)
|
@ExpectSystemExitWithStatus(SOPGPException.MissingInput.EXIT_CODE)
|
||||||
public void assertMissingSessionKeyFileCausesExit61() {
|
public void assertMissingSessionKeyFileCausesExit61() {
|
||||||
SopCLI.main(new String[] {"decrypt", "--with-session-key", "missing"});
|
SopCLI.main(new String[] {"decrypt", "--with-session-key", "missing"});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(23)
|
@ExpectSystemExitWithStatus(SOPGPException.IncompleteVerification.EXIT_CODE)
|
||||||
public void verifyOutWithoutVerifyWithCausesExit23() {
|
public void verifyOutWithoutVerifyWithCausesExit23() {
|
||||||
SopCLI.main(new String[] {"decrypt", "--verify-out", "out.file"});
|
SopCLI.main(new String[] {"decrypt", "--verify-out", "out.file"});
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,13 +48,13 @@ public class EncryptCmdTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(19)
|
@ExpectSystemExitWithStatus(SOPGPException.MissingArg.EXIT_CODE)
|
||||||
public void missingBothPasswordAndCertFileCauseExit19() {
|
public void missingBothPasswordAndCertFileCauseExit19() {
|
||||||
SopCLI.main(new String[] {"encrypt", "--no-armor"});
|
SopCLI.main(new String[] {"encrypt", "--no-armor"});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(37)
|
@ExpectSystemExitWithStatus(SOPGPException.UnsupportedOption.EXIT_CODE)
|
||||||
public void as_unsupportedEncryptAsCausesExit37() throws SOPGPException.UnsupportedOption {
|
public void as_unsupportedEncryptAsCausesExit37() throws SOPGPException.UnsupportedOption {
|
||||||
when(encrypt.mode(any())).thenThrow(new SOPGPException.UnsupportedOption("Setting encryption mode not supported."));
|
when(encrypt.mode(any())).thenThrow(new SOPGPException.UnsupportedOption("Setting encryption mode not supported."));
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ public class EncryptCmdTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(37)
|
@ExpectSystemExitWithStatus(SOPGPException.UnsupportedOption.EXIT_CODE)
|
||||||
public void as_invalidModeOptionCausesExit37() {
|
public void as_invalidModeOptionCausesExit37() {
|
||||||
SopCLI.main(new String[] {"encrypt", "--as", "invalid"});
|
SopCLI.main(new String[] {"encrypt", "--as", "invalid"});
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ public class EncryptCmdTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(31)
|
@ExpectSystemExitWithStatus(SOPGPException.PasswordNotHumanReadable.EXIT_CODE)
|
||||||
public void withPassword_notHumanReadablePasswordCausesExit31() throws SOPGPException.PasswordNotHumanReadable, SOPGPException.UnsupportedOption, IOException {
|
public void withPassword_notHumanReadablePasswordCausesExit31() throws SOPGPException.PasswordNotHumanReadable, SOPGPException.UnsupportedOption, IOException {
|
||||||
when(encrypt.withPassword("pretendThisIsNotReadable")).thenThrow(new SOPGPException.PasswordNotHumanReadable());
|
when(encrypt.withPassword("pretendThisIsNotReadable")).thenThrow(new SOPGPException.PasswordNotHumanReadable());
|
||||||
File passwordFile = TestFileUtil.writeTempStringFile("pretendThisIsNotReadable");
|
File passwordFile = TestFileUtil.writeTempStringFile("pretendThisIsNotReadable");
|
||||||
|
@ -85,7 +85,7 @@ public class EncryptCmdTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(37)
|
@ExpectSystemExitWithStatus(SOPGPException.UnsupportedOption.EXIT_CODE)
|
||||||
public void withPassword_unsupportedWithPasswordCausesExit37() throws SOPGPException.PasswordNotHumanReadable, SOPGPException.UnsupportedOption, IOException {
|
public void withPassword_unsupportedWithPasswordCausesExit37() throws SOPGPException.PasswordNotHumanReadable, SOPGPException.UnsupportedOption, IOException {
|
||||||
when(encrypt.withPassword(any())).thenThrow(new SOPGPException.UnsupportedOption("Encrypting with password not supported."));
|
when(encrypt.withPassword(any())).thenThrow(new SOPGPException.UnsupportedOption("Encrypting with password not supported."));
|
||||||
File passwordFile = TestFileUtil.writeTempStringFile("orange");
|
File passwordFile = TestFileUtil.writeTempStringFile("orange");
|
||||||
|
@ -102,13 +102,13 @@ public class EncryptCmdTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(61)
|
@ExpectSystemExitWithStatus(SOPGPException.MissingInput.EXIT_CODE)
|
||||||
public void signWith_nonExistentKeyFileCausesExit61() {
|
public void signWith_nonExistentKeyFileCausesExit61() {
|
||||||
SopCLI.main(new String[] {"encrypt", "--with-password", "admin", "--sign-with", "nonExistent.asc"});
|
SopCLI.main(new String[] {"encrypt", "--with-password", "admin", "--sign-with", "nonExistent.asc"});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(67)
|
@ExpectSystemExitWithStatus(SOPGPException.KeyIsProtected.EXIT_CODE)
|
||||||
public void signWith_keyIsProtectedCausesExit67() throws SOPGPException.KeyIsProtected, SOPGPException.UnsupportedAsymmetricAlgo, SOPGPException.KeyCannotSign, SOPGPException.BadData, IOException {
|
public void signWith_keyIsProtectedCausesExit67() throws SOPGPException.KeyIsProtected, SOPGPException.UnsupportedAsymmetricAlgo, SOPGPException.KeyCannotSign, SOPGPException.BadData, IOException {
|
||||||
when(encrypt.signWith((InputStream) any())).thenThrow(new SOPGPException.KeyIsProtected());
|
when(encrypt.signWith((InputStream) any())).thenThrow(new SOPGPException.KeyIsProtected());
|
||||||
File keyFile = File.createTempFile("sign-with", ".asc");
|
File keyFile = File.createTempFile("sign-with", ".asc");
|
||||||
|
@ -117,7 +117,7 @@ public class EncryptCmdTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(13)
|
@ExpectSystemExitWithStatus(SOPGPException.UnsupportedAsymmetricAlgo.EXIT_CODE)
|
||||||
public void signWith_unsupportedAsymmetricAlgoCausesExit13() throws SOPGPException.KeyIsProtected, SOPGPException.UnsupportedAsymmetricAlgo, SOPGPException.KeyCannotSign, SOPGPException.BadData, IOException {
|
public void signWith_unsupportedAsymmetricAlgoCausesExit13() throws SOPGPException.KeyIsProtected, SOPGPException.UnsupportedAsymmetricAlgo, SOPGPException.KeyCannotSign, SOPGPException.BadData, IOException {
|
||||||
when(encrypt.signWith((InputStream) any())).thenThrow(new SOPGPException.UnsupportedAsymmetricAlgo("Unsupported asymmetric algorithm.", new Exception()));
|
when(encrypt.signWith((InputStream) any())).thenThrow(new SOPGPException.UnsupportedAsymmetricAlgo("Unsupported asymmetric algorithm.", new Exception()));
|
||||||
File keyFile = File.createTempFile("sign-with", ".asc");
|
File keyFile = File.createTempFile("sign-with", ".asc");
|
||||||
|
@ -126,7 +126,7 @@ public class EncryptCmdTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(79)
|
@ExpectSystemExitWithStatus(SOPGPException.KeyCannotSign.EXIT_CODE)
|
||||||
public void signWith_certCannotSignCausesExit79() throws IOException, SOPGPException.KeyIsProtected, SOPGPException.UnsupportedAsymmetricAlgo, SOPGPException.KeyCannotSign, SOPGPException.BadData {
|
public void signWith_certCannotSignCausesExit79() throws IOException, SOPGPException.KeyIsProtected, SOPGPException.UnsupportedAsymmetricAlgo, SOPGPException.KeyCannotSign, SOPGPException.BadData {
|
||||||
when(encrypt.signWith((InputStream) any())).thenThrow(new SOPGPException.KeyCannotSign());
|
when(encrypt.signWith((InputStream) any())).thenThrow(new SOPGPException.KeyCannotSign());
|
||||||
File keyFile = File.createTempFile("sign-with", ".asc");
|
File keyFile = File.createTempFile("sign-with", ".asc");
|
||||||
|
@ -135,7 +135,7 @@ public class EncryptCmdTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(41)
|
@ExpectSystemExitWithStatus(SOPGPException.BadData.EXIT_CODE)
|
||||||
public void signWith_badDataCausesExit41() throws SOPGPException.KeyIsProtected, SOPGPException.UnsupportedAsymmetricAlgo, SOPGPException.KeyCannotSign, SOPGPException.BadData, IOException {
|
public void signWith_badDataCausesExit41() throws SOPGPException.KeyIsProtected, SOPGPException.UnsupportedAsymmetricAlgo, SOPGPException.KeyCannotSign, SOPGPException.BadData, IOException {
|
||||||
when(encrypt.signWith((InputStream) any())).thenThrow(new SOPGPException.BadData(new IOException()));
|
when(encrypt.signWith((InputStream) any())).thenThrow(new SOPGPException.BadData(new IOException()));
|
||||||
File keyFile = File.createTempFile("sign-with", ".asc");
|
File keyFile = File.createTempFile("sign-with", ".asc");
|
||||||
|
@ -144,13 +144,13 @@ public class EncryptCmdTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(61)
|
@ExpectSystemExitWithStatus(SOPGPException.MissingInput.EXIT_CODE)
|
||||||
public void cert_nonExistentCertFileCausesExit61() {
|
public void cert_nonExistentCertFileCausesExit61() {
|
||||||
SopCLI.main(new String[] {"encrypt", "invalid.asc"});
|
SopCLI.main(new String[] {"encrypt", "invalid.asc"});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(13)
|
@ExpectSystemExitWithStatus(SOPGPException.UnsupportedAsymmetricAlgo.EXIT_CODE)
|
||||||
public void cert_unsupportedAsymmetricAlgorithmCausesExit13() throws IOException, SOPGPException.UnsupportedAsymmetricAlgo, SOPGPException.CertCannotEncrypt, SOPGPException.BadData {
|
public void cert_unsupportedAsymmetricAlgorithmCausesExit13() throws IOException, SOPGPException.UnsupportedAsymmetricAlgo, SOPGPException.CertCannotEncrypt, SOPGPException.BadData {
|
||||||
when(encrypt.withCert((InputStream) any())).thenThrow(new SOPGPException.UnsupportedAsymmetricAlgo("Unsupported asymmetric algorithm.", new Exception()));
|
when(encrypt.withCert((InputStream) any())).thenThrow(new SOPGPException.UnsupportedAsymmetricAlgo("Unsupported asymmetric algorithm.", new Exception()));
|
||||||
File certFile = File.createTempFile("cert", ".asc");
|
File certFile = File.createTempFile("cert", ".asc");
|
||||||
|
@ -158,7 +158,7 @@ public class EncryptCmdTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(17)
|
@ExpectSystemExitWithStatus(SOPGPException.CertCannotEncrypt.EXIT_CODE)
|
||||||
public void cert_certCannotEncryptCausesExit17() throws IOException, SOPGPException.UnsupportedAsymmetricAlgo, SOPGPException.CertCannotEncrypt, SOPGPException.BadData {
|
public void cert_certCannotEncryptCausesExit17() throws IOException, SOPGPException.UnsupportedAsymmetricAlgo, SOPGPException.CertCannotEncrypt, SOPGPException.BadData {
|
||||||
when(encrypt.withCert((InputStream) any())).thenThrow(new SOPGPException.CertCannotEncrypt("Certificate cannot encrypt.", new Exception()));
|
when(encrypt.withCert((InputStream) any())).thenThrow(new SOPGPException.CertCannotEncrypt("Certificate cannot encrypt.", new Exception()));
|
||||||
File certFile = File.createTempFile("cert", ".asc");
|
File certFile = File.createTempFile("cert", ".asc");
|
||||||
|
@ -166,7 +166,7 @@ public class EncryptCmdTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(41)
|
@ExpectSystemExitWithStatus(SOPGPException.BadData.EXIT_CODE)
|
||||||
public void cert_badDataCausesExit41() throws IOException, SOPGPException.UnsupportedAsymmetricAlgo, SOPGPException.CertCannotEncrypt, SOPGPException.BadData {
|
public void cert_badDataCausesExit41() throws IOException, SOPGPException.UnsupportedAsymmetricAlgo, SOPGPException.CertCannotEncrypt, SOPGPException.BadData {
|
||||||
when(encrypt.withCert((InputStream) any())).thenThrow(new SOPGPException.BadData(new IOException()));
|
when(encrypt.withCert((InputStream) any())).thenThrow(new SOPGPException.BadData(new IOException()));
|
||||||
File certFile = File.createTempFile("cert", ".asc");
|
File certFile = File.createTempFile("cert", ".asc");
|
||||||
|
|
|
@ -68,7 +68,7 @@ public class ExtractCertCmdTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(41)
|
@ExpectSystemExitWithStatus(SOPGPException.BadData.EXIT_CODE)
|
||||||
public void key_badDataCausesExit41() throws IOException, SOPGPException.BadData {
|
public void key_badDataCausesExit41() throws IOException, SOPGPException.BadData {
|
||||||
when(extractCert.key((InputStream) any())).thenThrow(new SOPGPException.BadData(new IOException()));
|
when(extractCert.key((InputStream) any())).thenThrow(new SOPGPException.BadData(new IOException()));
|
||||||
SopCLI.main(new String[] {"extract-cert"});
|
SopCLI.main(new String[] {"extract-cert"});
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class GenerateKeyCmdTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(19)
|
@ExpectSystemExitWithStatus(SOPGPException.MissingArg.EXIT_CODE)
|
||||||
public void missingArgumentCausesExit19() throws SOPGPException.UnsupportedAsymmetricAlgo, SOPGPException.MissingArg, IOException {
|
public void missingArgumentCausesExit19() throws SOPGPException.UnsupportedAsymmetricAlgo, SOPGPException.MissingArg, IOException {
|
||||||
// TODO: RFC4880-bis and the current Stateless OpenPGP CLI spec allow keys to have no user-ids,
|
// TODO: RFC4880-bis and the current Stateless OpenPGP CLI spec allow keys to have no user-ids,
|
||||||
// so we might want to change this test in the future.
|
// so we might want to change this test in the future.
|
||||||
|
@ -78,7 +78,7 @@ public class GenerateKeyCmdTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(13)
|
@ExpectSystemExitWithStatus(SOPGPException.UnsupportedAsymmetricAlgo.EXIT_CODE)
|
||||||
public void unsupportedAsymmetricAlgorithmCausesExit13() throws SOPGPException.UnsupportedAsymmetricAlgo, SOPGPException.MissingArg, IOException {
|
public void unsupportedAsymmetricAlgorithmCausesExit13() throws SOPGPException.UnsupportedAsymmetricAlgo, SOPGPException.MissingArg, IOException {
|
||||||
when(generateKey.generate()).thenThrow(new SOPGPException.UnsupportedAsymmetricAlgo("Unsupported asymmetric algorithm.", new Exception()));
|
when(generateKey.generate()).thenThrow(new SOPGPException.UnsupportedAsymmetricAlgo("Unsupported asymmetric algorithm.", new Exception()));
|
||||||
SopCLI.main(new String[] {"generate-key", "Alice"});
|
SopCLI.main(new String[] {"generate-key", "Alice"});
|
||||||
|
|
|
@ -57,40 +57,40 @@ public class SignCmdTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(37)
|
@ExpectSystemExitWithStatus(SOPGPException.UnsupportedOption.EXIT_CODE)
|
||||||
public void as_invalidOptionCausesExit37() {
|
public void as_invalidOptionCausesExit37() {
|
||||||
SopCLI.main(new String[] {"sign", "--as", "Invalid", keyFile.getAbsolutePath()});
|
SopCLI.main(new String[] {"sign", "--as", "Invalid", keyFile.getAbsolutePath()});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(37)
|
@ExpectSystemExitWithStatus(SOPGPException.UnsupportedOption.EXIT_CODE)
|
||||||
public void as_unsupportedOptionCausesExit37() throws SOPGPException.UnsupportedOption {
|
public void as_unsupportedOptionCausesExit37() throws SOPGPException.UnsupportedOption {
|
||||||
when(detachedSign.mode(any())).thenThrow(new SOPGPException.UnsupportedOption("Setting signing mode not supported."));
|
when(detachedSign.mode(any())).thenThrow(new SOPGPException.UnsupportedOption("Setting signing mode not supported."));
|
||||||
SopCLI.main(new String[] {"sign", "--as", "binary", keyFile.getAbsolutePath()});
|
SopCLI.main(new String[] {"sign", "--as", "binary", keyFile.getAbsolutePath()});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(61)
|
@ExpectSystemExitWithStatus(SOPGPException.MissingInput.EXIT_CODE)
|
||||||
public void key_nonExistentKeyFileCausesExit61() {
|
public void key_nonExistentKeyFileCausesExit61() {
|
||||||
SopCLI.main(new String[] {"sign", "invalid.asc"});
|
SopCLI.main(new String[] {"sign", "invalid.asc"});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(67)
|
@ExpectSystemExitWithStatus(SOPGPException.KeyIsProtected.EXIT_CODE)
|
||||||
public void key_keyIsProtectedCausesExit67() throws SOPGPException.KeyIsProtected, IOException, SOPGPException.BadData {
|
public void key_keyIsProtectedCausesExit67() throws SOPGPException.KeyIsProtected, IOException, SOPGPException.BadData {
|
||||||
when(detachedSign.key((InputStream) any())).thenThrow(new SOPGPException.KeyIsProtected());
|
when(detachedSign.key((InputStream) any())).thenThrow(new SOPGPException.KeyIsProtected());
|
||||||
SopCLI.main(new String[] {"sign", keyFile.getAbsolutePath()});
|
SopCLI.main(new String[] {"sign", keyFile.getAbsolutePath()});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(41)
|
@ExpectSystemExitWithStatus(SOPGPException.BadData.EXIT_CODE)
|
||||||
public void key_badDataCausesExit41() throws SOPGPException.KeyIsProtected, IOException, SOPGPException.BadData {
|
public void key_badDataCausesExit41() throws SOPGPException.KeyIsProtected, IOException, SOPGPException.BadData {
|
||||||
when(detachedSign.key((InputStream) any())).thenThrow(new SOPGPException.BadData(new IOException()));
|
when(detachedSign.key((InputStream) any())).thenThrow(new SOPGPException.BadData(new IOException()));
|
||||||
SopCLI.main(new String[] {"sign", keyFile.getAbsolutePath()});
|
SopCLI.main(new String[] {"sign", keyFile.getAbsolutePath()});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(19)
|
@ExpectSystemExitWithStatus(SOPGPException.MissingArg.EXIT_CODE)
|
||||||
public void key_missingKeyFileCausesExit19() {
|
public void key_missingKeyFileCausesExit19() {
|
||||||
SopCLI.main(new String[] {"sign"});
|
SopCLI.main(new String[] {"sign"});
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ public class SignCmdTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(53)
|
@ExpectSystemExitWithStatus(SOPGPException.ExpectedText.EXIT_CODE)
|
||||||
public void data_expectedTextExceptionCausesExit53() throws IOException, SOPGPException.ExpectedText {
|
public void data_expectedTextExceptionCausesExit53() throws IOException, SOPGPException.ExpectedText {
|
||||||
when(detachedSign.data((InputStream) any())).thenThrow(new SOPGPException.ExpectedText());
|
when(detachedSign.data((InputStream) any())).thenThrow(new SOPGPException.ExpectedText());
|
||||||
SopCLI.main(new String[] {"sign", keyFile.getAbsolutePath()});
|
SopCLI.main(new String[] {"sign", keyFile.getAbsolutePath()});
|
||||||
|
|
|
@ -93,7 +93,7 @@ public class VerifyCmdTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(37)
|
@ExpectSystemExitWithStatus(SOPGPException.UnsupportedOption.EXIT_CODE)
|
||||||
public void notAfter_unsupportedOptionCausesExit37() throws SOPGPException.UnsupportedOption {
|
public void notAfter_unsupportedOptionCausesExit37() throws SOPGPException.UnsupportedOption {
|
||||||
when(detachedVerify.notAfter(any())).thenThrow(new SOPGPException.UnsupportedOption("Setting upper signature date boundary not supported."));
|
when(detachedVerify.notAfter(any())).thenThrow(new SOPGPException.UnsupportedOption("Setting upper signature date boundary not supported."));
|
||||||
SopCLI.main(new String[] {"verify", "--not-after", "2019-10-29T18:36:45Z", signature.getAbsolutePath(), cert.getAbsolutePath()});
|
SopCLI.main(new String[] {"verify", "--not-after", "2019-10-29T18:36:45Z", signature.getAbsolutePath(), cert.getAbsolutePath()});
|
||||||
|
@ -120,7 +120,7 @@ public class VerifyCmdTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(37)
|
@ExpectSystemExitWithStatus(SOPGPException.UnsupportedOption.EXIT_CODE)
|
||||||
public void notBefore_unsupportedOptionCausesExit37() throws SOPGPException.UnsupportedOption {
|
public void notBefore_unsupportedOptionCausesExit37() throws SOPGPException.UnsupportedOption {
|
||||||
when(detachedVerify.notBefore(any())).thenThrow(new SOPGPException.UnsupportedOption("Setting lower signature date boundary not supported."));
|
when(detachedVerify.notBefore(any())).thenThrow(new SOPGPException.UnsupportedOption("Setting lower signature date boundary not supported."));
|
||||||
SopCLI.main(new String[] {"verify", "--not-before", "2019-10-29T18:36:45Z", signature.getAbsolutePath(), cert.getAbsolutePath()});
|
SopCLI.main(new String[] {"verify", "--not-before", "2019-10-29T18:36:45Z", signature.getAbsolutePath(), cert.getAbsolutePath()});
|
||||||
|
@ -138,40 +138,40 @@ public class VerifyCmdTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(61)
|
@ExpectSystemExitWithStatus(SOPGPException.MissingInput.EXIT_CODE)
|
||||||
public void cert_fileNotFoundCausesExit61() {
|
public void cert_fileNotFoundCausesExit61() {
|
||||||
SopCLI.main(new String[] {"verify", signature.getAbsolutePath(), "invalid.asc"});
|
SopCLI.main(new String[] {"verify", signature.getAbsolutePath(), "invalid.asc"});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(41)
|
@ExpectSystemExitWithStatus(SOPGPException.BadData.EXIT_CODE)
|
||||||
public void cert_badDataCausesExit41() throws SOPGPException.BadData, IOException {
|
public void cert_badDataCausesExit41() throws SOPGPException.BadData, IOException {
|
||||||
when(detachedVerify.cert((InputStream) any())).thenThrow(new SOPGPException.BadData(new IOException()));
|
when(detachedVerify.cert((InputStream) any())).thenThrow(new SOPGPException.BadData(new IOException()));
|
||||||
SopCLI.main(new String[] {"verify", signature.getAbsolutePath(), cert.getAbsolutePath()});
|
SopCLI.main(new String[] {"verify", signature.getAbsolutePath(), cert.getAbsolutePath()});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(61)
|
@ExpectSystemExitWithStatus(SOPGPException.MissingInput.EXIT_CODE)
|
||||||
public void signature_fileNotFoundCausesExit61() {
|
public void signature_fileNotFoundCausesExit61() {
|
||||||
SopCLI.main(new String[] {"verify", "invalid.sig", cert.getAbsolutePath()});
|
SopCLI.main(new String[] {"verify", "invalid.sig", cert.getAbsolutePath()});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(41)
|
@ExpectSystemExitWithStatus(SOPGPException.BadData.EXIT_CODE)
|
||||||
public void signature_badDataCausesExit41() throws SOPGPException.BadData, IOException {
|
public void signature_badDataCausesExit41() throws SOPGPException.BadData, IOException {
|
||||||
when(detachedVerify.signatures((InputStream) any())).thenThrow(new SOPGPException.BadData(new IOException()));
|
when(detachedVerify.signatures((InputStream) any())).thenThrow(new SOPGPException.BadData(new IOException()));
|
||||||
SopCLI.main(new String[] {"verify", signature.getAbsolutePath(), cert.getAbsolutePath()});
|
SopCLI.main(new String[] {"verify", signature.getAbsolutePath(), cert.getAbsolutePath()});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(3)
|
@ExpectSystemExitWithStatus(SOPGPException.NoSignature.EXIT_CODE)
|
||||||
public void data_noSignaturesCausesExit3() throws SOPGPException.NoSignature, IOException, SOPGPException.BadData {
|
public void data_noSignaturesCausesExit3() throws SOPGPException.NoSignature, IOException, SOPGPException.BadData {
|
||||||
when(detachedVerify.data((InputStream) any())).thenThrow(new SOPGPException.NoSignature());
|
when(detachedVerify.data((InputStream) any())).thenThrow(new SOPGPException.NoSignature());
|
||||||
SopCLI.main(new String[] {"verify", signature.getAbsolutePath(), cert.getAbsolutePath()});
|
SopCLI.main(new String[] {"verify", signature.getAbsolutePath(), cert.getAbsolutePath()});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(41)
|
@ExpectSystemExitWithStatus(SOPGPException.BadData.EXIT_CODE)
|
||||||
public void data_badDataCausesExit41() throws SOPGPException.NoSignature, IOException, SOPGPException.BadData {
|
public void data_badDataCausesExit41() throws SOPGPException.NoSignature, IOException, SOPGPException.BadData {
|
||||||
when(detachedVerify.data((InputStream) any())).thenThrow(new SOPGPException.BadData(new IOException()));
|
when(detachedVerify.data((InputStream) any())).thenThrow(new SOPGPException.BadData(new IOException()));
|
||||||
SopCLI.main(new String[] {"verify", signature.getAbsolutePath(), cert.getAbsolutePath()});
|
SopCLI.main(new String[] {"verify", signature.getAbsolutePath(), cert.getAbsolutePath()});
|
||||||
|
|
|
@ -14,6 +14,7 @@ import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import sop.SOP;
|
import sop.SOP;
|
||||||
import sop.cli.picocli.SopCLI;
|
import sop.cli.picocli.SopCLI;
|
||||||
|
import sop.exception.SOPGPException;
|
||||||
import sop.operation.Version;
|
import sop.operation.Version;
|
||||||
|
|
||||||
public class VersionCmdTest {
|
public class VersionCmdTest {
|
||||||
|
@ -53,7 +54,7 @@ public class VersionCmdTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ExpectSystemExitWithStatus(37)
|
@ExpectSystemExitWithStatus(SOPGPException.UnsupportedOption.EXIT_CODE)
|
||||||
public void assertInvalidOptionResultsInExit37() {
|
public void assertInvalidOptionResultsInExit37() {
|
||||||
SopCLI.main(new String[] {"version", "--invalid"});
|
SopCLI.main(new String[] {"version", "--invalid"});
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ public abstract class SOPGPException extends RuntimeException {
|
||||||
public abstract int getExitCode();
|
public abstract int getExitCode();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* No acceptable signatures found (sop verify).
|
* No acceptable signatures found (sop verify, inline-verify).
|
||||||
*/
|
*/
|
||||||
public static class NoSignature extends SOPGPException {
|
public static class NoSignature extends SOPGPException {
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ public abstract class SOPGPException extends RuntimeException {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asymmetric algorithm unsupported (sop encrypt).
|
* Asymmetric algorithm unsupported (sop encrypt, sign, inline-sign).
|
||||||
*/
|
*/
|
||||||
public static class UnsupportedAsymmetricAlgo extends SOPGPException {
|
public static class UnsupportedAsymmetricAlgo extends SOPGPException {
|
||||||
|
|
||||||
|
@ -250,6 +250,10 @@ public abstract class SOPGPException extends RuntimeException {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public KeyIsProtected(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
public KeyIsProtected(String message, Throwable cause) {
|
public KeyIsProtected(String message, Throwable cause) {
|
||||||
super(message, cause);
|
super(message, cause);
|
||||||
}
|
}
|
||||||
|
@ -295,8 +299,10 @@ public abstract class SOPGPException extends RuntimeException {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A indirect input parameter is a special designator (it starts with @),
|
* Exception that gets thrown if a special designator (starting with @) is given, but the filesystem contains
|
||||||
* and a filename matching the designator is actually present.
|
* a file matching the designator.
|
||||||
|
*
|
||||||
|
* E.g. <pre>@ENV:FOO</pre> is given, but <pre>./@ENV:FOO</pre> exists on the filesystem.
|
||||||
*/
|
*/
|
||||||
public static class AmbiguousInput extends SOPGPException {
|
public static class AmbiguousInput extends SOPGPException {
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue