use of com.quorum.tessera.config.KeyConfiguration in project tessera by ConsenSys.
the class KeyConfigurationValidatorTest method inlineSetIsValid.
@Test
public void inlineSetIsValid() {
final KeyConfiguration configuration = new KeyConfiguration(null, emptyList(), null, null, null);
assertThat(validator.isValid(configuration, mock(ConstraintValidatorContext.class))).isTrue();
}
use of com.quorum.tessera.config.KeyConfiguration 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);
}
use of com.quorum.tessera.config.KeyConfiguration in project tessera by ConsenSys.
the class DefaultKeyVaultConfigValidationsTest method validCase.
@Test
public void validCase() {
KeyConfiguration keyConfiguration = mock(KeyConfiguration.class);
// Not ideal. Having to use config object in tests to apply validation rules.
KeyVaultConfig keyVaultConfig = new DefaultKeyVaultConfig() {
{
setKeyVaultType(KeyVaultType.AZURE);
}
};
List<KeyVaultConfig> keyVaultConfigList = Arrays.asList(mock(KeyVaultConfig.class));
when(keyConfiguration.getKeyVaultConfigs()).thenReturn(keyVaultConfigList);
ConfigKeyPair keyPair = new AzureVaultKeyPair("publicKeyId", "privateKeyId", null, null);
List<ConfigKeyPair> keyPairs = Arrays.asList(keyPair);
Set<ConstraintViolation<?>> results = validator.validate(keyConfiguration, keyPairs);
assertThat(results).isEmpty();
}
use of com.quorum.tessera.config.KeyConfiguration in project tessera by ConsenSys.
the class DefaultKeyVaultConfigValidationsTest method noKeyVaultConfigsReturnsEmptySet.
@Test
public void noKeyVaultConfigsReturnsEmptySet() {
KeyConfiguration keyConfiguration = new KeyConfiguration();
Set<ConstraintViolation<?>> results = validator.validate(keyConfiguration, null);
assertThat(results).isEmpty();
}
use of com.quorum.tessera.config.KeyConfiguration in project tessera by ConsenSys.
the class KeyConfigurationValidatorTest method bothNotSetIsValid.
@Test
public void bothNotSetIsValid() {
final KeyConfiguration configuration = new KeyConfiguration(null, null, null, null, null);
assertThat(validator.isValid(configuration, mock(ConstraintValidatorContext.class))).isTrue();
}
Aggregations