test(rbac): cover review gaps from PR 2 self-review
- Add TestRequireRole_CrossTenantSuperuserBypass: pin the CanAccessAllTenants -> Owner-gate bypass behaviour for RequireRole, matching the existing coverage on RequireOwnershipOrRole. Catches reorderings of the fast paths that would re-lock org-level superusers out of foreign-tenant Owner-only routes. - Add TestAgentCreatorLookup_CrossTenantIsHiddenAsNotFound: lock down the defence-in-depth tenant re-check inside AgentCreatorLookup so a future refactor that loosens the service-layer scope (or wires a cross-tenant variant by mistake) cannot leak access via the ownership shortcut. - Reword RequireOwnershipOrRole step 7-8 doc comment so "role check already failed" is unambiguous (it refers to step 1 above). - Annotate the synthetic-system-user construction in middleware/auth.go with a back-pointer to types.IsSyntheticUserID so anyone changing the prefix or numeric suffix knows to update the helper too.
This commit is contained in:
@@ -220,6 +220,12 @@ func Auth(
|
||||
// 确保所有依赖 UserContextKey 的下游 handler 正常工作。
|
||||
user, err := userService.GetUserByTenantID(c.Request.Context(), tenantID)
|
||||
if err != nil || user == nil {
|
||||
// Synthetic user. The "system-<tenantID>" shape is recognised
|
||||
// by types.IsSyntheticUserID, which RBAC service-layer code
|
||||
// uses to skip recording these IDs as a resource creator.
|
||||
// Do NOT change the prefix or numeric suffix without
|
||||
// updating that helper, otherwise KB/Agent CreatorID will
|
||||
// silently start pointing at the synthetic user again.
|
||||
user = &types.User{
|
||||
ID: fmt.Sprintf("system-%d", tenantID),
|
||||
Username: fmt.Sprintf("system-%d", tenantID),
|
||||
|
||||
Reference in New Issue
Block a user