use of com.quorum.tessera.config.keypairs.FilesystemKeyPair in project tessera by ConsenSys.
the class PicoCliDelegateTest method keygenUpdateConfig.
@Test
public void keygenUpdateConfig() 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");
assertThat(Files.exists(configOutputPath)).isFalse();
CliResult result = cliDelegate.execute("-keygen", "-filename", keyOutputPath.toString(), "-output", configOutputPath.toString(), "-configfile", configFile.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();
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);
}
}
use of com.quorum.tessera.config.keypairs.FilesystemKeyPair 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.config.keypairs.FilesystemKeyPair 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.config.keypairs.FilesystemKeyPair 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);
}
}
use of com.quorum.tessera.config.keypairs.FilesystemKeyPair in project tessera by ConsenSys.
the class FileKeyGeneratorTest method providingPathSavesToFile.
@Test
public void providingPathSavesToFile() throws IOException {
final Path tempFolder = Files.createTempDirectory(UUID.randomUUID().toString());
final String keyFilesName = tempFolder.resolve("providingPathSavesToFile").toString();
doReturn(keyPair).when(encryptor).generateNewKeys();
final FilesystemKeyPair generated = generator.generate(keyFilesName, null, null);
assertThat(Files.exists(tempFolder.resolve("providingPathSavesToFile.pub"))).isTrue();
assertThat(Files.exists(tempFolder.resolve("providingPathSavesToFile.key"))).isTrue();
verify(encryptor).generateNewKeys();
}
Aggregations