MCPcopy Index your code
hub / github.com/coder/coder / injectSystemActor

Function injectSystemActor

coderd/workspaceagents_internal_test.go:100–104  ·  view source on GitHub ↗

injectSystemActor is a test-only middleware that seeds an RBAC actor into the request context so handlers using api.Authorize do not panic via httpmw.UserAuthorization. Pair it with mockAuthorizer to short-circuit authorization in tests that focus on plumbing rather than RBAC.

(next http.Handler)

Source from the content-addressed store, hash-verified

98// short-circuit authorization in tests that focus on plumbing rather
99// than RBAC.
100func injectSystemActor(next http.Handler) http.Handler {
101 return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
102 next.ServeHTTP(rw, r.WithContext(dbauthz.AsSystemRestricted(r.Context())))
103 })
104}
105
106// runWatchChatGitWorkspaceLookupTest exercises the GetWorkspaceByID
107// error branches in authorizeChatWorkspaceExec. The chat middleware

Callers

nothing calls this directly

Calls 4

AsSystemRestrictedFunction · 0.92
WithContextMethod · 0.80
ContextMethod · 0.65
ServeHTTPMethod · 0.45

Tested by

no test coverage detected