Search in sources :

Example 1 with KeyConfiguration

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();
}
Also used : KeyConfiguration(com.quorum.tessera.config.KeyConfiguration) ConstraintValidatorContext(jakarta.validation.ConstraintValidatorContext) Test(org.junit.Test)

Example 2 with KeyConfiguration

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);
}
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 3 with KeyConfiguration

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();
}
Also used : KeyVaultConfig(com.quorum.tessera.config.KeyVaultConfig) DefaultKeyVaultConfig(com.quorum.tessera.config.DefaultKeyVaultConfig) DefaultKeyVaultConfig(com.quorum.tessera.config.DefaultKeyVaultConfig) KeyConfiguration(com.quorum.tessera.config.KeyConfiguration) ConstraintViolation(jakarta.validation.ConstraintViolation) ConfigKeyPair(com.quorum.tessera.config.keypairs.ConfigKeyPair) AzureVaultKeyPair(com.quorum.tessera.config.keypairs.AzureVaultKeyPair) Test(org.junit.Test)

Example 4 with KeyConfiguration

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();
}
Also used : KeyConfiguration(com.quorum.tessera.config.KeyConfiguration) ConstraintViolation(jakarta.validation.ConstraintViolation) Test(org.junit.Test)

Example 5 with KeyConfiguration

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();
}
Also used : KeyConfiguration(com.quorum.tessera.config.KeyConfiguration) ConstraintValidatorContext(jakarta.validation.ConstraintValidatorContext) 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