open-vault/api/secret_test.go

56 lines
948 B
Go
Raw Normal View History

2015-03-12 00:46:25 +00:00
package api
import (
"reflect"
"strings"
"testing"
"time"
2015-03-12 00:46:25 +00:00
)
func TestParseSecret(t *testing.T) {
raw := strings.TrimSpace(`
{
"lease_id": "foo",
2015-03-12 00:46:25 +00:00
"renewable": true,
"lease_duration": 10,
2015-03-16 20:29:51 +00:00
"data": {
"key": "value"
2015-10-07 21:21:41 +00:00
},
"warnings": [
"a warning!"
2016-05-08 01:08:13 +00:00
],
"wrap_info": {
"token": "token",
"ttl": 60,
"creation_time": "2016-06-07T15:52:10-04:00"
2016-05-08 01:08:13 +00:00
}
2015-03-12 00:46:25 +00:00
}`)
rawTime, _ := time.Parse(time.RFC3339, "2016-06-07T15:52:10-04:00")
2015-03-12 00:46:25 +00:00
secret, err := ParseSecret(strings.NewReader(raw))
if err != nil {
t.Fatalf("err: %s", err)
}
expected := &Secret{
LeaseID: "foo",
2015-03-16 20:29:51 +00:00
Renewable: true,
LeaseDuration: 10,
2015-03-12 00:46:25 +00:00
Data: map[string]interface{}{
"key": "value",
},
2015-10-07 21:21:41 +00:00
Warnings: []string{
"a warning!",
},
2016-05-08 01:08:13 +00:00
WrapInfo: &SecretWrapInfo{
Token: "token",
TTL: 60,
CreationTime: rawTime,
2016-05-08 01:08:13 +00:00
},
2015-03-12 00:46:25 +00:00
}
if !reflect.DeepEqual(secret, expected) {
t.Fatalf("bad:\ngot\n%#v\nexpected\n%#v\n", secret, expected)
2015-03-12 00:46:25 +00:00
}
}