Files
threshold/internal/iam/ids_test.go
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

52 lines
1.5 KiB
Go
Raw Normal View History

2020-08-10 17:15:02 -04:00
// Copyright (c) HashiCorp, Inc.
2023-02-02 17:15:17 -08:00
// SPDX-License-Identifier: BUSL-1.1
2020-06-11 16:36:47 -04:00
package iam
import (
"context"
2020-06-11 16:36:47 -04:00
"strings"
"testing"
"github.com/hashicorp/boundary/globals"
2020-11-05 16:54:03 -05:00
"github.com/hashicorp/boundary/internal/errors"
2020-08-10 17:15:02 -04:00
"github.com/hashicorp/boundary/internal/types/scope"
2020-06-11 16:36:47 -04:00
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func Test_PublicIds(t *testing.T) {
ctx := context.Background()
2020-06-15 12:42:08 -04:00
t.Run("role", func(t *testing.T) {
id, err := newRoleId(ctx)
2020-06-15 12:42:08 -04:00
require.NoError(t, err)
assert.True(t, strings.HasPrefix(id, globals.RolePrefix+"_"))
2020-06-15 12:42:08 -04:00
})
2020-06-11 16:36:47 -04:00
t.Run("user", func(t *testing.T) {
id, err := newUserId(ctx)
2020-06-11 16:36:47 -04:00
require.NoError(t, err)
assert.True(t, strings.HasPrefix(id, globals.UserPrefix+"_"))
2020-06-11 16:36:47 -04:00
})
t.Run("group", func(t *testing.T) {
id, err := newGroupId(ctx)
2020-06-11 16:36:47 -04:00
require.NoError(t, err)
assert.True(t, strings.HasPrefix(id, globals.GroupPrefix+"_"))
2020-06-11 16:36:47 -04:00
})
t.Run("oidc managed group", func(t *testing.T) {
assert.True(t, strings.HasPrefix("mgoidc_1234567890", globals.OidcManagedGroupPrefix+"_"))
})
t.Run("scopes", func(t *testing.T) {
id, err := newScopeId(ctx, scope.Org)
require.NoError(t, err)
2020-07-11 12:00:49 -04:00
assert.True(t, strings.HasPrefix(id, scope.Org.Prefix()))
id, err = newScopeId(ctx, scope.Project)
require.NoError(t, err)
assert.True(t, strings.HasPrefix(id, scope.Project.Prefix()))
id, err = newScopeId(ctx, scope.Unknown)
require.Error(t, err)
assert.Empty(t, id)
2020-12-23 11:00:00 -08:00
assert.True(t, errors.Match(errors.T(errors.InvalidParameter), err))
})
2020-06-11 16:36:47 -04:00
}