Search in sources :

Example 6 with FilesystemKeyPair

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);
    }
}
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)

Example 7 with FilesystemKeyPair

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));
}
Also used : FilesystemKeyPair(com.quorum.tessera.config.keypairs.FilesystemKeyPair) CliResult(com.quorum.tessera.cli.CliResult) Test(org.junit.Test)

Example 8 with FilesystemKeyPair

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);
}
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 9 with FilesystemKeyPair

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);
    }
}
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)

Example 10 with FilesystemKeyPair

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();
}
Also used : Path(java.nio.file.Path) FilesystemKeyPair(com.quorum.tessera.config.keypairs.FilesystemKeyPair) Test(org.junit.Test)

Aggregations

FilesystemKeyPair (com.quorum.tessera.config.keypairs.FilesystemKeyPair)11 Test (org.junit.Test)10 Path (java.nio.file.Path)8 CliResult (com.quorum.tessera.cli.CliResult)6 KeyEncryptor (com.quorum.tessera.config.keys.KeyEncryptor)3 HashMap (java.util.HashMap)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 CliException (com.quorum.tessera.cli.CliException)2 KeyDataConfig (com.quorum.tessera.config.KeyDataConfig)2 PrivateKeyData (com.quorum.tessera.config.PrivateKeyData)2 ConstraintViolationException (jakarta.validation.ConstraintViolationException)2 UncheckedIOException (java.io.UncheckedIOException)2 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)2 ArgonOptions (com.quorum.tessera.config.ArgonOptions)1 KeyData (com.quorum.tessera.config.KeyData)1 KeyPair (com.quorum.tessera.encryption.KeyPair)1 PrivateKey (com.quorum.tessera.encryption.PrivateKey)1