open-vault/vault/capabilities_test.go

46 lines
987 B
Go
Raw Normal View History

2016-03-03 17:24:28 +00:00
package vault
2016-03-05 05:03:55 +00:00
import (
"reflect"
"testing"
)
func TestCapabilities(t *testing.T) {
2016-03-05 05:03:55 +00:00
c, _, token := TestCoreUnsealed(t)
actual, err := c.Capabilities(token, "path")
if err != nil {
t.Fatalf("err: %s", err)
}
expected := []string{"root"}
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("bad: got\n%#v\nexpected\n%#v\n", actual, expected)
}
// Create a policy
policy, _ := Parse(aclPolicy)
err = c.policyStore.SetPolicy(policy)
if err != nil {
t.Fatalf("err: %v", err)
}
// Create a token for the policy
ent := &TokenEntry{
ID: "capabilitiestoken",
Path: "testpath",
Policies: []string{"dev"},
}
if err := c.tokenStore.create(ent); err != nil {
t.Fatalf("err: %v", err)
}
actual, err = c.Capabilities("capabilitiestoken", "foo/bar")
if err != nil {
t.Fatalf("err: %s", err)
}
2016-03-18 16:55:18 +00:00
expected = []string{"create", "read", "sudo"}
2016-03-05 05:03:55 +00:00
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("bad: got\n%#v\nexpected\n%#v\n", actual, expected)
}
}