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));
}
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);
}
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:");
}
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();
}
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);
}
}
Aggregations