forked from hashicorp/vault
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unwrapping_raw_body_test.go
62 lines (55 loc) · 1.3 KB
/
unwrapping_raw_body_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
package http
import (
"testing"
kv "github.com/hashicorp/vault-plugin-secrets-kv"
"github.com/hashicorp/vault/api"
"github.com/hashicorp/vault/sdk/logical"
"github.com/hashicorp/vault/vault"
)
func TestUnwrapping_Raw_Body(t *testing.T) {
coreConfig := &vault.CoreConfig{
LogicalBackends: map[string]logical.Factory{
"kv": kv.Factory,
},
}
cluster := vault.NewTestCluster(t, coreConfig, &vault.TestClusterOptions{
HandlerFunc: Handler,
})
cluster.Start()
defer cluster.Cleanup()
core := cluster.Cores[0].Core
vault.TestWaitActive(t, core)
client := cluster.Cores[0].Client
// Mount a k/v backend, version 2
err := client.Sys().Mount("kv", &api.MountInput{
Type: "kv",
Options: map[string]string{"version": "2"},
})
if err != nil {
t.Fatal(err)
}
client.SetWrappingLookupFunc(func(operation, path string) string {
return "5m"
})
secret, err := client.Logical().Write("kv/foo/bar", map[string]interface{}{
"a": "b",
})
if err != nil {
t.Fatal(err)
}
if secret == nil {
t.Fatal("nil secret")
}
if secret.WrapInfo == nil {
t.Fatal("nil wrap info")
}
wrapToken := secret.WrapInfo.Token
client.SetWrappingLookupFunc(nil)
secret, err = client.Logical().Unwrap(wrapToken)
if err != nil {
t.Fatal(err)
}
if len(secret.Warnings) != 1 {
t.Fatal("expected 1 warning")
}
}