Search in sources :

Example 6 with KeyConfiguration

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

the class KeyConfigurationValidatorTest method fileSetIsValid.

@Test
public void fileSetIsValid() {
    final KeyConfiguration configuration = new KeyConfiguration(Paths.get("anything"), null, null, null, null);
    assertThat(validator.isValid(configuration, mock(ConstraintValidatorContext.class))).isTrue();
}
Also used : KeyConfiguration(com.quorum.tessera.config.KeyConfiguration) ConstraintValidatorContext(jakarta.validation.ConstraintValidatorContext) Test(org.junit.Test)

Example 7 with KeyConfiguration

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

the class KeyConfigurationValidatorTest method bothSetIsInvalid.

@Test
public void bothSetIsInvalid() {
    final KeyConfiguration configuration = new KeyConfiguration(Paths.get("anything"), emptyList(), null, null, null);
    assertThat(validator.isValid(configuration, mock(ConstraintValidatorContext.class))).isFalse();
}
Also used : KeyConfiguration(com.quorum.tessera.config.KeyConfiguration) ConstraintValidatorContext(jakarta.validation.ConstraintValidatorContext) Test(org.junit.Test)

Example 8 with KeyConfiguration

use of com.quorum.tessera.config.KeyConfiguration 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 9 with KeyConfiguration

use of com.quorum.tessera.config.KeyConfiguration 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)

Aggregations

KeyConfiguration (com.quorum.tessera.config.KeyConfiguration)9 Test (org.junit.Test)9 ConstraintValidatorContext (jakarta.validation.ConstraintValidatorContext)4 Config (com.quorum.tessera.config.Config)3 ConstraintViolation (jakarta.validation.ConstraintViolation)2 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 DefaultKeyVaultConfig (com.quorum.tessera.config.DefaultKeyVaultConfig)1 KeyData (com.quorum.tessera.config.KeyData)1 KeyVaultConfig (com.quorum.tessera.config.KeyVaultConfig)1 AzureVaultKeyPair (com.quorum.tessera.config.keypairs.AzureVaultKeyPair)1 ConfigKeyPair (com.quorum.tessera.config.keypairs.ConfigKeyPair)1 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)1