dbauthzTestStore wraps the test database with the same dbauthz layer used in production (coderd.go:370). Without it the test would not catch RBAC failures from the chatd subject; with it the test fails loudly if the elevation in OIDCAccessToken is removed or weakened.
(t *testing.T, db database.Store)
| 25 | // catch RBAC failures from the chatd subject; with it the test fails |
| 26 | // loudly if the elevation in OIDCAccessToken is removed or weakened. |
| 27 | func dbauthzTestStore(t *testing.T, db database.Store) database.Store { |
| 28 | t.Helper() |
| 29 | |
| 30 | authz := rbac.NewStrictCachingAuthorizer(prometheus.NewRegistry()) |
| 31 | acs := &atomic.Pointer[dbauthz.AccessControlStore]{} |
| 32 | var tacs dbauthz.AccessControlStore = fakeAccessControlStore{} |
| 33 | acs.Store(&tacs) |
| 34 | return dbauthz.New(db, authz, testutil.Logger(t), acs) |
| 35 | } |
| 36 | |
| 37 | // fakeAccessControlStore mirrors coderdtest.FakeAccessControlStore but is |
| 38 | // inlined here to avoid an import cycle (coderdtest imports coderd). |
no test coverage detected