27
27
}
28
28
)
29
29
30
- // Define the suite, and absorb the built-in basic suite
31
- // functionality from testify - including a T() method which
32
- // returns the current testing context
30
+ // MethodTestSuite runs all methods tests for AuthzQuerier. The reason we use
31
+ // a test suite, is so we can account for all functions tested on the AuthzQuerier.
32
+ // We can then assert all methods were tested and asserted for proper RBAC
33
+ // checks. This forces RBAC checks to be written for all methods.
34
+ // Additionally, the way unit tests are written allows for easily executing
35
+ // a single test for debugging.
33
36
type MethodTestSuite struct {
34
37
suite.Suite
35
38
// methodAccounting counts all methods called by a 'RunMethodTest'
@@ -113,6 +116,19 @@ MethodLoop:
113
116
}
114
117
115
118
require .True (t , found , "method %q does not exist" , testName )
119
+
120
+ var pairs []coderdtest.ActionObjectPair
121
+ for _ , assrt := range testCase .Assertions {
122
+ for _ , action := range assrt .Actions {
123
+ pairs = append (pairs , coderdtest.ActionObjectPair {
124
+ Action : action ,
125
+ Object : assrt .Object ,
126
+ })
127
+ }
128
+ }
129
+
130
+ rec .AssertActor (t , actor , pairs ... )
131
+ require .NoError (t , rec .AllAsserted (), "all rbac calls must be asserted" )
116
132
}
117
133
118
134
func methodInputs (inputs ... any ) []reflect.Value {
@@ -135,6 +151,7 @@ func asserts(inputs ...any) []AssertRBAC {
135
151
if ! ok {
136
152
panic (fmt .Sprintf ("object type '%T' not a supported key" , obj ))
137
153
}
154
+ rbacObj := obj .RBACObject ()
138
155
139
156
var actions []rbac.Action
140
157
actions , ok = inputs [i + 1 ].([]rbac.Action )
@@ -152,7 +169,7 @@ func asserts(inputs ...any) []AssertRBAC {
152
169
}
153
170
154
171
out = append (out , AssertRBAC {
155
- Object : rbac. Object {} ,
172
+ Object : rbacObj ,
156
173
Actions : actions ,
157
174
})
158
175
}
0 commit comments