2015-03-12 00:46:25 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
2016-06-07 20:01:09 +00:00
|
|
|
"time"
|
2015-03-12 00:46:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestParseSecret(t *testing.T) {
|
|
|
|
raw := strings.TrimSpace(`
|
|
|
|
{
|
2015-04-08 20:35:32 +00:00
|
|
|
"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",
|
2016-06-07 19:00:35 +00:00
|
|
|
"ttl": 60,
|
2016-06-13 23:58:17 +00:00
|
|
|
"creation_time": "2016-06-07T15:52:10-04:00",
|
|
|
|
"wrapped_accessor": "abcd1234"
|
2016-05-08 01:08:13 +00:00
|
|
|
}
|
2015-03-12 00:46:25 +00:00
|
|
|
}`)
|
|
|
|
|
2016-06-07 20:01:09 +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{
|
2015-04-08 20:35:32 +00:00
|
|
|
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{
|
2016-06-13 23:58:17 +00:00
|
|
|
Token: "token",
|
|
|
|
TTL: 60,
|
|
|
|
CreationTime: rawTime,
|
|
|
|
WrappedAccessor: "abcd1234",
|
2016-05-08 01:08:13 +00:00
|
|
|
},
|
2015-03-12 00:46:25 +00:00
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(secret, expected) {
|
2016-06-07 20:01:09 +00:00
|
|
|
t.Fatalf("bad:\ngot\n%#v\nexpected\n%#v\n", secret, expected)
|
2015-03-12 00:46:25 +00:00
|
|
|
}
|
|
|
|
}
|