@@ -114,9 +114,7 @@ func (s *MethodTestSuite) Subtest(testCaseF func(db database.Store, check *expec
114
114
s .methodAccounting [methodName ]++
115
115
116
116
db := dbmem .New ()
117
- fakeAuthorizer := & coderdtest.FakeAuthorizer {
118
- AlwaysReturn : nil ,
119
- }
117
+ fakeAuthorizer := & coderdtest.FakeAuthorizer {}
120
118
rec := & coderdtest.RecordingAuthorizer {
121
119
Wrapped : fakeAuthorizer ,
122
120
}
@@ -174,8 +172,11 @@ func (s *MethodTestSuite) Subtest(testCaseF func(db database.Store, check *expec
174
172
// Always run
175
173
s .Run ("Success" , func () {
176
174
rec .Reset ()
177
- fakeAuthorizer .AlwaysReturn = nil
178
- fakeAuthorizer .ConditionalReturn = testCase .successAuthorizer
175
+ if testCase .successAuthorizer != nil {
176
+ fakeAuthorizer .ConditionalReturn = testCase .successAuthorizer
177
+ } else {
178
+ fakeAuthorizer .AlwaysReturn (nil )
179
+ }
179
180
180
181
outputs , err := callMethod (ctx )
181
182
if testCase .err == nil {
@@ -233,7 +234,7 @@ func (s *MethodTestSuite) NoActorErrorTest(callMethod func(ctx context.Context)
233
234
// Asserts that the error returned is a NotAuthorizedError.
234
235
func (s * MethodTestSuite ) NotAuthorizedErrorTest (ctx context.Context , az * coderdtest.FakeAuthorizer , testCase expects , callMethod func (ctx context.Context ) ([]reflect.Value , error )) {
235
236
s .Run ("NotAuthorized" , func () {
236
- az .AlwaysReturn = rbac .ForbiddenWithInternal (xerrors .New ("Always fail authz" ), rbac.Subject {}, "" , rbac.Object {}, nil )
237
+ az .AlwaysReturn ( rbac .ForbiddenWithInternal (xerrors .New ("Always fail authz" ), rbac.Subject {}, "" , rbac.Object {}, nil ) )
237
238
238
239
// If we have assertions, that means the method should FAIL
239
240
// if RBAC will disallow the request. The returned error should
@@ -258,8 +259,8 @@ func (s *MethodTestSuite) NotAuthorizedErrorTest(ctx context.Context, az *coderd
258
259
// Pass in a canceled context
259
260
ctx , cancel := context .WithCancel (ctx )
260
261
cancel ()
261
- az .AlwaysReturn = rbac .ForbiddenWithInternal (& topdown.Error {Code : topdown .CancelErr },
262
- rbac.Subject {}, "" , rbac.Object {}, nil )
262
+ az .AlwaysReturn ( rbac .ForbiddenWithInternal (& topdown.Error {Code : topdown .CancelErr },
263
+ rbac.Subject {}, "" , rbac.Object {}, nil ))
263
264
264
265
// If we have assertions, that means the method should FAIL
265
266
// if RBAC will disallow the request. The returned error should
0 commit comments