Skip to content

Commit

Permalink
Fix incorrect template parameters in VaultEncryptionHelper
Browse files Browse the repository at this point in the history
Fixes #470
  • Loading branch information
sleberknight committed Dec 3, 2020
1 parent 5b6fe4f commit 38e9871
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ public VaultEncryptionHelper(VaultConfiguration configuration) {
private static VaultConfiguration validateAndCopyVaultConfiguration(VaultConfiguration configuration) {
checkArgumentNotBlank(configuration.getVaultPasswordFilePath(), "vaultPasswordFilePath is required");
checkArgument(isExistingPath(configuration.getVaultPasswordFilePath()),
"vault password file does not exist: {}", configuration.getVaultPasswordFilePath());
"vault password file does not exist: %s", configuration.getVaultPasswordFilePath());
checkArgumentNotBlank(configuration.getAnsibleVaultPath(), "ansibleVaultPath is required");
checkArgument(isExistingPath(configuration.getAnsibleVaultPath()),
"ansible-vault executable does not exist: {}", configuration.getAnsibleVaultPath());
"ansible-vault executable does not exist: %s", configuration.getAnsibleVaultPath());

return configuration.copyOf();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.NullAndEmptySource;
import org.kiwiproject.base.process.ProcessHelper;
import org.kiwiproject.collect.KiwiLists;
import org.kiwiproject.internal.Fixtures;
Expand Down Expand Up @@ -87,11 +88,53 @@ void shouldNotAllowNullConfig() {
}

@Test
void shouldValidateVaultConfiguration() {
var emptyConfig = new VaultConfiguration();
void shouldNotAllowNullProcessHelper() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new VaultEncryptionHelper(mock(VaultConfiguration.class), null));
}

@ParameterizedTest
@NullAndEmptySource
void shouldValidateVaultPasswordFilePath(String vaultPasswordFilePath) {
var config = new VaultConfiguration();
config.setVaultPasswordFilePath(vaultPasswordFilePath);

assertThatIllegalArgumentException()
.isThrownBy(() -> new VaultEncryptionHelper(config))
.withMessage("vaultPasswordFilePath is required");
}

@Test
void shouldValidateVaultPasswordFilePathExists() {
var config = new VaultConfiguration();
config.setVaultPasswordFilePath("/almost/certainly/does/not/exist.txt");

assertThatIllegalArgumentException()
.isThrownBy(() -> new VaultEncryptionHelper(config))
.withMessage("vault password file does not exist: %s", config.getVaultPasswordFilePath());
}

@ParameterizedTest
@NullAndEmptySource
void shouldValidateAnsibleVaultPath(String ansibleVaultPath) {
var config = new VaultConfiguration();
config.setVaultPasswordFilePath(configuration.getVaultPasswordFilePath()); // passes validation
config.setAnsibleVaultPath(ansibleVaultPath);

assertThatIllegalArgumentException()
.isThrownBy(() -> new VaultEncryptionHelper(config))
.withMessage("ansibleVaultPath is required");
}

@Test
void shouldValidateAnsibleVaultPathExists() {
var config = new VaultConfiguration();
config.setVaultPasswordFilePath(configuration.getVaultPasswordFilePath()); // passes validation
config.setAnsibleVaultPath("/almost/certainly/does/not/exist.txt");

assertThatIllegalArgumentException()
.isThrownBy(() -> new VaultEncryptionHelper(emptyConfig));
.isThrownBy(() -> new VaultEncryptionHelper(config))
.withMessage("ansible-vault executable does not exist: %s", config.getAnsibleVaultPath());
}
}

Expand Down

0 comments on commit 38e9871

Please sign in to comment.