- Notifications
You must be signed in to change notification settings - Fork1k
feat: improve RBAC resource ID matching and structured allowlist targets#20035
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:thomask33/09-29-feat_typed_rbac_allow_list
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package coderd | ||
import ( | ||
"testing" | ||
"time" | ||
"github.com/google/uuid" | ||
"github.com/stretchr/testify/require" | ||
"go.uber.org/mock/gomock" | ||
"github.com/coder/coder/v2/coderd/database" | ||
"github.com/coder/coder/v2/coderd/database/dbmock" | ||
"github.com/coder/coder/v2/coderd/rbac/policy" | ||
"github.com/coder/coder/v2/codersdk" | ||
) | ||
func TestConvertAPIKeyAllowListDisplayName(t *testing.T) { | ||
t.Parallel() | ||
ctrl := gomock.NewController(t) | ||
t.Cleanup(ctrl.Finish) | ||
db := dbmock.NewMockStore(ctrl) | ||
templateID := uuid.New() | ||
db.EXPECT(). | ||
GetTemplateByID(gomock.Any(), templateID). | ||
Return(database.Template{ | ||
ID: templateID, | ||
Name: "infra-template", | ||
DisplayName: "Infra Template", | ||
}, nil). | ||
Times(1) | ||
key := database.APIKey{ | ||
ID: "key-1", | ||
UserID: uuid.New(), | ||
LastUsed: time.Now(), | ||
ExpiresAt: time.Now().Add(time.Hour), | ||
CreatedAt: time.Now(), | ||
UpdatedAt: time.Now(), | ||
LoginType: database.LoginTypeToken, | ||
LifetimeSeconds: int64(time.Hour.Seconds()), | ||
TokenName: "cli", | ||
Scopes: database.APIKeyScopes{database.ApiKeyScopeCoderAll}, | ||
AllowList: database.AllowList{ | ||
{Type: string(codersdk.ResourceTemplate), ID: templateID.String()}, | ||
}, | ||
} | ||
result := convertAPIKey(key) | ||
require.Len(t, result.AllowList, 1) | ||
require.Equal(t, codersdk.ResourceTemplate, result.AllowList[0].Type) | ||
require.Equal(t, templateID.String(), result.AllowList[0].ID) | ||
require.Equal(t, "Infra Template", result.AllowList[0].DisplayName) | ||
} | ||
func TestConvertAPIKeyAllowListDisplayNameWildcard(t *testing.T) { | ||
t.Parallel() | ||
ctrl := gomock.NewController(t) | ||
t.Cleanup(ctrl.Finish) | ||
key := database.APIKey{ | ||
ID: "key-2", | ||
AllowList: database.AllowList{ | ||
{Type: string(codersdk.ResourceWildcard), ID: policy.WildcardSymbol}, | ||
}, | ||
} | ||
result := convertAPIKey(key) | ||
require.Len(t, result.AllowList, 1) | ||
require.Equal(t, codersdk.ResourceWildcard, result.AllowList[0].Type) | ||
require.Equal(t, "*", result.AllowList[0].ID) | ||
require.Empty(t, result.AllowList[0].DisplayName) | ||
} |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.