forked from testcontainers/testcontainers-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_vault.py
More file actions
41 lines (36 loc) · 1.24 KB
/
test_vault.py
File metadata and controls
41 lines (36 loc) · 1.24 KB
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
import hvac
from testcontainers.vault import VaultContainer
def test_docker_run_vault():
config = VaultContainer("hashicorp/vault:1.16.1")
with config as vault:
url = vault.get_connection_url()
client = hvac.Client(url=url)
status = client.sys.read_health_status()
assert status.status_code == 200
def test_docker_run_vault_act_as_root():
config = VaultContainer("hashicorp/vault:1.16.1")
with config as vault:
url = vault.get_connection_url()
client = hvac.Client(url=url, token=vault.root_token)
assert client.is_authenticated()
assert client.sys.is_initialized()
assert not client.sys.is_sealed()
client.sys.enable_secrets_engine(
backend_type="kv",
path="secrets",
config={
"version": "2",
},
)
client.secrets.kv.v2.create_or_update_secret(
path="my-secret",
mount_point="secrets",
secret={
"pssst": "this is secret",
},
)
resp = client.secrets.kv.v2.read_secret(
path="my-secret",
mount_point="secrets",
)
assert resp["data"]["data"]["pssst"] == "this is secret"