Skip to content
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
7 changes: 7 additions & 0 deletions modules/vault/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@ description = "Testcontainers :: Vault"
dependencies {
api project(':testcontainers')

testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.11.0'

testImplementation 'org.junit.jupiter:junit-jupiter:5.13.4'
testImplementation 'com.bettercloud:vault-java-driver:5.1.0'
testImplementation 'io.rest-assured:rest-assured:5.5.6'
testImplementation 'org.assertj:assertj-core:3.27.4'

}

test {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
import com.bettercloud.vault.VaultConfig;
import com.bettercloud.vault.VaultException;
import com.bettercloud.vault.response.LogicalResponse;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;

public class VaultClientTest {
class VaultClientTest {

private static final String VAULT_TOKEN = "my-root-token";

@Test
public void writeAndReadMultipleValues() throws VaultException {
void writeAndReadMultipleValues() throws VaultException {
try (VaultContainer<?> vaultContainer = new VaultContainer<>("vault:1.1.3").withVaultToken(VAULT_TOKEN)) {
vaultContainer.start();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import com.bettercloud.vault.VaultConfig;
import com.bettercloud.vault.response.LogicalResponse;
import io.restassured.response.Response;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.GenericContainer;

import java.util.HashMap;
Expand All @@ -18,11 +19,10 @@
* This test shows the pattern to use the VaultContainer @ClassRule for a junit test. It also has tests that ensure
* the secrets were added correctly by reading from Vault with the CLI, over HTTP and over Client Library.
*/
public class VaultContainerTest {
class VaultContainerTest {

private static final String VAULT_TOKEN = "my-root-token";

@ClassRule
// vaultContainer {
public static VaultContainer<?> vaultContainer = new VaultContainer<>("hashicorp/vault:1.13")
.withVaultToken(VAULT_TOKEN)
Expand All @@ -35,8 +35,18 @@ public class VaultContainerTest {

// }

@BeforeAll
static void setUp() {
vaultContainer.start();
}

@AfterAll
static void tearDown() {
vaultContainer.stop();
}

@Test
public void readFirstSecretPathWithCli() throws Exception {
void readFirstSecretPathWithCli() throws Exception {
GenericContainer.ExecResult result = vaultContainer.execInContainer(
"vault",
"kv",
Expand All @@ -48,7 +58,7 @@ public void readFirstSecretPathWithCli() throws Exception {
}

@Test
public void readSecondSecretPathWithCli() throws Exception {
void readSecondSecretPathWithCli() throws Exception {
GenericContainer.ExecResult result = vaultContainer.execInContainer(
"vault",
"kv",
Expand All @@ -66,7 +76,7 @@ public void readSecondSecretPathWithCli() throws Exception {
}

@Test
public void readFirstSecretPathOverHttpApi() {
void readFirstSecretPathOverHttpApi() {
Response response = given()
.header("X-Vault-Token", VAULT_TOKEN)
.when()
Expand All @@ -76,7 +86,7 @@ public void readFirstSecretPathOverHttpApi() {
}

@Test
public void readSecondSecretPathOverHttpApi() throws InterruptedException {
void readSecondSecretPathOverHttpApi() throws InterruptedException {
Response response = given()
.header("X-Vault-Token", VAULT_TOKEN)
.when()
Expand All @@ -90,7 +100,7 @@ public void readSecondSecretPathOverHttpApi() throws InterruptedException {
}

@Test
public void readTransitKeyOverHttpApi() throws InterruptedException {
void readTransitKeyOverHttpApi() throws InterruptedException {
Response response = given()
.header("X-Vault-Token", VAULT_TOKEN)
.when()
Expand All @@ -102,7 +112,7 @@ public void readTransitKeyOverHttpApi() throws InterruptedException {

@Test
// readWithLibrary {
public void readFirstSecretPathOverClientLibrary() throws Exception {
void readFirstSecretPathOverClientLibrary() throws Exception {
final VaultConfig config = new VaultConfig()
.address(vaultContainer.getHttpHostAddress())
.token(VAULT_TOKEN)
Expand All @@ -118,7 +128,7 @@ public void readFirstSecretPathOverClientLibrary() throws Exception {
// }

@Test
public void readSecondSecretPathOverClientLibrary() throws Exception {
void readSecondSecretPathOverClientLibrary() throws Exception {
final VaultConfig config = new VaultConfig()
.address(vaultContainer.getHttpHostAddress())
.token(VAULT_TOKEN)
Expand All @@ -135,7 +145,7 @@ public void readSecondSecretPathOverClientLibrary() throws Exception {
}

@Test
public void writeSecretOverClientLibrary() throws Exception {
void writeSecretOverClientLibrary() throws Exception {
final VaultConfig config = new VaultConfig()
.address(vaultContainer.getHttpHostAddress())
.token(VAULT_TOKEN)
Expand Down
Loading