Search in sources :

Example 31 with CliResult

use of com.quorum.tessera.cli.CliResult in project tessera by ConsenSys.

the class PicoCliDelegateTest method keygenNoArgsPrintsHelp.

@Test
public void keygenNoArgsPrintsHelp() throws Exception {
    final CliResult result = cliDelegate.execute("keygen");
    final String sysout = systemOutOutput.getLog();
    final String syserr = systemErrOutput.getLog();
    assertThat(result).isNotNull();
    assertThat(result.getConfig()).isNotPresent();
    assertThat(result.getStatus()).isEqualTo(0);
    assertThat(result.isSuppressStartup()).isTrue();
    assertThat(syserr).isEmpty();
    assertThat(sysout).isNotEmpty();
    assertThat(sysout).contains("Usage: tessera keygen [OPTIONS] [COMMAND]", "Description:", "Options:", "Commands:");
}
Also used : CliResult(com.quorum.tessera.cli.CliResult) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 32 with CliResult

use of com.quorum.tessera.cli.CliResult in project tessera by ConsenSys.

the class PicoCliDelegateTest method withValidConfig.

@Test
public void withValidConfig() throws Exception {
    Path configFile = Paths.get(getClass().getResource("/sample-config.json").toURI());
    CliResult result = cliDelegate.execute("-configfile", configFile.toString());
    assertThat(result).isNotNull();
    assertThat(result.getConfig()).isPresent();
    assertThat(result.getStatus()).isEqualTo(0);
    assertThat(result.isSuppressStartup()).isFalse();
}
Also used : Path(java.nio.file.Path) CliResult(com.quorum.tessera.cli.CliResult) Test(org.junit.Test)

Example 33 with CliResult

use of com.quorum.tessera.cli.CliResult in project tessera by ConsenSys.

the class PicoCliDelegateTest method keyupdateHelp.

@Test
public void keyupdateHelp() throws Exception {
    final CliResult result = cliDelegate.execute("keyupdate", "help");
    final String sysout = systemOutOutput.getLog();
    final String syserr = systemErrOutput.getLog();
    assertThat(result).isNotNull();
    assertThat(result.getConfig()).isNotPresent();
    assertThat(result.getStatus()).isEqualTo(0);
    assertThat(result.isSuppressStartup()).isTrue();
    assertThat(syserr).isEmpty();
    assertThat(sysout).isNotEmpty();
    assertThat(sysout).contains("Usage: tessera keyupdate [OPTIONS] [COMMAND]", "Description:", "Options:", "Commands:");
}
Also used : CliResult(com.quorum.tessera.cli.CliResult) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 34 with CliResult

use of com.quorum.tessera.cli.CliResult in project tessera by ConsenSys.

the class KeyGenCommandTest method noArgsProvided.

@Test
public void noArgsProvided() throws Exception {
    ConfigKeyPair configKeyPair = mock(ConfigKeyPair.class);
    when(keyGenerator.generate("", null, null)).thenReturn(configKeyPair);
    when(keyGeneratorFactory.create(refEq(null), any(EncryptorConfig.class))).thenReturn(keyGenerator);
    int exitCode = commandLine.execute();
    assertThat(exitCode).isZero();
    CommandLine.ParseResult parseResult = commandLine.getParseResult();
    assertThat(parseResult).isNotNull();
    assertThat(parseResult.matchedArgs()).isEmpty();
    assertThat(parseResult.unmatched()).isEmpty();
    CliResult result = commandLine.getExecutionResult();
    assertThat(result).isNotNull();
    assertThat(result.isSuppressStartup()).isTrue();
    assertThat(result.getConfig()).isNotPresent();
    assertThat(result.getStatus()).isEqualTo(0);
    verify(keyDataMarshaller).marshal(configKeyPair);
    verify(keyGeneratorFactory).create(refEq(null), any(EncryptorConfig.class));
    verify(keyGenerator).generate("", null, null);
}
Also used : CommandLine(picocli.CommandLine) CliResult(com.quorum.tessera.cli.CliResult) ConfigKeyPair(com.quorum.tessera.config.keypairs.ConfigKeyPair) Test(org.junit.Test)

Example 35 with CliResult

use of com.quorum.tessera.cli.CliResult in project tessera by ConsenSys.

the class KeyGenCommandTest method onlyMulipleOutputFilesProvided.

@Test
public void onlyMulipleOutputFilesProvided() throws Exception {
    List<String> optionVariations = List.of("--keyout", "-filename");
    List<String> valueVariations = List.of("myfile", "myotherfile", "yetanother");
    ConfigKeyPair configKeyPair = mock(ConfigKeyPair.class);
    valueVariations.forEach(filename -> {
        when(keyGenerator.generate(filename, null, null)).thenReturn(configKeyPair);
    });
    when(keyGeneratorFactory.create(refEq(null), any(EncryptorConfig.class))).thenReturn(keyGenerator);
    for (String option : optionVariations) {
        String arg = option.concat("=").concat(String.join(",", valueVariations));
        int exitCode = commandLine.execute(arg);
        assertThat(exitCode).isZero();
        CommandLine.ParseResult parseResult = commandLine.getParseResult();
        assertThat(parseResult).isNotNull();
        assertThat(parseResult.matchedArgs()).hasSize(1);
        assertThat(parseResult.hasMatchedOption(option));
        assertThat(parseResult.unmatched()).isEmpty();
        CliResult result = commandLine.getExecutionResult();
        assertThat(result).isNotNull();
        assertThat(result.isSuppressStartup()).isTrue();
        assertThat(result.getConfig()).isNotPresent();
    }
    verify(keyDataMarshaller, times(optionVariations.size() * valueVariations.size())).marshal(configKeyPair);
    verify(keyGeneratorFactory, times(optionVariations.size())).create(refEq(null), any(EncryptorConfig.class));
    valueVariations.forEach(filename -> {
        verify(keyGenerator, times(optionVariations.size())).generate(filename, null, null);
    });
}
Also used : CommandLine(picocli.CommandLine) CliResult(com.quorum.tessera.cli.CliResult) ConfigKeyPair(com.quorum.tessera.config.keypairs.ConfigKeyPair) Test(org.junit.Test)

Aggregations

CliResult (com.quorum.tessera.cli.CliResult)38 Test (org.junit.Test)29 Path (java.nio.file.Path)15 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)10 CommandLine (picocli.CommandLine)9 CliException (com.quorum.tessera.cli.CliException)7 ConstraintViolationException (jakarta.validation.ConstraintViolationException)7 FilesystemKeyPair (com.quorum.tessera.config.keypairs.FilesystemKeyPair)6 Config (com.quorum.tessera.config.Config)5 ConfigConverter (com.quorum.tessera.cli.parsers.ConfigConverter)4 ConfigKeyPair (com.quorum.tessera.config.keypairs.ConfigKeyPair)4 KeyDataConfig (com.quorum.tessera.config.KeyDataConfig)3 KeyEncryptor (com.quorum.tessera.config.keys.KeyEncryptor)3 ConstraintViolation (jakarta.validation.ConstraintViolation)3 UncheckedIOException (java.io.UncheckedIOException)3 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)3 HashMap (java.util.HashMap)3 Enclave (com.quorum.tessera.enclave.Enclave)2 EnclaveCliAdapter (com.quorum.tessera.enclave.server.EnclaveCliAdapter)2 TesseraServer (com.quorum.tessera.server.TesseraServer)2