2023-03-15 16:00:52 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2017-10-11 17:21:20 +00:00
|
|
|
package vault
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
2018-10-19 19:47:26 +00:00
|
|
|
"strings"
|
2017-10-11 17:21:20 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/vault/helper/identity"
|
2018-09-18 03:03:00 +00:00
|
|
|
"github.com/hashicorp/vault/helper/namespace"
|
2019-04-12 21:54:35 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/logical"
|
2017-10-11 17:21:20 +00:00
|
|
|
)
|
|
|
|
|
2018-11-13 16:16:10 +00:00
|
|
|
// Issue 5729
|
|
|
|
func TestIdentityStore_DuplicateAliases(t *testing.T) {
|
|
|
|
c, _, _ := TestCoreUnsealed(t)
|
|
|
|
|
|
|
|
resp, err := c.systemBackend.HandleRequest(namespace.RootContext(nil), &logical.Request{
|
|
|
|
Path: "auth",
|
|
|
|
Operation: logical.ReadOperation,
|
|
|
|
})
|
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("bad: resp: %#v\nerr: %v", resp, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
tokenMountAccessor := resp.Data["token/"].(map[string]interface{})["accessor"].(string)
|
|
|
|
|
|
|
|
// Create an entity and attach an alias to it
|
|
|
|
resp, err = c.identityStore.HandleRequest(namespace.RootContext(nil), &logical.Request{
|
|
|
|
Path: "entity-alias",
|
|
|
|
Operation: logical.UpdateOperation,
|
|
|
|
Data: map[string]interface{}{
|
|
|
|
"mount_accessor": tokenMountAccessor,
|
|
|
|
"name": "testaliasname",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("bad: resp: %#v\nerr: %v", resp, err)
|
|
|
|
}
|
|
|
|
aliasID := resp.Data["id"].(string)
|
|
|
|
|
|
|
|
// Create another entity without an alias
|
|
|
|
resp, err = c.identityStore.HandleRequest(namespace.RootContext(nil), &logical.Request{
|
|
|
|
Path: "entity",
|
|
|
|
Operation: logical.UpdateOperation,
|
|
|
|
})
|
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("bad: resp: %#v\nerr: %v", resp, err)
|
|
|
|
}
|
|
|
|
entityID2 := resp.Data["id"].(string)
|
|
|
|
|
|
|
|
// Set the second entity ID as the canonical ID for the previous alias,
|
|
|
|
// initiating an alias transfer
|
|
|
|
resp, err = c.identityStore.HandleRequest(namespace.RootContext(nil), &logical.Request{
|
|
|
|
Path: "entity-alias/id/" + aliasID,
|
|
|
|
Operation: logical.UpdateOperation,
|
|
|
|
Data: map[string]interface{}{
|
|
|
|
"canonical_id": entityID2,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("bad: resp: %#v\nerr: %v", resp, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read the new entity
|
|
|
|
resp, err = c.identityStore.HandleRequest(namespace.RootContext(nil), &logical.Request{
|
|
|
|
Path: "entity/id/" + entityID2,
|
|
|
|
Operation: logical.ReadOperation,
|
|
|
|
})
|
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("bad: resp: %#v\nerr: %v", resp, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure that there is only one alias
|
|
|
|
aliases := resp.Data["aliases"].([]interface{})
|
|
|
|
if len(aliases) != 1 {
|
|
|
|
t.Fatalf("bad: length of aliases; expected: %d, actual: %d", 1, len(aliases))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure that no merging activity has taken place
|
|
|
|
if len(aliases[0].(map[string]interface{})["merged_from_canonical_ids"].([]string)) != 0 {
|
|
|
|
t.Fatalf("expected no merging to take place")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-19 19:47:26 +00:00
|
|
|
func TestIdentityStore_CaseInsensitiveEntityAliasName(t *testing.T) {
|
|
|
|
ctx := namespace.RootContext(nil)
|
|
|
|
i, accessor, _ := testIdentityStoreWithGithubAuth(ctx, t)
|
|
|
|
|
|
|
|
// Create an entity
|
|
|
|
resp, err := i.HandleRequest(ctx, &logical.Request{
|
|
|
|
Path: "entity",
|
|
|
|
Operation: logical.UpdateOperation,
|
|
|
|
})
|
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("bad: err:%v\nresp: %#v", err, resp)
|
|
|
|
}
|
|
|
|
entityID := resp.Data["id"].(string)
|
|
|
|
|
|
|
|
testAliasName := "testAliasName"
|
|
|
|
// Create a case sensitive alias name
|
|
|
|
resp, err = i.HandleRequest(ctx, &logical.Request{
|
|
|
|
Path: "entity-alias",
|
|
|
|
Operation: logical.UpdateOperation,
|
|
|
|
Data: map[string]interface{}{
|
|
|
|
"mount_accessor": accessor,
|
|
|
|
"canonical_id": entityID,
|
|
|
|
"name": testAliasName,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("bad: err:%v\nresp: %#v", err, resp)
|
|
|
|
}
|
|
|
|
aliasID := resp.Data["id"].(string)
|
|
|
|
|
|
|
|
// Ensure that reading the alias returns case sensitive alias name
|
|
|
|
resp, err = i.HandleRequest(ctx, &logical.Request{
|
|
|
|
Path: "entity-alias/id/" + aliasID,
|
|
|
|
Operation: logical.ReadOperation,
|
|
|
|
})
|
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("bad: err:%v\nresp: %#v", err, resp)
|
|
|
|
}
|
|
|
|
aliasName := resp.Data["name"].(string)
|
|
|
|
if aliasName != testAliasName {
|
|
|
|
t.Fatalf("bad alias name; expected: %q, actual: %q", testAliasName, aliasName)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Overwrite the alias using lower cased alias name. This shouldn't error.
|
|
|
|
resp, err = i.HandleRequest(ctx, &logical.Request{
|
|
|
|
Path: "entity-alias/id/" + aliasID,
|
|
|
|
Operation: logical.UpdateOperation,
|
|
|
|
Data: map[string]interface{}{
|
|
|
|
"mount_accessor": accessor,
|
|
|
|
"canonical_id": entityID,
|
|
|
|
"name": strings.ToLower(testAliasName),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("bad: err:%v\nresp: %#v", err, resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure that reading the alias returns lower cased alias name
|
|
|
|
resp, err = i.HandleRequest(ctx, &logical.Request{
|
|
|
|
Path: "entity-alias/id/" + aliasID,
|
|
|
|
Operation: logical.ReadOperation,
|
|
|
|
})
|
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("bad: err:%v\nresp: %#v", err, resp)
|
|
|
|
}
|
|
|
|
aliasName = resp.Data["name"].(string)
|
|
|
|
if aliasName != strings.ToLower(testAliasName) {
|
|
|
|
t.Fatalf("bad alias name; expected: %q, actual: %q", testAliasName, aliasName)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure that there is one entity alias
|
|
|
|
resp, err = i.HandleRequest(ctx, &logical.Request{
|
|
|
|
Path: "entity-alias/id",
|
|
|
|
Operation: logical.ListOperation,
|
|
|
|
})
|
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("bad: err:%v\nresp: %#v", err, resp)
|
|
|
|
}
|
|
|
|
if len(resp.Data["keys"].([]string)) != 1 {
|
|
|
|
t.Fatalf("bad length of entity aliases; expected: 1, actual: %d", len(resp.Data["keys"].([]string)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-11 17:21:20 +00:00
|
|
|
// This test is required because MemDB does not take care of ensuring
|
|
|
|
// uniqueness of indexes that are marked unique.
|
|
|
|
func TestIdentityStore_AliasSameAliasNames(t *testing.T) {
|
|
|
|
var err error
|
|
|
|
var resp *logical.Response
|
2018-09-18 03:03:00 +00:00
|
|
|
|
|
|
|
ctx := namespace.RootContext(nil)
|
|
|
|
is, githubAccessor, _ := testIdentityStoreWithGithubAuth(ctx, t)
|
2017-10-11 17:21:20 +00:00
|
|
|
|
|
|
|
aliasData := map[string]interface{}{
|
|
|
|
"name": "testaliasname",
|
|
|
|
"mount_accessor": githubAccessor,
|
|
|
|
}
|
|
|
|
|
|
|
|
aliasReq := &logical.Request{
|
|
|
|
Operation: logical.UpdateOperation,
|
2017-11-14 01:59:42 +00:00
|
|
|
Path: "entity-alias",
|
2017-10-11 17:21:20 +00:00
|
|
|
Data: aliasData,
|
|
|
|
}
|
|
|
|
|
2017-11-02 20:05:48 +00:00
|
|
|
// Register an alias
|
2018-09-18 03:03:00 +00:00
|
|
|
resp, err = is.HandleRequest(ctx, aliasReq)
|
2017-10-11 17:21:20 +00:00
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("err:%v resp:%#v", err, resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Register another alias with same name
|
2018-09-18 03:03:00 +00:00
|
|
|
resp, err = is.HandleRequest(ctx, aliasReq)
|
2017-10-11 17:21:20 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-06-14 16:53:00 +00:00
|
|
|
if resp != nil {
|
|
|
|
t.Fatalf("expected no response since this modification should be idempotent")
|
2017-10-11 17:21:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIdentityStore_MemDBAliasIndexes(t *testing.T) {
|
|
|
|
var err error
|
|
|
|
|
2018-09-18 03:03:00 +00:00
|
|
|
ctx := namespace.RootContext(nil)
|
|
|
|
is, githubAccessor, _ := testIdentityStoreWithGithubAuth(ctx, t)
|
2017-10-11 17:21:20 +00:00
|
|
|
if is == nil {
|
|
|
|
t.Fatal("failed to create test identity store")
|
|
|
|
}
|
|
|
|
|
2021-08-30 19:31:11 +00:00
|
|
|
validateMountResp := is.router.ValidateMountByAccessor(githubAccessor)
|
2017-10-11 17:21:20 +00:00
|
|
|
if validateMountResp == nil {
|
|
|
|
t.Fatal("failed to validate github auth mount")
|
|
|
|
}
|
|
|
|
|
|
|
|
entity := &identity.Entity{
|
|
|
|
ID: "testentityid",
|
|
|
|
Name: "testentityname",
|
|
|
|
}
|
|
|
|
|
2019-05-07 19:29:51 +00:00
|
|
|
entity.BucketKey = is.entityPacker.BucketKey(entity.ID)
|
2017-10-11 17:21:20 +00:00
|
|
|
|
2018-06-24 11:45:53 +00:00
|
|
|
txn := is.db.Txn(true)
|
|
|
|
defer txn.Abort()
|
|
|
|
err = is.MemDBUpsertEntityInTxn(txn, entity)
|
2017-10-11 17:21:20 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-06-24 11:45:53 +00:00
|
|
|
txn.Commit()
|
2017-10-11 17:21:20 +00:00
|
|
|
|
|
|
|
alias := &identity.Alias{
|
2017-11-02 20:05:48 +00:00
|
|
|
CanonicalID: entity.ID,
|
2017-10-11 17:21:20 +00:00
|
|
|
ID: "testaliasid",
|
|
|
|
MountAccessor: githubAccessor,
|
|
|
|
MountType: validateMountResp.MountType,
|
|
|
|
Name: "testaliasname",
|
|
|
|
Metadata: map[string]string{
|
|
|
|
"testkey1": "testmetadatavalue1",
|
|
|
|
"testkey2": "testmetadatavalue2",
|
|
|
|
},
|
2021-10-15 19:20:00 +00:00
|
|
|
LocalBucketKey: is.localAliasPacker.BucketKey(entity.ID),
|
2017-10-11 17:21:20 +00:00
|
|
|
}
|
|
|
|
|
2018-06-24 11:45:53 +00:00
|
|
|
txn = is.db.Txn(true)
|
|
|
|
defer txn.Abort()
|
|
|
|
err = is.MemDBUpsertAliasInTxn(txn, alias, false)
|
2017-10-11 17:21:20 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-06-24 11:45:53 +00:00
|
|
|
txn.Commit()
|
2017-10-11 17:21:20 +00:00
|
|
|
|
2017-11-02 20:05:48 +00:00
|
|
|
aliasFetched, err := is.MemDBAliasByID("testaliasid", false, false)
|
2017-10-11 17:21:20 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(alias, aliasFetched) {
|
|
|
|
t.Fatalf("bad: mismatched aliases; expected: %#v\n actual: %#v\n", alias, aliasFetched)
|
|
|
|
}
|
|
|
|
|
2017-11-02 20:05:48 +00:00
|
|
|
aliasFetched, err = is.MemDBAliasByFactors(validateMountResp.MountAccessor, "testaliasname", false, false)
|
2017-10-11 17:21:20 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(alias, aliasFetched) {
|
|
|
|
t.Fatalf("bad: mismatched aliases; expected: %#v\n actual: %#v\n", alias, aliasFetched)
|
|
|
|
}
|
|
|
|
|
|
|
|
alias2 := &identity.Alias{
|
2017-11-02 20:05:48 +00:00
|
|
|
CanonicalID: entity.ID,
|
2017-10-11 17:21:20 +00:00
|
|
|
ID: "testaliasid2",
|
|
|
|
MountAccessor: validateMountResp.MountAccessor,
|
|
|
|
MountType: validateMountResp.MountType,
|
|
|
|
Name: "testaliasname2",
|
|
|
|
Metadata: map[string]string{
|
|
|
|
"testkey1": "testmetadatavalue1",
|
|
|
|
"testkey3": "testmetadatavalue3",
|
|
|
|
},
|
2021-10-15 19:20:00 +00:00
|
|
|
LocalBucketKey: is.localAliasPacker.BucketKey(entity.ID),
|
2017-10-11 17:21:20 +00:00
|
|
|
}
|
|
|
|
|
2018-06-24 11:45:53 +00:00
|
|
|
txn = is.db.Txn(true)
|
|
|
|
defer txn.Abort()
|
|
|
|
err = is.MemDBUpsertAliasInTxn(txn, alias2, false)
|
2017-10-11 17:21:20 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-06-24 11:45:53 +00:00
|
|
|
err = is.MemDBDeleteAliasByIDInTxn(txn, "testaliasid", false)
|
2017-10-11 17:21:20 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-06-24 11:45:53 +00:00
|
|
|
txn.Commit()
|
2017-10-11 17:21:20 +00:00
|
|
|
|
2017-11-02 20:05:48 +00:00
|
|
|
aliasFetched, err = is.MemDBAliasByID("testaliasid", false, false)
|
2017-10-11 17:21:20 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if aliasFetched != nil {
|
|
|
|
t.Fatalf("expected a nil alias")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIdentityStore_AliasRegister(t *testing.T) {
|
|
|
|
var err error
|
|
|
|
var resp *logical.Response
|
|
|
|
|
2018-09-18 03:03:00 +00:00
|
|
|
ctx := namespace.RootContext(nil)
|
|
|
|
is, githubAccessor, _ := testIdentityStoreWithGithubAuth(ctx, t)
|
2017-10-11 17:21:20 +00:00
|
|
|
|
|
|
|
if is == nil {
|
|
|
|
t.Fatal("failed to create test alias store")
|
|
|
|
}
|
|
|
|
|
|
|
|
aliasData := map[string]interface{}{
|
|
|
|
"name": "testaliasname",
|
|
|
|
"mount_accessor": githubAccessor,
|
|
|
|
"metadata": []string{"organization=hashicorp", "team=vault"},
|
|
|
|
}
|
|
|
|
|
|
|
|
aliasReq := &logical.Request{
|
|
|
|
Operation: logical.UpdateOperation,
|
2017-11-14 01:59:42 +00:00
|
|
|
Path: "entity-alias",
|
2017-10-11 17:21:20 +00:00
|
|
|
Data: aliasData,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Register the alias
|
2018-09-18 03:03:00 +00:00
|
|
|
resp, err = is.HandleRequest(ctx, aliasReq)
|
2017-10-11 17:21:20 +00:00
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("err:%v resp:%#v", err, resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
idRaw, ok := resp.Data["id"]
|
|
|
|
if !ok {
|
|
|
|
t.Fatalf("alias id not present in alias register response")
|
|
|
|
}
|
|
|
|
|
|
|
|
id := idRaw.(string)
|
|
|
|
if id == "" {
|
|
|
|
t.Fatalf("invalid alias id in alias register response")
|
|
|
|
}
|
|
|
|
|
2017-11-02 20:05:48 +00:00
|
|
|
entityIDRaw, ok := resp.Data["canonical_id"]
|
2017-10-11 17:21:20 +00:00
|
|
|
if !ok {
|
|
|
|
t.Fatalf("entity id not present in alias register response")
|
|
|
|
}
|
|
|
|
|
|
|
|
entityID := entityIDRaw.(string)
|
|
|
|
if entityID == "" {
|
|
|
|
t.Fatalf("invalid entity id in alias register response")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIdentityStore_AliasUpdate(t *testing.T) {
|
2018-09-18 03:03:00 +00:00
|
|
|
ctx := namespace.RootContext(nil)
|
|
|
|
is, githubAccessor, _ := testIdentityStoreWithGithubAuth(ctx, t)
|
2017-10-11 17:21:20 +00:00
|
|
|
|
2021-12-10 23:07:47 +00:00
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
createData map[string]interface{}
|
|
|
|
updateData map[string]interface{}
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "noop",
|
|
|
|
createData: map[string]interface{}{
|
|
|
|
"name": "noop",
|
|
|
|
"mount_accessor": githubAccessor,
|
|
|
|
"custom_metadata": map[string]string{
|
|
|
|
"foo": "baz",
|
|
|
|
"bar": "qux",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
updateData: map[string]interface{}{
|
|
|
|
"name": "noop",
|
|
|
|
"mount_accessor": githubAccessor,
|
|
|
|
"custom_metadata": map[string]string{
|
|
|
|
"foo": "baz",
|
|
|
|
"bar": "qux",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "no-custom-metadata",
|
|
|
|
createData: map[string]interface{}{
|
|
|
|
"name": "no-custom-metadata",
|
|
|
|
"mount_accessor": githubAccessor,
|
|
|
|
},
|
|
|
|
updateData: map[string]interface{}{
|
|
|
|
"name": "no-custom-metadata",
|
|
|
|
"mount_accessor": githubAccessor,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "update-name-custom-metadata",
|
|
|
|
createData: map[string]interface{}{
|
|
|
|
"name": "update-name-custom-metadata",
|
|
|
|
"mount_accessor": githubAccessor,
|
|
|
|
"custom_metadata": make(map[string]string),
|
|
|
|
},
|
|
|
|
updateData: map[string]interface{}{
|
|
|
|
"name": "update-name-custom-metadata-2",
|
|
|
|
"mount_accessor": githubAccessor,
|
|
|
|
"custom_metadata": map[string]string{
|
|
|
|
"bar": "qux",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "update-name",
|
|
|
|
createData: map[string]interface{}{
|
|
|
|
"name": "update-name",
|
|
|
|
"mount_accessor": githubAccessor,
|
|
|
|
"custom_metadata": map[string]string{
|
|
|
|
"foo": "baz",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
updateData: map[string]interface{}{
|
|
|
|
"name": "update-name-2",
|
|
|
|
"mount_accessor": githubAccessor,
|
|
|
|
"custom_metadata": map[string]string{
|
|
|
|
"foo": "baz",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "update-metadata",
|
|
|
|
createData: map[string]interface{}{
|
|
|
|
"name": "update-metadata",
|
|
|
|
"mount_accessor": githubAccessor,
|
|
|
|
"custom_metadata": map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
updateData: map[string]interface{}{
|
|
|
|
"name": "update-metadata",
|
|
|
|
"mount_accessor": githubAccessor,
|
|
|
|
"custom_metadata": map[string]string{
|
|
|
|
"foo": "baz",
|
|
|
|
"bar": "qux",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "clear-metadata",
|
|
|
|
createData: map[string]interface{}{
|
|
|
|
"name": "clear",
|
|
|
|
"mount_accessor": githubAccessor,
|
|
|
|
"custom_metadata": map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
updateData: map[string]interface{}{
|
|
|
|
"name": "clear",
|
|
|
|
"mount_accessor": githubAccessor,
|
|
|
|
"custom_metadata": map[string]string{},
|
|
|
|
},
|
|
|
|
},
|
2023-05-01 10:42:30 +00:00
|
|
|
{
|
|
|
|
name: "only-metadata",
|
|
|
|
createData: map[string]interface{}{
|
|
|
|
"name": "only",
|
|
|
|
"mount_accessor": githubAccessor,
|
|
|
|
"custom_metadata": map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
updateData: map[string]interface{}{
|
|
|
|
"custom_metadata": map[string]string{
|
|
|
|
"bar": "baz",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "only-metadata-clear",
|
|
|
|
createData: map[string]interface{}{
|
|
|
|
"name": "only-clear",
|
|
|
|
"mount_accessor": githubAccessor,
|
|
|
|
"custom_metadata": map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
updateData: map[string]interface{}{
|
|
|
|
"custom_metadata": map[string]string{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "only-metadata-none-before",
|
|
|
|
createData: map[string]interface{}{
|
|
|
|
"name": "no-metadata",
|
|
|
|
"mount_accessor": githubAccessor,
|
|
|
|
},
|
|
|
|
updateData: map[string]interface{}{
|
|
|
|
"custom_metadata": map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-10-11 17:21:20 +00:00
|
|
|
}
|
|
|
|
|
2021-12-10 23:07:47 +00:00
|
|
|
handleRequest := func(t *testing.T, req *logical.Request) *logical.Response {
|
|
|
|
t.Helper()
|
|
|
|
resp, err := is.HandleRequest(ctx, req)
|
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("err:%v resp:%#v", err, resp)
|
|
|
|
}
|
|
|
|
return resp
|
|
|
|
}
|
|
|
|
|
|
|
|
respDefaults := map[string]interface{}{
|
|
|
|
"custom_metadata": map[string]string{},
|
|
|
|
}
|
|
|
|
|
|
|
|
checkValues := func(t *testing.T, reqData, respData map[string]interface{}) {
|
|
|
|
t.Helper()
|
|
|
|
expected := make(map[string]interface{})
|
|
|
|
for k := range reqData {
|
|
|
|
expected[k] = reqData[k]
|
|
|
|
}
|
|
|
|
|
|
|
|
for k := range respDefaults {
|
|
|
|
if _, ok := expected[k]; !ok {
|
|
|
|
expected[k] = respDefaults[k]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
actual := make(map[string]interface{}, len(expected))
|
|
|
|
for k := range expected {
|
|
|
|
actual[k] = respData[k]
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(expected, actual) {
|
|
|
|
t.Fatalf("expected data %#v, actual %#v", expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
resp := handleRequest(t, &logical.Request{
|
|
|
|
Operation: logical.UpdateOperation,
|
|
|
|
Path: "entity-alias",
|
|
|
|
Data: tt.createData,
|
|
|
|
})
|
|
|
|
|
|
|
|
readReq := &logical.Request{
|
|
|
|
Operation: logical.ReadOperation,
|
|
|
|
Path: "entity-alias/id/" + resp.Data["id"].(string),
|
|
|
|
}
|
|
|
|
|
|
|
|
// check create
|
|
|
|
resp = handleRequest(t, readReq)
|
|
|
|
checkValues(t, tt.createData, resp.Data)
|
|
|
|
|
|
|
|
// check update
|
|
|
|
resp = handleRequest(t, &logical.Request{
|
|
|
|
Operation: logical.UpdateOperation,
|
|
|
|
Path: readReq.Path,
|
|
|
|
Data: tt.updateData,
|
|
|
|
})
|
|
|
|
resp = handleRequest(t, readReq)
|
|
|
|
checkValues(t, tt.updateData, resp.Data)
|
|
|
|
})
|
2021-09-17 18:03:47 +00:00
|
|
|
}
|
2017-10-11 17:21:20 +00:00
|
|
|
}
|
|
|
|
|
2021-10-14 16:52:07 +00:00
|
|
|
// Test to check that the alias cannot be updated with a new entity
|
|
|
|
// which already has an alias for the mount on the alias to be updated
|
|
|
|
func TestIdentityStore_AliasMove_DuplicateAccessor(t *testing.T) {
|
|
|
|
var err error
|
|
|
|
var resp *logical.Response
|
|
|
|
ctx := namespace.RootContext(nil)
|
|
|
|
is, githubAccessor, _ := testIdentityStoreWithGithubAuth(ctx, t)
|
|
|
|
|
|
|
|
// Create 2 entities and 1 alias on each, against the same github mount
|
|
|
|
resp, err = is.HandleRequest(ctx, &logical.Request{
|
|
|
|
Path: "entity",
|
|
|
|
Operation: logical.UpdateOperation,
|
|
|
|
Data: map[string]interface{}{
|
|
|
|
"name": "testentity1",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("bad: err:%v\nresp: %#v", err, resp)
|
|
|
|
}
|
|
|
|
entity1ID := resp.Data["id"].(string)
|
|
|
|
|
|
|
|
alias1Data := map[string]interface{}{
|
|
|
|
"name": "testaliasname1",
|
|
|
|
"mount_accessor": githubAccessor,
|
|
|
|
"canonical_id": entity1ID,
|
|
|
|
}
|
|
|
|
|
|
|
|
aliasReq := &logical.Request{
|
|
|
|
Operation: logical.UpdateOperation,
|
|
|
|
Path: "entity-alias",
|
|
|
|
Data: alias1Data,
|
|
|
|
}
|
|
|
|
|
|
|
|
// This will create an alias against the requested entity
|
|
|
|
resp, err = is.HandleRequest(ctx, aliasReq)
|
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("err:%v resp:%#v", err, resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err = is.HandleRequest(ctx, &logical.Request{
|
|
|
|
Path: "entity",
|
|
|
|
Operation: logical.UpdateOperation,
|
|
|
|
Data: map[string]interface{}{
|
|
|
|
"name": "testentity2",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("bad: err:%v\nresp: %#v", err, resp)
|
|
|
|
}
|
|
|
|
entity2ID := resp.Data["id"].(string)
|
|
|
|
|
|
|
|
alias2Data := map[string]interface{}{
|
|
|
|
"name": "testaliasname2",
|
|
|
|
"mount_accessor": githubAccessor,
|
|
|
|
"canonical_id": entity2ID,
|
|
|
|
}
|
|
|
|
|
|
|
|
aliasReq.Data = alias2Data
|
|
|
|
|
|
|
|
// This will create an alias against the requested entity
|
|
|
|
resp, err = is.HandleRequest(ctx, aliasReq)
|
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("err:%v resp:%#v", err, resp)
|
|
|
|
}
|
|
|
|
alias2ID := resp.Data["id"].(string)
|
|
|
|
|
|
|
|
// Attempt to update the second alias to point to the first entity
|
|
|
|
updateData := map[string]interface{}{
|
|
|
|
"canonical_id": entity1ID,
|
|
|
|
}
|
|
|
|
|
|
|
|
aliasReq.Data = updateData
|
|
|
|
aliasReq.Path = "entity-alias/id/" + alias2ID
|
|
|
|
resp, err = is.HandleRequest(ctx, aliasReq)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp == nil || !resp.IsError() {
|
|
|
|
t.Fatalf("expected an error as alias on the github accessor exists for testentity1")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test that the alias cannot be changed to a mount for which
|
|
|
|
// the entity already has an alias
|
|
|
|
func TestIdentityStore_AliasUpdate_DuplicateAccessor(t *testing.T) {
|
|
|
|
var err error
|
|
|
|
var resp *logical.Response
|
|
|
|
ctx := namespace.RootContext(nil)
|
|
|
|
|
|
|
|
is, ghAccessor, upAccessor, _ := testIdentityStoreWithGithubUserpassAuth(ctx, t)
|
|
|
|
|
|
|
|
// Create 1 entity and 2 aliases on it, one for each mount
|
|
|
|
resp, err = is.HandleRequest(ctx, &logical.Request{
|
|
|
|
Path: "entity",
|
|
|
|
Operation: logical.UpdateOperation,
|
|
|
|
Data: map[string]interface{}{
|
|
|
|
"name": "testentity",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("bad: err:%v\nresp: %#v", err, resp)
|
|
|
|
}
|
|
|
|
entityID := resp.Data["id"].(string)
|
|
|
|
|
|
|
|
alias1Data := map[string]interface{}{
|
|
|
|
"name": "testaliasname1",
|
|
|
|
"mount_accessor": ghAccessor,
|
|
|
|
"canonical_id": entityID,
|
|
|
|
}
|
|
|
|
|
|
|
|
aliasReq := &logical.Request{
|
|
|
|
Operation: logical.UpdateOperation,
|
|
|
|
Path: "entity-alias",
|
|
|
|
Data: alias1Data,
|
|
|
|
}
|
|
|
|
|
|
|
|
// This will create an alias against the requested entity
|
|
|
|
resp, err = is.HandleRequest(ctx, aliasReq)
|
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("err:%v resp:%#v", err, resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
alias2Data := map[string]interface{}{
|
|
|
|
"name": "testaliasname2",
|
|
|
|
"mount_accessor": upAccessor,
|
|
|
|
"canonical_id": entityID,
|
|
|
|
}
|
|
|
|
|
|
|
|
aliasReq.Data = alias2Data
|
|
|
|
|
|
|
|
// This will create an alias against the requested entity
|
|
|
|
resp, err = is.HandleRequest(ctx, aliasReq)
|
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("err:%v resp:%#v", err, resp)
|
|
|
|
}
|
|
|
|
alias2ID := resp.Data["id"].(string)
|
|
|
|
|
|
|
|
// Attempt to update the userpass mount to point to the github mount
|
|
|
|
updateData := map[string]interface{}{
|
|
|
|
"mount_accessor": ghAccessor,
|
|
|
|
}
|
|
|
|
|
|
|
|
aliasReq.Data = updateData
|
|
|
|
aliasReq.Path = "entity-alias/id/" + alias2ID
|
|
|
|
resp, err = is.HandleRequest(ctx, aliasReq)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp == nil || !resp.IsError() {
|
|
|
|
t.Fatalf("expected an error as an alias on the github accessor already exists for testentity")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test that alias creation fails if an alias for the specified mount
|
|
|
|
// and entity has already been created
|
|
|
|
func TestIdentityStore_AliasCreate_DuplicateAccessor(t *testing.T) {
|
|
|
|
var err error
|
|
|
|
var resp *logical.Response
|
|
|
|
ctx := namespace.RootContext(nil)
|
|
|
|
is, githubAccessor, _ := testIdentityStoreWithGithubAuth(ctx, t)
|
|
|
|
|
|
|
|
resp, err = is.HandleRequest(ctx, &logical.Request{
|
|
|
|
Path: "entity",
|
|
|
|
Operation: logical.UpdateOperation,
|
|
|
|
})
|
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("bad: err:%v\nresp: %#v", err, resp)
|
|
|
|
}
|
|
|
|
entityID := resp.Data["id"].(string)
|
|
|
|
|
|
|
|
aliasData := map[string]interface{}{
|
|
|
|
"name": "testaliasname",
|
|
|
|
"mount_accessor": githubAccessor,
|
|
|
|
"canonical_id": entityID,
|
|
|
|
}
|
|
|
|
|
|
|
|
aliasReq := &logical.Request{
|
|
|
|
Operation: logical.UpdateOperation,
|
|
|
|
Path: "entity-alias",
|
|
|
|
Data: aliasData,
|
|
|
|
}
|
|
|
|
|
|
|
|
// This will create an alias against the requested entity
|
|
|
|
resp, err = is.HandleRequest(ctx, aliasReq)
|
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("err:%v resp:%#v", err, resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
aliasData["name"] = "testaliasname2"
|
|
|
|
aliasReq = &logical.Request{
|
|
|
|
Operation: logical.UpdateOperation,
|
|
|
|
Path: "entity-alias",
|
|
|
|
Data: aliasData,
|
|
|
|
}
|
|
|
|
|
|
|
|
// This will try to create a new alias with the same accessor and entity
|
|
|
|
resp, err = is.HandleRequest(ctx, aliasReq)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if resp == nil || !resp.IsError() {
|
|
|
|
t.Fatalf("expected an error as alias already exists for this accessor and entity")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-11 17:21:20 +00:00
|
|
|
func TestIdentityStore_AliasUpdate_ByID(t *testing.T) {
|
|
|
|
var err error
|
|
|
|
var resp *logical.Response
|
2018-09-18 03:03:00 +00:00
|
|
|
ctx := namespace.RootContext(nil)
|
|
|
|
is, githubAccessor, _ := testIdentityStoreWithGithubAuth(ctx, t)
|
2017-10-11 17:21:20 +00:00
|
|
|
|
|
|
|
updateData := map[string]interface{}{
|
|
|
|
"name": "updatedaliasname",
|
|
|
|
"mount_accessor": githubAccessor,
|
|
|
|
}
|
|
|
|
|
|
|
|
updateReq := &logical.Request{
|
|
|
|
Operation: logical.UpdateOperation,
|
2017-11-14 01:59:42 +00:00
|
|
|
Path: "entity-alias/id/invalidaliasid",
|
2017-10-11 17:21:20 +00:00
|
|
|
Data: updateData,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to update an non-existent alias
|
2018-09-18 03:03:00 +00:00
|
|
|
resp, err = is.HandleRequest(ctx, updateReq)
|
2017-10-11 17:21:20 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if resp == nil || !resp.IsError() {
|
|
|
|
t.Fatalf("expected an error due to invalid alias id")
|
|
|
|
}
|
|
|
|
|
2021-09-17 18:03:47 +00:00
|
|
|
customMetadata := make(map[string]string)
|
|
|
|
customMetadata["foo"] = "abc"
|
2017-10-11 17:21:20 +00:00
|
|
|
registerData := map[string]interface{}{
|
2021-09-17 18:03:47 +00:00
|
|
|
"name": "testaliasname",
|
|
|
|
"mount_accessor": githubAccessor,
|
|
|
|
"custom_metadata": customMetadata,
|
2017-10-11 17:21:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
registerReq := &logical.Request{
|
|
|
|
Operation: logical.UpdateOperation,
|
2017-11-14 01:59:42 +00:00
|
|
|
Path: "entity-alias",
|
2017-10-11 17:21:20 +00:00
|
|
|
Data: registerData,
|
|
|
|
}
|
|
|
|
|
2018-09-18 03:03:00 +00:00
|
|
|
resp, err = is.HandleRequest(ctx, registerReq)
|
2017-10-11 17:21:20 +00:00
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("err:%v resp:%#v", err, resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
idRaw, ok := resp.Data["id"]
|
|
|
|
if !ok {
|
|
|
|
t.Fatalf("alias id not present in response")
|
|
|
|
}
|
|
|
|
id := idRaw.(string)
|
|
|
|
if id == "" {
|
|
|
|
t.Fatalf("invalid alias id")
|
|
|
|
}
|
|
|
|
|
2017-11-14 01:59:42 +00:00
|
|
|
updateReq.Path = "entity-alias/id/" + id
|
2018-09-18 03:03:00 +00:00
|
|
|
resp, err = is.HandleRequest(ctx, updateReq)
|
2017-10-11 17:21:20 +00:00
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("err:%v resp:%#v", err, resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
readReq := &logical.Request{
|
|
|
|
Operation: logical.ReadOperation,
|
|
|
|
Path: updateReq.Path,
|
|
|
|
}
|
2018-09-18 03:03:00 +00:00
|
|
|
resp, err = is.HandleRequest(ctx, readReq)
|
2017-10-11 17:21:20 +00:00
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("err:%v resp:%#v", err, resp)
|
|
|
|
}
|
|
|
|
|
2018-07-25 02:01:58 +00:00
|
|
|
if resp.Data["name"] != "updatedaliasname" {
|
2017-10-11 17:21:20 +00:00
|
|
|
t.Fatalf("failed to update alias information; \n response data: %#v\n", resp.Data)
|
|
|
|
}
|
2021-09-17 18:03:47 +00:00
|
|
|
if !reflect.DeepEqual(resp.Data["custom_metadata"], customMetadata) {
|
|
|
|
t.Fatalf("failed to update alias information; \n response data: %#v\n", resp.Data)
|
|
|
|
}
|
2017-10-11 17:21:20 +00:00
|
|
|
|
|
|
|
delete(registerReq.Data, "name")
|
|
|
|
|
2018-09-18 03:03:00 +00:00
|
|
|
resp, err = is.HandleRequest(ctx, registerReq)
|
2017-10-11 17:21:20 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if resp == nil || !resp.IsError() {
|
|
|
|
t.Fatalf("expected error due to missing alias name")
|
|
|
|
}
|
|
|
|
|
|
|
|
registerReq.Data["name"] = "testaliasname"
|
|
|
|
delete(registerReq.Data, "mount_accessor")
|
|
|
|
|
2018-09-18 03:03:00 +00:00
|
|
|
resp, err = is.HandleRequest(ctx, registerReq)
|
2017-10-11 17:21:20 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if resp == nil || !resp.IsError() {
|
|
|
|
t.Fatalf("expected error due to missing mount accessor")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIdentityStore_AliasReadDelete(t *testing.T) {
|
|
|
|
var err error
|
|
|
|
var resp *logical.Response
|
|
|
|
|
2018-09-18 03:03:00 +00:00
|
|
|
ctx := namespace.RootContext(nil)
|
|
|
|
is, githubAccessor, _ := testIdentityStoreWithGithubAuth(ctx, t)
|
2017-10-11 17:21:20 +00:00
|
|
|
|
2021-09-17 18:03:47 +00:00
|
|
|
customMetadata := make(map[string]string)
|
|
|
|
customMetadata["foo"] = "abc"
|
2017-10-11 17:21:20 +00:00
|
|
|
registerData := map[string]interface{}{
|
2021-09-17 18:03:47 +00:00
|
|
|
"name": "testaliasname",
|
|
|
|
"mount_accessor": githubAccessor,
|
|
|
|
"metadata": []string{"organization=hashicorp", "team=vault"},
|
|
|
|
"custom_metadata": customMetadata,
|
2017-10-11 17:21:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
registerReq := &logical.Request{
|
|
|
|
Operation: logical.UpdateOperation,
|
2017-11-14 01:59:42 +00:00
|
|
|
Path: "entity-alias",
|
2017-10-11 17:21:20 +00:00
|
|
|
Data: registerData,
|
|
|
|
}
|
|
|
|
|
2018-09-18 03:03:00 +00:00
|
|
|
resp, err = is.HandleRequest(ctx, registerReq)
|
2017-10-11 17:21:20 +00:00
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("err:%v resp:%#v", err, resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
idRaw, ok := resp.Data["id"]
|
|
|
|
if !ok {
|
|
|
|
t.Fatalf("alias id not present in response")
|
|
|
|
}
|
|
|
|
id := idRaw.(string)
|
|
|
|
if id == "" {
|
|
|
|
t.Fatalf("invalid alias id")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read it back using alias id
|
|
|
|
aliasReq := &logical.Request{
|
|
|
|
Operation: logical.ReadOperation,
|
2017-11-14 01:59:42 +00:00
|
|
|
Path: "entity-alias/id/" + id,
|
2017-10-11 17:21:20 +00:00
|
|
|
}
|
2018-09-18 03:03:00 +00:00
|
|
|
resp, err = is.HandleRequest(ctx, aliasReq)
|
2017-10-11 17:21:20 +00:00
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("err:%v resp:%#v", err, resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp.Data["id"].(string) == "" ||
|
2017-11-02 20:05:48 +00:00
|
|
|
resp.Data["canonical_id"].(string) == "" ||
|
2017-10-11 17:21:20 +00:00
|
|
|
resp.Data["name"].(string) != registerData["name"] ||
|
2021-09-17 18:03:47 +00:00
|
|
|
resp.Data["mount_type"].(string) != "github" || !reflect.DeepEqual(resp.Data["custom_metadata"], customMetadata) {
|
2017-10-11 17:21:20 +00:00
|
|
|
t.Fatalf("bad: alias read response; \nexpected: %#v \nactual: %#v\n", registerData, resp.Data)
|
|
|
|
}
|
|
|
|
|
|
|
|
aliasReq.Operation = logical.DeleteOperation
|
2018-09-18 03:03:00 +00:00
|
|
|
resp, err = is.HandleRequest(ctx, aliasReq)
|
2017-10-11 17:21:20 +00:00
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("err:%v resp:%#v", err, resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
aliasReq.Operation = logical.ReadOperation
|
2018-09-18 03:03:00 +00:00
|
|
|
resp, err = is.HandleRequest(ctx, aliasReq)
|
2017-10-11 17:21:20 +00:00
|
|
|
if err != nil || (resp != nil && resp.IsError()) {
|
|
|
|
t.Fatalf("err:%v resp:%#v", err, resp)
|
|
|
|
}
|
|
|
|
if resp != nil {
|
|
|
|
t.Fatalf("bad: alias read response; expected: nil, actual: %#v\n", resp)
|
|
|
|
}
|
|
|
|
}
|