Search in sources :

Example 66 with Config

use of com.quorum.tessera.config.Config in project tessera by ConsenSys.

the class PasswordFileUpdaterWriterTest method configContainsPasswordListThrowsException.

@Test
public void configContainsPasswordListThrowsException() {
    final Config config = mock(Config.class);
    final KeyConfiguration keyConfiguration = mock(KeyConfiguration.class);
    when(config.getKeys()).thenReturn(keyConfiguration);
    when(keyConfiguration.getPasswords()).thenReturn(Collections.singletonList("pwd"));
    final Throwable ex = catchThrowable(() -> writer.updateAndWrite(null, config, null));
    assertThat(ex).isExactlyInstanceOf(ConfigException.class);
    assertThat(ex.getMessage()).contains("Configfile must contain \"passwordFile\" field. The \"passwords\" field is no longer supported.");
}
Also used : KeyConfiguration(com.quorum.tessera.config.KeyConfiguration) Config(com.quorum.tessera.config.Config) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Test(org.junit.Test)

Example 67 with Config

use of com.quorum.tessera.config.Config in project tessera by ConsenSys.

the class PasswordFileUpdaterWriterTest method passwordFileAlreadyExists.

@Test
public void passwordFileAlreadyExists() {
    final Config config = mock(Config.class);
    final Path pwdFile = mock(Path.class);
    final String path = "somepath";
    when(pwdFile.toString()).thenReturn(path);
    when(filesDelegate.exists(pwdFile)).thenReturn(true);
    final Throwable ex = catchThrowable(() -> writer.updateAndWrite(null, config, pwdFile));
    assertThat(ex).isExactlyInstanceOf(FileAlreadyExistsException.class);
    assertThat(ex.getMessage()).contains(path);
    verify(filesDelegate).exists(pwdFile);
}
Also used : Path(java.nio.file.Path) Config(com.quorum.tessera.config.Config) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Test(org.junit.Test)

Example 68 with Config

use of com.quorum.tessera.config.Config in project tessera by ConsenSys.

the class PasswordFileUpdaterWriterTest method newPasswordsWrittenToNewFileIncludingEmptyLinesForExistingKeys.

@Test
public void newPasswordsWrittenToNewFileIncludingEmptyLinesForExistingKeys() throws Exception {
    final Config config = mock(Config.class);
    final KeyConfiguration keyConfiguration = mock(KeyConfiguration.class);
    final List<KeyData> existingKeys = Arrays.asList(mock(KeyData.class), mock(KeyData.class));
    when(config.getKeys()).thenReturn(keyConfiguration);
    when(keyConfiguration.getKeyData()).thenReturn(existingKeys);
    final Path pwdFile = mock(Path.class);
    final String path = "somepath";
    when(pwdFile.toString()).thenReturn(path);
    final List<String> existingAndNewPasswords = new ArrayList<>(Arrays.asList("", "", "pwd1", "pwd2"));
    final List<char[]> newPasswords = new ArrayList<>(Arrays.asList("pwd1".toCharArray(), "pwd2".toCharArray()));
    writer.updateAndWrite(newPasswords, config, pwdFile);
    verify(filesDelegate).exists(pwdFile);
    verify(filesDelegate).createFile(pwdFile);
    verify(filesDelegate).setPosixFilePermissions(pwdFile, Stream.of(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE).collect(Collectors.toSet()));
    verify(filesDelegate).write(pwdFile, existingAndNewPasswords, APPEND);
}
Also used : Path(java.nio.file.Path) KeyConfiguration(com.quorum.tessera.config.KeyConfiguration) Config(com.quorum.tessera.config.Config) ArrayList(java.util.ArrayList) KeyData(com.quorum.tessera.config.KeyData) Test(org.junit.Test)

Example 69 with Config

use of com.quorum.tessera.config.Config in project tessera by ConsenSys.

the class ServerConfigsValidatorTest method isNotValidWhenNoP2PServersAreDefined.

@Test
public void isNotValidWhenNoP2PServersAreDefined() {
    List<ServerConfig> serverConfigList = serverConfigList().stream().filter(s -> s.getApp() != AppType.P2P).collect(Collectors.toList());
    Config config = new Config();
    config.setServerConfigs(serverConfigList);
    assertThat(validator.isValid(config, cvc)).isFalse();
    verify(cvc).disableDefaultConstraintViolation();
    verify(cvc).buildConstraintViolationWithTemplate(eq("Exactly one P2P server must be configured."));
}
Also used : AppType(com.quorum.tessera.config.AppType) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ConstraintValidatorContext(jakarta.validation.ConstraintValidatorContext) HashMap(java.util.HashMap) Test(org.junit.Test) ServerConfig(com.quorum.tessera.config.ServerConfig) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Mockito(org.mockito.Mockito) CommunicationType(com.quorum.tessera.config.CommunicationType) List(java.util.List) Map(java.util.Map) After(org.junit.After) Config(com.quorum.tessera.config.Config) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Before(org.junit.Before) ServerConfig(com.quorum.tessera.config.ServerConfig) ServerConfig(com.quorum.tessera.config.ServerConfig) Config(com.quorum.tessera.config.Config) Test(org.junit.Test)

Example 70 with Config

use of com.quorum.tessera.config.Config in project tessera by ConsenSys.

the class ServerConfigsValidatorTest method isNotValidWhenTwoOrMoreP2PServersAreDefinedAndEnabled.

@Test
public void isNotValidWhenTwoOrMoreP2PServersAreDefinedAndEnabled() {
    List<ServerConfig> serverConfigList = serverConfigList();
    serverConfigList.add(serverConfigsMap.get(AppType.P2P));
    Config config = new Config();
    config.setServerConfigs(serverConfigList);
    assertThat(validator.isValid(config, cvc)).isFalse();
    verify(cvc).disableDefaultConstraintViolation();
    verify(cvc).buildConstraintViolationWithTemplate(eq("Exactly one P2P server must be configured."));
}
Also used : ServerConfig(com.quorum.tessera.config.ServerConfig) ServerConfig(com.quorum.tessera.config.ServerConfig) Config(com.quorum.tessera.config.Config) Test(org.junit.Test)

Aggregations

Config (com.quorum.tessera.config.Config)78 Test (org.junit.Test)54 ServerConfig (com.quorum.tessera.config.ServerConfig)20 ConfigFactory (com.quorum.tessera.config.ConfigFactory)18 Path (java.nio.file.Path)11 Before (org.junit.Before)11 ResidentGroup (com.quorum.tessera.config.ResidentGroup)9 ClientFactory (com.quorum.tessera.jaxrs.client.ClientFactory)9 EntityManagerFactory (jakarta.persistence.EntityManagerFactory)9 Client (jakarta.ws.rs.client.Client)9 JdbcConfig (com.quorum.tessera.config.JdbcConfig)7 Map (java.util.Map)7 Collectors (java.util.stream.Collectors)7 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)7 After (org.junit.After)7 CommandLine (picocli.CommandLine)7 PrivacyViolationException (com.quorum.tessera.transaction.exception.PrivacyViolationException)6 CliResult (com.quorum.tessera.cli.CliResult)5 EncryptorConfig (com.quorum.tessera.config.EncryptorConfig)5 PublicKey (com.quorum.tessera.encryption.PublicKey)5