-
Notifications
You must be signed in to change notification settings - Fork 2
/
vault_integration_test.go
71 lines (64 loc) · 1.52 KB
/
vault_integration_test.go
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package pvc
import (
"log"
"os"
"testing"
)
const (
testSecretPath = "secret/development/test_value"
)
var testvb = vaultBackend{
host: os.Getenv("VAULT_ADDR"),
appid: os.Getenv("VAULT_TEST_APPID"),
userid: os.Getenv("VAULT_TEST_USERID"),
token: os.Getenv("VAULT_TEST_TOKEN"),
authRetries: 3,
authRetryDelaySecs: 1,
}
func testGetVaultClient(t *testing.T) *vaultClient {
vc, err := newVaultClient(&testvb)
if err != nil {
log.Fatalf("error creating client: %v", err)
}
return vc
}
func TestVaultIntegrationAppIDAuth(t *testing.T) {
if testvb.host == "" {
t.Logf("VAULT_ADDR undefined, skipping")
return
}
vc := testGetVaultClient(t)
err := vc.AppIDAuth(testvb.appid, testvb.userid, "")
if err != nil {
log.Fatalf("error authenticating: %v", err)
}
}
func TestVaultIntegrationTokenAuth(t *testing.T) {
if testvb.host == "" {
t.Logf("VAULT_ADDR undefined, skipping")
return
}
vc := testGetVaultClient(t)
err := vc.TokenAuth(testvb.token)
if err != nil {
log.Fatalf("error authenticating: %v", err)
}
}
func TestVaultIntegrationGetValue(t *testing.T) {
if testvb.host == "" {
t.Logf("VAULT_ADDR undefined, skipping")
return
}
vc := testGetVaultClient(t)
err := vc.AppIDAuth(testvb.appid, testvb.userid, "")
if err != nil {
t.Fatalf("error authenticating: %v", err)
}
s, err := vc.GetStringValue(testSecretPath)
if err != nil {
t.Fatalf("error getting value: %v", err)
}
if s != "foo" {
t.Fatalf("bad value: %v (expected 'foo')", s)
}
}