Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions coderd/rbac/authz.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ func (a RegoAuthorizer) Prepare(ctx context.Context, subject Subject, action Act

prepared, err := a.newPartialAuthorizer(ctx, subject, action, objectType)
if err != nil {
err = correctCancelError(err)
return nil, xerrors.Errorf("new partial authorizer: %w", err)
}

Expand Down
18 changes: 18 additions & 0 deletions coderd/rbac/authz_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,24 @@ func TestAuthorizeScope(t *testing.T) {
)
}

func TestCanceledPrepare(t *testing.T) {
t.Parallel()

authorizer := NewAuthorizer(prometheus.NewRegistry())
// This context is canceled intentionally to test the prepare error.
ctx, cancel := context.WithCancel(context.Background())
cancel()

// The error should be a `context.Canceled` error.
// By default Rego throws a custom cancelled error.
_, err := authorizer.Prepare(ctx, Subject{
ID: "foo",
Roles: RoleNames{RoleOwner()},
Scope: ScopeAll,
}, ActionRead, ResourceWorkspace.Type)
require.ErrorIs(t, err, context.Canceled, "expected canceled context")
}

// cases applies a given function to all test cases. This makes generalities easier to create.
func cases(opt func(c authTestCase) authTestCase, cases []authTestCase) []authTestCase {
if opt == nil {
Expand Down