This adds several relationships into the resource package that are then made use of to improve the grant validation that runs during Parse. By understanding mappings between ID and resource type the validation checks can far better align with actual allowed grant formats so we can find several common misunderstandings before they simply result in an authorization failure. In the future some of these functions could be used in the logic in the actual ACL checks but it's not currently necessary and I don't want to lump that change in with this. Note that the tests have not meaningfully changed, but they _have_ had to be updated because the stricter validation is actually catching issues.
29 lines
812 B
Go
29 lines
812 B
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
package globals
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/boundary/internal/types/resource"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestResourceTypeFromPrefix(t *testing.T) {
|
|
// Test a random sampling
|
|
vals := map[string]resource.Type{
|
|
VaultCredentialLibraryPrefix: resource.CredentialLibrary,
|
|
OidcManagedGroupPrefix: resource.ManagedGroup,
|
|
StaticHostSetPrefix: resource.HostSet,
|
|
JsonCredentialPrefix: resource.Credential,
|
|
}
|
|
|
|
for prefix, typ := range vals {
|
|
assert.Equal(t, typ, ResourceTypeFromPrefix(prefix))
|
|
assert.Equal(t, typ, ResourceTypeFromPrefix(fmt.Sprintf("%s_foobar", prefix)))
|
|
assert.Equal(t, resource.Unknown, ResourceTypeFromPrefix(fmt.Sprintf("%sfoobar", prefix)))
|
|
}
|
|
}
|