feat(tenant): 按租户隔离用户身份与后台权限
This commit is contained in:
@@ -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{
|
||||
|
||||
Reference in New Issue
Block a user