Skip to content

Commit 6cc14b4

Browse files
committed
Add rbac checks
1 parent d37379d commit 6cc14b4

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

coderd/authzquery/methods_test.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ var (
2727
}
2828
)
2929

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.
3336
type MethodTestSuite struct {
3437
suite.Suite
3538
// methodAccounting counts all methods called by a 'RunMethodTest'
@@ -113,6 +116,19 @@ MethodLoop:
113116
}
114117

115118
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")
116132
}
117133

118134
func methodInputs(inputs ...any) []reflect.Value {
@@ -135,6 +151,7 @@ func asserts(inputs ...any) []AssertRBAC {
135151
if !ok {
136152
panic(fmt.Sprintf("object type '%T' not a supported key", obj))
137153
}
154+
rbacObj := obj.RBACObject()
138155

139156
var actions []rbac.Action
140157
actions, ok = inputs[i+1].([]rbac.Action)
@@ -152,7 +169,7 @@ func asserts(inputs ...any) []AssertRBAC {
152169
}
153170

154171
out = append(out, AssertRBAC{
155-
Object: rbac.Object{},
172+
Object: rbacObj,
156173
Actions: actions,
157174
})
158175
}

0 commit comments

Comments
 (0)