forked from testcontainers/testcontainers-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VaultClientTest.java
45 lines (32 loc) · 1.55 KB
/
VaultClientTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package org.testcontainers.vault;
import com.bettercloud.vault.Vault;
import com.bettercloud.vault.VaultConfig;
import com.bettercloud.vault.VaultException;
import com.bettercloud.vault.response.LogicalResponse;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
public class VaultClientTest {
private static final String VAULT_TOKEN = "my-root-token";
@Test
public void writeAndReadMultipleValues() throws VaultException {
try (VaultContainer<?> vaultContainer = new VaultContainer<>("vault:1.1.3").withVaultToken(VAULT_TOKEN)) {
vaultContainer.start();
final VaultConfig config = new VaultConfig()
.address("http://" + vaultContainer.getHost() + ":" + vaultContainer.getFirstMappedPort())
.token(VAULT_TOKEN)
.build();
final Vault vault = new Vault(config);
final Map<String, Object> secrets = new HashMap<>();
secrets.put("value", "world");
secrets.put("other_value", "another world");
// Write operation
final LogicalResponse writeResponse = vault.logical().write("secret/hello", secrets);
assertThat(writeResponse.getRestResponse().getStatus()).isEqualTo(200);
// Read operation
final Map<String, String> value = vault.logical().read("secret/hello").getData();
assertThat(value).containsEntry("value", "world").containsEntry("other_value", "another world");
}
}
}