Skip to content

Commit bbe4f18

Browse files
committed
User proper rbac errors in unit test
1 parent 035609b commit bbe4f18

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

coderd/coderd.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,6 @@ func New(options *Options) *API {
325325
DisableSessionExpiryRefresh: options.DeploymentConfig.DisableSessionExpiryRefresh.Value,
326326
Optional: true,
327327
}),
328-
// TODO: We should remove this auth context after middleware.
329328
httpmw.AsAuthzSystem(
330329
// Redirect to the login page if the user tries to open an app with
331330
// "me" as the username and they are not logged in.

coderd/database/dbauthz/setup_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func (s *MethodTestSuite) NoActorErrorTest(callMethod func(ctx context.Context)
201201
// Asserts that the error returned is a NotAuthorizedError.
202202
func (s *MethodTestSuite) NotAuthorizedErrorTest(ctx context.Context, az *coderdtest.FakeAuthorizer, callMethod func(ctx context.Context) ([]reflect.Value, error)) {
203203
s.Run("NotAuthorized", func() {
204-
az.AlwaysReturn = xerrors.New("Always fail authz")
204+
az.AlwaysReturn = rbac.ForbiddenWithInternal(xerrors.New("Always fail authz"), rbac.Subject{}, "", rbac.Object{}, nil)
205205

206206
// If we have assertions, that means the method should FAIL
207207
// if RBAC will disallow the request. The returned error should
@@ -211,6 +211,7 @@ func (s *MethodTestSuite) NotAuthorizedErrorTest(ctx context.Context, az *coderd
211211
// This is unfortunate, but if we are using `Filter` the error returned will be nil. So filter out
212212
// any case where the error is nil and the response is an empty slice.
213213
if err != nil || !hasEmptySliceResponse(resp) {
214+
s.ErrorContainsf(err, "unauthorized", "error string should have a good message")
214215
s.Errorf(err, "method should an error with disallow authz")
215216
s.ErrorIsf(err, sql.ErrNoRows, "error should match sql.ErrNoRows")
216217
s.ErrorAs(err, &dbauthz.NotAuthorizedError{}, "error should be NotAuthorizedError")

0 commit comments

Comments
 (0)