fix(tenant): 封堵审计文件与历史用户跨站访问
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package adminaudit
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"hfb_sys/backend/internal/database"
|
||||
"hfb_sys/backend/internal/model"
|
||||
"hfb_sys/backend/internal/tenancy"
|
||||
)
|
||||
|
||||
func TestListIsScopedByOperatingTenant(t *testing.T) {
|
||||
db := database.NewTestDB()
|
||||
rows := []model.AuditLog{
|
||||
{TenantID: 101, ActorType: "admin", ActorID: 1, Action: "tenant.a", BizType: "test"},
|
||||
{TenantID: 202, ActorType: "admin", ActorID: 2, Action: "tenant.b", BizType: "test"},
|
||||
{TenantID: 0, ActorType: "admin", ActorID: 3, Action: "platform", BizType: "test"},
|
||||
}
|
||||
if err := db.Create(&rows).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ctx := tenancy.WithScope(context.Background(), tenancy.Scope{TenantID: 101})
|
||||
result, err := NewRepository(db).List(ctx, Query{Page: 1, PageSize: 20})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
items := result.Items.([]LogDTO)
|
||||
if result.Total != 1 || len(items) != 1 || items[0].Action != "tenant.a" {
|
||||
t.Fatalf("tenant audit list = %+v", result)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user