Search in sources :

Example 26 with CliResult

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

the class PicoCliDelegateTest method keygen.

@Test
public void keygen() throws Exception {
    FilesystemKeyPair keypair = mock(FilesystemKeyPair.class);
    when(keyGenerator.generate(anyString(), eq(null), eq(null))).thenReturn(keypair);
    CliResult result = cliDelegate.execute("-keygen", "-filename", UUID.randomUUID().toString());
    assertThat(result).isNotNull();
    assertThat(result.getStatus()).isEqualTo(0);
    assertThat(result.getConfig()).isNotNull();
    assertThat(result.isSuppressStartup()).isTrue();
    verify(keyGenerator).generate(anyString(), eq(null), eq(null));
}
Also used : FilesystemKeyPair(com.quorum.tessera.config.keypairs.FilesystemKeyPair) CliResult(com.quorum.tessera.cli.CliResult) Test(org.junit.Test)

Example 27 with CliResult

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

the class PicoCliDelegateTest method keygenOutputToCLI.

@Test
public void keygenOutputToCLI() throws Exception {
    Path publicKeyPath = Files.createTempFile(UUID.randomUUID().toString(), "");
    Path privateKeyPath = Files.createTempFile(UUID.randomUUID().toString(), "");
    Files.write(privateKeyPath, Arrays.asList("SOMEDATA"));
    Files.write(publicKeyPath, Arrays.asList("SOMEDATA"));
    KeyEncryptor keyEncryptor = mock(KeyEncryptor.class);
    FilesystemKeyPair keypair = new FilesystemKeyPair(publicKeyPath, privateKeyPath, keyEncryptor);
    when(keyGenerator.generate(anyString(), eq(null), eq(null))).thenReturn(keypair);
    Path unixSocketPath = Files.createTempFile(UUID.randomUUID().toString(), ".ipc");
    Map<String, Object> params = new HashMap<>();
    params.put("unixSocketPath", unixSocketPath.toString());
    Path configFile = Paths.get(getClass().getResource("/keygen-sample.json").toURI());
    Path keyOutputPath = configFile.resolveSibling(UUID.randomUUID().toString());
    CliResult result = cliDelegate.execute("-keygen", "-filename", keyOutputPath.toString(), "-configfile", configFile.toString());
    assertThat(result).isNotNull();
    assertThat(result.getStatus()).isEqualTo(0);
    assertThat(result.getConfig()).isNotNull();
    assertThat(result.isSuppressStartup()).isTrue();
    verify(keyGenerator).generate(anyString(), eq(null), eq(null));
    verifyNoMoreInteractions(keyGenerator);
}
Also used : Path(java.nio.file.Path) FilesystemKeyPair(com.quorum.tessera.config.keypairs.FilesystemKeyPair) HashMap(java.util.HashMap) CliResult(com.quorum.tessera.cli.CliResult) KeyEncryptor(com.quorum.tessera.config.keys.KeyEncryptor) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 28 with CliResult

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

the class PicoCliDelegateTest method noArgsPrintsHelp.

@Test
public void noArgsPrintsHelp() throws Exception {
    final CliResult result = cliDelegate.execute();
    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 [OPTIONS] [COMMAND]", "Description:", "Options:", "Commands:");
}
Also used : CliResult(com.quorum.tessera.cli.CliResult) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 29 with CliResult

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

the class PicoCliDelegateTest method withValidConfigAndPidfile.

@Test
public void withValidConfigAndPidfile() throws Exception {
    Path configFile = Paths.get(getClass().getResource("/sample-config.json").toURI());
    String tempDir = System.getProperty("java.io.tmpdir");
    Path pidFilePath = Paths.get(tempDir, UUID.randomUUID().toString());
    assertThat(pidFilePath).doesNotExist();
    CliResult result = cliDelegate.execute("-configfile", configFile.toString(), "-pidfile", pidFilePath.toString());
    assertThat(pidFilePath).exists();
    pidFilePath.toFile().deleteOnExit();
    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) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 30 with CliResult

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

the class PicoCliDelegateTest method keygenUpdateConfigAndPasswordFile.

@Test
public void keygenUpdateConfigAndPasswordFile() throws Exception {
    Path publicKeyPath = Files.createTempFile(UUID.randomUUID().toString(), "");
    Path privateKeyPath = Files.createTempFile(UUID.randomUUID().toString(), "");
    Files.write(privateKeyPath, Arrays.asList("SOMEDATA"));
    Files.write(publicKeyPath, Arrays.asList("SOMEDATA"));
    KeyEncryptor keyEncryptor = mock(KeyEncryptor.class);
    FilesystemKeyPair keypair = new FilesystemKeyPair(publicKeyPath, privateKeyPath, keyEncryptor);
    when(keyGenerator.generate(anyString(), eq(null), eq(null))).thenReturn(keypair);
    Path unixSocketPath = Files.createTempFile(UUID.randomUUID().toString(), ".ipc");
    Map<String, Object> params = new HashMap<>();
    params.put("unixSocketPath", unixSocketPath.toString());
    Path configFile = Paths.get(getClass().getResource("/keygen-sample.json").toURI());
    Path keyOutputPath = configFile.resolveSibling(UUID.randomUUID().toString());
    Path configOutputPath = configFile.resolveSibling(UUID.randomUUID().toString() + ".json");
    Path pwdOutputPath = configFile.resolveSibling(UUID.randomUUID().toString() + ".pwds");
    assertThat(Files.exists(configOutputPath)).isFalse();
    assertThat(Files.exists(pwdOutputPath)).isFalse();
    CliResult result = cliDelegate.execute("-keygen", "-filename", keyOutputPath.toString(), "-output", configOutputPath.toString(), "-configfile", configFile.toString(), "--pwdout", pwdOutputPath.toString());
    assertThat(result).isNotNull();
    assertThat(result.getStatus()).isEqualTo(0);
    assertThat(result.getConfig()).isNotNull();
    assertThat(result.isSuppressStartup()).isTrue();
    assertThat(Files.exists(configOutputPath)).isTrue();
    configOutputPath.toFile().deleteOnExit();
    assertThat(Files.exists(pwdOutputPath)).isTrue();
    pwdOutputPath.toFile().deleteOnExit();
    verify(keyGenerator).generate(anyString(), eq(null), eq(null));
    verifyNoMoreInteractions(keyGenerator);
    try {
        cliDelegate.execute("-keygen", "-filename", UUID.randomUUID().toString(), "-output", configOutputPath.toString(), "-configfile", configFile.toString());
        failBecauseExceptionWasNotThrown(Exception.class);
    } catch (Exception ex) {
        assertThat(ex).isInstanceOf(UncheckedIOException.class);
        assertThat(ex.getCause()).isExactlyInstanceOf(FileAlreadyExistsException.class);
    }
}
Also used : Path(java.nio.file.Path) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) FilesystemKeyPair(com.quorum.tessera.config.keypairs.FilesystemKeyPair) HashMap(java.util.HashMap) CliResult(com.quorum.tessera.cli.CliResult) KeyEncryptor(com.quorum.tessera.config.keys.KeyEncryptor) UncheckedIOException(java.io.UncheckedIOException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CliException(com.quorum.tessera.cli.CliException) ConstraintViolationException(jakarta.validation.ConstraintViolationException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) UncheckedIOException(java.io.UncheckedIOException) 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