Hashicorp Vault Module
Testcontainers module for Vault. Vault is a tool for managing secrets. More information on Vault here.
Usage example
You can start a Vault container instance from any Java application by using:
public static VaultContainer<?> vaultContainer = new VaultContainer<>("hashicorp/vault:1.13")
.withVaultToken(VAULT_TOKEN)
.withInitCommand(
"secrets enable transit",
"write -f transit/keys/my-key",
"kv put secret/testing1 top_secret=password123",
"kv put secret/testing2 secret_one=password1 secret_two=password2 secret_three=password3 secret_three=password3 secret_four=password4"
);
Use CLI to read data from Vault container:
GenericContainer.ExecResult result = vaultContainer.execInContainer(
"vault",
"kv",
"get",
"-format=json",
"secret/testing1"
);
assertThat(result.getStdout()).contains("password123");
Use Http API to read data from Vault container:
Response response = given()
.header("X-Vault-Token", VAULT_TOKEN)
.when()
.get(vaultContainer.getHttpHostAddress() + "/v1/secret/data/testing1")
.thenReturn();
assertThat(response.body().jsonPath().getString("data.data.top_secret")).isEqualTo("password123");
Adding this module to your project dependencies
Add the following dependency to your pom.xml/build.gradle file:
testImplementation "org.testcontainers:testcontainers-vault:2.0.4"
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers-vault</artifactId>
<version>2.0.4</version>
<scope>test</scope>
</dependency>
License
See LICENSE.
Copyright
Copyright (c) 2017 Capital One Services, LLC and other authors.
See AUTHORS for contributors.