Search in sources :

Example 1 with Config

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

the class PasswordFileUpdaterWriterTest method newPasswordsAppendedToExistingPasswordsAndWrittenToFile.

@Test
public void newPasswordsAppendedToExistingPasswordsAndWrittenToFile() throws Exception {
    final Config config = mock(Config.class);
    final KeyConfiguration keyConfiguration = mock(KeyConfiguration.class);
    final Path existingPwdFile = mock(Path.class);
    when(config.getKeys()).thenReturn(keyConfiguration);
    when(keyConfiguration.getPasswordFile()).thenReturn(existingPwdFile);
    final Path pwdFile = mock(Path.class);
    final String path = "somepath";
    when(pwdFile.toString()).thenReturn(path);
    final List<String> existingPasswords = new ArrayList<>(Arrays.asList("pwd1", "pwd2"));
    final List<String> existingAndNewPasswords = new ArrayList<>(Arrays.asList("pwd1", "pwd2", "pwd3", "pwd4"));
    final List<char[]> newPasswords = new ArrayList<>(Arrays.asList("pwd3".toCharArray(), "pwd4".toCharArray()));
    when(filesDelegate.readAllLines(any())).thenReturn(existingPasswords);
    writer.updateAndWrite(newPasswords, config, pwdFile);
    verify(filesDelegate).readAllLines(existingPwdFile);
    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) Test(org.junit.Test)

Example 2 with Config

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

the class ServerConfigsValidatorTest method isValidWhenServerConfigsIsNull.

@Test
public void isValidWhenServerConfigsIsNull() {
    Config config = new Config();
    config.setServerConfigs(null);
    assertThat(validator.isValid(config, cvc)).isTrue();
}
Also used : ServerConfig(com.quorum.tessera.config.ServerConfig) Config(com.quorum.tessera.config.Config) Test(org.junit.Test)

Example 3 with Config

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

the class ServerConfigsValidatorTest method isNotValidWhenNoQ2TServersAreDefined.

@Test
public void isNotValidWhenNoQ2TServersAreDefined() {
    List<ServerConfig> serverConfigList = serverConfigList().stream().filter(s -> s.getApp() != AppType.Q2T).collect(Collectors.toList());
    Config config = new Config();
    config.setServerConfigs(serverConfigList);
    assertThat(validator.isValid(config, cvc)).isFalse();
    verify(cvc).disableDefaultConstraintViolation();
    verify(cvc).buildConstraintViolationWithTemplate(eq("At least one Q2T server must be configured or bootstrap mode enabled."));
}
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 4 with Config

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

the class ServerConfigsValidatorTest method isNotValidWhenQ2TServersAreDefinedOnBootstrapNode.

@Test
public void isNotValidWhenQ2TServersAreDefinedOnBootstrapNode() {
    List<ServerConfig> serverConfigList = serverConfigList();
    Config config = new Config();
    config.setBootstrapNode(true);
    config.setServerConfigs(serverConfigList);
    assertThat(validator.isValid(config, cvc)).isFalse();
    verify(cvc).disableDefaultConstraintViolation();
    verify(cvc).buildConstraintViolationWithTemplate(eq("Q2T server cannot be specified on a bootstrap node."));
}
Also used : ServerConfig(com.quorum.tessera.config.ServerConfig) ServerConfig(com.quorum.tessera.config.ServerConfig) Config(com.quorum.tessera.config.Config) Test(org.junit.Test)

Example 5 with Config

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

the class ServerConfigsValidatorTest method isValidWhenValidDataIsSupplied.

@Test
public void isValidWhenValidDataIsSupplied() {
    List<ServerConfig> serverConfigList = serverConfigList();
    Config config = new Config();
    config.setServerConfigs(serverConfigList);
    assertThat(validator.isValid(config, cvc)).isTrue();
}
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