Fix broken testcases
This commit is contained in:
parent
d348735322
commit
68367f60c8
|
@ -28,13 +28,21 @@ func TestSysCapabilitiesAccessor(t *testing.T) {
|
|||
"path": "testpath",
|
||||
})
|
||||
|
||||
var actual map[string][]string
|
||||
var result map[string]interface{}
|
||||
testResponseStatus(t, resp, 200)
|
||||
testResponseBody(t, resp, &actual)
|
||||
testResponseBody(t, resp, &result)
|
||||
|
||||
expected := map[string][]string{
|
||||
"capabilities": []string{"root"},
|
||||
err = resp.DecodeJSON(&result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var actual []string
|
||||
capabilitiesRaw := result["data"].(map[string]interface{})["capabilities"].([]interface{})
|
||||
for _, capability := range capabilitiesRaw {
|
||||
actual = append(actual, capability.(string))
|
||||
}
|
||||
|
||||
expected := []string{"root"}
|
||||
if !reflect.DeepEqual(actual, expected) {
|
||||
t.Fatalf("bad: got\n%#v\nexpected\n%#v\n", actual, expected)
|
||||
}
|
||||
|
@ -69,11 +77,19 @@ func TestSysCapabilitiesAccessor(t *testing.T) {
|
|||
"path": "testpath",
|
||||
})
|
||||
testResponseStatus(t, resp, 200)
|
||||
testResponseBody(t, resp, &actual)
|
||||
testResponseBody(t, resp, &result)
|
||||
|
||||
expected = map[string][]string{
|
||||
"capabilities": []string{"sudo", "read"},
|
||||
err = resp.DecodeJSON(&result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var actual []string
|
||||
capabilitiesRaw := result["data"].(map[string]interface{})["capabilities"].([]interface{})
|
||||
for _, capability := range capabilitiesRaw {
|
||||
actual = append(actual, capability.(string))
|
||||
}
|
||||
|
||||
expected := []string{"sudo", "read"}
|
||||
if !reflect.DeepEqual(actual, expected) {
|
||||
t.Fatalf("bad: got\n%#v\nexpected\n%#v\n", actual, expected)
|
||||
}
|
||||
|
|
|
@ -5,61 +5,6 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
func TestCapabilitiesAccessor(t *testing.T) {
|
||||
c, _, token := TestCoreUnsealed(t)
|
||||
|
||||
// Lookup the token in the store to get root token's accessor
|
||||
tokenEntry, err := c.tokenStore.Lookup(token)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
accessor := tokenEntry.Accessor
|
||||
|
||||
// Use the accessor to fetch the capabilities
|
||||
actual, err := c.CapabilitiesAccessor(accessor, "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)
|
||||
}
|
||||
|
||||
// Lookup the token in the store to get token's accessor
|
||||
tokenEntry, err = c.tokenStore.Lookup("capabilitiestoken")
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
accessor = tokenEntry.Accessor
|
||||
|
||||
// Use the accessor to fetch the capabilities
|
||||
actual, err = c.CapabilitiesAccessor(accessor, "foo/bar")
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
expected = []string{"sudo", "read", "create"}
|
||||
if !reflect.DeepEqual(actual, expected) {
|
||||
t.Fatalf("bad: got\n%#v\nexpected\n%#v\n", actual, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCapabilities(t *testing.T) {
|
||||
c, _, token := TestCoreUnsealed(t)
|
||||
|
||||
|
|
|
@ -477,7 +477,7 @@ func (b *SystemBackend) handleCapabilities(req *logical.Request, d *framework.Fi
|
|||
func (b *SystemBackend) handleCapabilitiesAccessor(req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
|
||||
accessor := d.Get("accessor").(string)
|
||||
if accessor == "" {
|
||||
return nil, &StatusBadRequest{Err: "missing accessor"}
|
||||
return logical.ErrorResponse("missing accessor"), nil
|
||||
}
|
||||
|
||||
token, err := b.Core.tokenStore.lookupByAccessor(accessor)
|
||||
|
|
Loading…
Reference in New Issue