Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect template parameters in VaultEncryptionHelper #471

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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