Files
vault/api/secret_test.go
Jeff Mitchell 91053b7471 Add creation time to returned wrapped token info
This makes it easier to understand the expected lifetime without a
lookup call that uses the single use left on the token.

This also adds a couple of safety checks and for JSON uses int, rather
than int64, for the TTL for the wrapped token.
2016-06-07 15:00:35 -04:00

53 lines
836 B
Go

package api
import (
"reflect"
"strings"
"testing"
)
func TestParseSecret(t *testing.T) {
raw := strings.TrimSpace(`
{
"lease_id": "foo",
"renewable": true,
"lease_duration": 10,
"data": {
"key": "value"
},
"warnings": [
"a warning!"
],
"wrap_info": {
"token": "token",
"ttl": 60,
"creation_time": 100000
}
}`)
secret, err := ParseSecret(strings.NewReader(raw))
if err != nil {
t.Fatalf("err: %s", err)
}
expected := &Secret{
LeaseID: "foo",
Renewable: true,
LeaseDuration: 10,
Data: map[string]interface{}{
"key": "value",
},
Warnings: []string{
"a warning!",
},
WrapInfo: &SecretWrapInfo{
Token: "token",
TTL: 60,
CreationTime: int64(100000),
},
}
if !reflect.DeepEqual(secret, expected) {
t.Fatalf("bad: %#v %#v", secret, expected)
}
}