61 lines
1.2 KiB
Go
61 lines
1.2 KiB
Go
package vault
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/hashicorp/go-uuid"
|
|
"github.com/hashicorp/vault/logical"
|
|
)
|
|
|
|
func TestRequestHandling_Wrapping(t *testing.T) {
|
|
core, _, root := TestCoreUnsealed(t)
|
|
|
|
core.logicalBackends["generic"] = PassthroughBackendFactory
|
|
|
|
meUUID, _ := uuid.GenerateUUID()
|
|
err := core.mount(&MountEntry{
|
|
Table: mountTableType,
|
|
UUID: meUUID,
|
|
Path: "wraptest",
|
|
Type: "generic",
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("err: %v", err)
|
|
}
|
|
|
|
// No duration specified
|
|
req := &logical.Request{
|
|
Path: "wraptest/foo",
|
|
ClientToken: root,
|
|
Operation: logical.UpdateOperation,
|
|
Data: map[string]interface{}{
|
|
"zip": "zap",
|
|
},
|
|
}
|
|
resp, err := core.HandleRequest(req)
|
|
if err != nil {
|
|
t.Fatalf("err: %v", err)
|
|
}
|
|
if resp != nil {
|
|
t.Fatalf("bad: %#v", resp)
|
|
}
|
|
|
|
req = &logical.Request{
|
|
Path: "wraptest/foo",
|
|
ClientToken: root,
|
|
Operation: logical.ReadOperation,
|
|
WrapTTL: time.Duration(15 * time.Second),
|
|
}
|
|
resp, err = core.HandleRequest(req)
|
|
if err != nil {
|
|
t.Fatalf("err: %v", err)
|
|
}
|
|
if resp == nil {
|
|
t.Fatalf("bad: %v", resp)
|
|
}
|
|
if resp.WrapInfo == nil || resp.WrapInfo.TTL != time.Duration(15*time.Second) {
|
|
t.Fatalf("bad: %#v", resp)
|
|
}
|
|
}
|