1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-09-14 12:49:39 +02:00

SOP commands: Throw UnsupportedSubcommand error when sop.command() returns null

This commit is contained in:
Paul Schaub 2022-01-09 02:04:12 +01:00
parent 1c2cbf0e75
commit 1aca7112d2
12 changed files with 127 additions and 10 deletions

View file

@ -4,11 +4,26 @@
package sop.cli.picocli;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.ginsberg.junit.exit.ExpectSystemExitWithStatus;
import org.junit.jupiter.api.Test;
import sop.SOP;
import sop.operation.Armor;
import sop.operation.Dearmor;
import sop.operation.Decrypt;
import sop.operation.DetachInbandSignatureAndMessage;
import sop.operation.Encrypt;
import sop.operation.ExtractCert;
import sop.operation.GenerateKey;
import sop.operation.Sign;
import sop.operation.Verify;
import sop.operation.Version;
public class SOPTest {
@ -28,4 +43,77 @@ public class SOPTest {
// At this point, no SOP backend is set, so an InvalidStateException triggers exit(1)
SopCLI.main(new String[] {"armor"});
}
@Test
public void UnsupportedSubcommandsTest() {
SOP nullCommandSOP = new SOP() {
@Override
public Version version() {
return null;
}
@Override
public GenerateKey generateKey() {
return null;
}
@Override
public ExtractCert extractCert() {
return null;
}
@Override
public Sign sign() {
return null;
}
@Override
public Verify verify() {
return null;
}
@Override
public Encrypt encrypt() {
return null;
}
@Override
public Decrypt decrypt() {
return null;
}
@Override
public Armor armor() {
return null;
}
@Override
public Dearmor dearmor() {
return null;
}
@Override
public DetachInbandSignatureAndMessage detachInbandSignatureAndMessage() {
return null;
}
};
SopCLI.setSopInstance(nullCommandSOP);
List<String[]> commands = new ArrayList<>();
commands.add(new String[] {"armor"});
commands.add(new String[] {"dearmor"});
commands.add(new String[] {"decrypt"});
commands.add(new String[] {"detach-inband-signature-and-message"});
commands.add(new String[] {"encrypt"});
commands.add(new String[] {"extract-cert"});
commands.add(new String[] {"generate-key"});
commands.add(new String[] {"sign"});
commands.add(new String[] {"verify", "signature.asc", "cert.asc"});
commands.add(new String[] {"version"});
for (String[] command : commands) {
int exit = SopCLI.execute(command);
assertEquals(69, exit, "Unexpected exit code for non-implemented command " + Arrays.toString(command) + ": " + exit);
}
}
}