2023-03-15 16:00:52 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2015-04-01 22:46:13 +00:00
|
|
|
package framework
|
|
|
|
|
|
|
|
import (
|
2018-01-19 06:44:44 +00:00
|
|
|
"context"
|
2015-04-01 22:46:13 +00:00
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
2019-04-12 21:54:35 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/logical"
|
2015-04-01 22:46:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestPolicyMap(t *testing.T) {
|
2015-04-17 16:35:49 +00:00
|
|
|
p := &PolicyMap{}
|
|
|
|
p.PathMap.Name = "foo"
|
2015-04-01 22:46:13 +00:00
|
|
|
s := new(logical.InmemStorage)
|
|
|
|
|
2018-01-19 06:44:44 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
p.Put(ctx, s, "foo", map[string]interface{}{"value": "bar"})
|
|
|
|
p.Put(ctx, s, "bar", map[string]interface{}{"value": "foo,baz "})
|
2015-04-01 22:46:13 +00:00
|
|
|
|
|
|
|
// Read via API
|
2018-01-19 06:44:44 +00:00
|
|
|
actual, err := p.Policies(ctx, s, "foo", "bar")
|
2015-04-01 22:46:13 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("bad: %#v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := []string{"bar", "baz", "foo"}
|
|
|
|
if !reflect.DeepEqual(actual, expected) {
|
|
|
|
t.Fatalf("bad: %#v", actual)
|
|
|
|
}
|
|
|
|
}
|