feat(tenant): 按租户隔离用户身份与后台权限

This commit is contained in:
yml
2026-11-15 15:37:23 +08:00
parent ca57f604bf
commit abf0fce89b
43 changed files with 1572 additions and 196 deletions
@@ -9,10 +9,22 @@ import (
"testing"
"time"
"hfb_sys/backend/internal/tenancy"
"github.com/gin-gonic/gin"
"github.com/redis/go-redis/v9"
)
func TestAdminPermissionCacheKeyIncludesTenant(t *testing.T) {
ctx := tenancy.WithScope(context.Background(), tenancy.Scope{TenantID: 101})
if got := adminPermissionCacheKey(ctx, 7); got != "admin:perms:7:tenant:101" {
t.Fatalf("tenant permission cache key = %q", got)
}
if got := adminPermissionCacheKey(context.Background(), 7); got != "admin:perms:7" {
t.Fatalf("legacy permission cache key = %q", got)
}
}
func TestRequireAnyPermission(t *testing.T) {
gin.SetMode(gin.TestMode)
rdb := redis.NewClient(&redis.Options{