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