mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-10-30 18:17:55 +00:00
Add identity templating helper to sdk/framework (#8088)
* Add identity templating helper to sdk/framework * Cleanup a bit * Fix length issue when groups/aliases are filtered due to ns * review feedback
This commit is contained in:
100
sdk/framework/identity_test.go
Normal file
100
sdk/framework/identity_test.go
Normal file
@@ -0,0 +1,100 @@
|
||||
package framework
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/vault/sdk/logical"
|
||||
)
|
||||
|
||||
func TestIdentityTemplating(t *testing.T) {
|
||||
sysView := &logical.StaticSystemView{
|
||||
EntityVal: &logical.Entity{
|
||||
ID: "test-id",
|
||||
Name: "test",
|
||||
Aliases: []*logical.Alias{
|
||||
{
|
||||
ID: "alias-id",
|
||||
Name: "test alias",
|
||||
MountAccessor: "test_mount",
|
||||
MountType: "secret",
|
||||
Metadata: map[string]string{
|
||||
"alias-metadata": "alias-metadata-value",
|
||||
},
|
||||
},
|
||||
},
|
||||
Metadata: map[string]string{
|
||||
"entity-metadata": "entity-metadata-value",
|
||||
},
|
||||
},
|
||||
GroupsVal: []*logical.Group{
|
||||
{
|
||||
ID: "group1-id",
|
||||
Name: "group1",
|
||||
Metadata: map[string]string{
|
||||
"group-metadata": "group-metadata-value",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
tCases := []struct {
|
||||
tpl string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
tpl: "{{identity.entity.id}}",
|
||||
expected: "test-id",
|
||||
},
|
||||
{
|
||||
tpl: "{{identity.entity.name}}",
|
||||
expected: "test",
|
||||
},
|
||||
{
|
||||
tpl: "{{identity.entity.metadata.entity-metadata}}",
|
||||
expected: "entity-metadata-value",
|
||||
},
|
||||
{
|
||||
tpl: "{{identity.entity.aliases.test_mount.id}}",
|
||||
expected: "alias-id",
|
||||
},
|
||||
{
|
||||
tpl: "{{identity.entity.aliases.test_mount.id}}",
|
||||
expected: "alias-id",
|
||||
},
|
||||
{
|
||||
tpl: "{{identity.entity.aliases.test_mount.name}}",
|
||||
expected: "test alias",
|
||||
},
|
||||
{
|
||||
tpl: "{{identity.entity.aliases.test_mount.metadata.alias-metadata}}",
|
||||
expected: "alias-metadata-value",
|
||||
},
|
||||
{
|
||||
tpl: "{{identity.groups.ids.group1-id.name}}",
|
||||
expected: "group1",
|
||||
},
|
||||
{
|
||||
tpl: "{{identity.groups.names.group1.id}}",
|
||||
expected: "group1-id",
|
||||
},
|
||||
{
|
||||
tpl: "{{identity.groups.names.group1.metadata.group-metadata}}",
|
||||
expected: "group-metadata-value",
|
||||
},
|
||||
{
|
||||
tpl: "{{identity.groups.ids.group1-id.metadata.group-metadata}}",
|
||||
expected: "group-metadata-value",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tCase := range tCases {
|
||||
out, err := PopulateIdentityTemplate(tCase.tpl, "test", sysView)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if out != tCase.expected {
|
||||
t.Fatalf("got %q, expected %q", out, tCase.expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user