Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c902715

Browse files
committed
Fix unit tests names
1 parent fdfdd73 commit c902715

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

coderd/authzquery/methods_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ func (s *MethodTestSuite) Subtest(testCaseF func(db database.Store, check *Metho
136136
if len(testCase.Assertions) > 0 {
137137
// Only run these tests if we know the underlying call makes
138138
// rbac assertions.
139-
s.TestNotAuthorized(ctx, fakeAuthorizer, callMethod)
140-
s.TestNoActor(callMethod)
139+
s.NotAuthorizedErrorTest(ctx, fakeAuthorizer, callMethod)
140+
s.NoActorErrorTest(callMethod)
141141
}
142142

143143
// Always run
@@ -180,17 +180,17 @@ func (s *MethodTestSuite) Subtest(testCaseF func(db database.Store, check *Metho
180180
}
181181
}
182182

183-
func (s *MethodTestSuite) TestNoActor(callMethod func(ctx context.Context) ([]reflect.Value, error)) {
183+
func (s *MethodTestSuite) NoActorErrorTest(callMethod func(ctx context.Context) ([]reflect.Value, error)) {
184184
s.Run("NoActor", func() {
185185
// Call without any actor
186186
_, err := callMethod(context.Background())
187187
s.ErrorIs(err, authzquery.NoActorError, "method should return NoActorError error when no actor is provided")
188188
})
189189
}
190190

191-
// TestNotAuthorized runs the given method with an authorizer that will fail authz.
191+
// NotAuthorizedErrorTest runs the given method with an authorizer that will fail authz.
192192
// Asserts that the error returned is a NotAuthorizedError.
193-
func (s *MethodTestSuite) TestNotAuthorized(ctx context.Context, az *coderdtest.FakeAuthorizer, callMethod func(ctx context.Context) ([]reflect.Value, error)) {
193+
func (s *MethodTestSuite) NotAuthorizedErrorTest(ctx context.Context, az *coderdtest.FakeAuthorizer, callMethod func(ctx context.Context) ([]reflect.Value, error)) {
194194
s.Run("NotAuthorized", func() {
195195
az.AlwaysReturn = xerrors.New("Always fail authz")
196196

@@ -302,8 +302,8 @@ MethodLoop:
302302
if len(testCase.Assertions) > 0 {
303303
// Only run these tests if we know the underlying call makes
304304
// rbac assertions.
305-
s.TestNotAuthorized(ctx, fakeAuthorizer, callMethod)
306-
s.TestNoActor(callMethod)
305+
s.NotAuthorizedErrorTest(ctx, fakeAuthorizer, callMethod)
306+
s.NoActorErrorTest(callMethod)
307307
}
308308

309309
// Always run

coderd/authzquery/workspace.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ func (q *AuthzQuerier) GetWorkspaceAgentByInstanceID(ctx context.Context, authIn
7474
// GetWorkspaceAgentsByResourceIDs is an all or nothing call. If the user cannot read
7575
// a single agent, the entire call will fail.
7676
func (q *AuthzQuerier) GetWorkspaceAgentsByResourceIDs(ctx context.Context, ids []uuid.UUID) ([]database.WorkspaceAgent, error) {
77+
if _, ok := ActorFromContext(ctx); !ok {
78+
return nil, NoActorError
79+
}
7780
// TODO: Make this more efficient. This is annoying because all these resources should be owned by the same workspace.
7881
// So the authz check should just be 1 check, but we cannot do that easily here. We should see if all callers can
7982
// instead do something like GetWorkspaceAgentsByWorkspaceID.

0 commit comments

Comments
 (0)