fix(chat): 修复跨站会话文件权限
This commit is contained in:
@@ -530,6 +530,86 @@ func TestQrCodeReplenishmentDoesNotCrossTenant(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestListingQrCodePoolDoesNotCrossTenant(t *testing.T) {
|
||||
db := setupQrCodeTestDB(t)
|
||||
otherTenantQR := model.ChatQrCode{
|
||||
TenantID: 101,
|
||||
ImageURL: "/api/files/object?key=qrcode%2Ftenant-a-only.png",
|
||||
Status: QrCodeStatusUnused,
|
||||
}
|
||||
if err := db.Create(&otherTenantQR).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
listing := model.RentalListing{
|
||||
ID: 301,
|
||||
SourceTenantID: 202,
|
||||
ListingNo: "L202611170301",
|
||||
OwnerID: 10,
|
||||
}
|
||||
var conversation *model.ChatConversation
|
||||
if err := db.Transaction(func(tx *gorm.DB) error {
|
||||
created, err := EnsureListingConversation(tx, listing, 0)
|
||||
conversation = created
|
||||
return err
|
||||
}); err != nil {
|
||||
t.Fatalf("建发布群失败: %v", err)
|
||||
}
|
||||
|
||||
var savedQR model.ChatQrCode
|
||||
if err := db.First(&savedQR, otherTenantQR.ID).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if savedQR.Status != QrCodeStatusUnused {
|
||||
t.Fatalf("其他租户二维码不得被消耗, status = %q", savedQR.Status)
|
||||
}
|
||||
var imageCount int64
|
||||
if err := db.Model(&model.ChatMessage{}).
|
||||
Where("conversation_id = ? AND content_type = ?", conversation.ID, "image").
|
||||
Count(&imageCount).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if imageCount != 0 {
|
||||
t.Fatalf("其他租户码池不得发送到当前群, image messages = %d", imageCount)
|
||||
}
|
||||
var task model.ChatQrCodeDeliveryTask
|
||||
if err := db.Where("conversation_id = ?", conversation.ID).First(&task).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if task.TenantID != 202 || task.Status != "pending" {
|
||||
t.Fatalf("补发任务 = %+v, want tenant 202 pending", task)
|
||||
}
|
||||
|
||||
ownTenantQR := model.ChatQrCode{
|
||||
TenantID: 202,
|
||||
ImageURL: "/api/files/object?key=qrcode%2Ftenant-b-only.png",
|
||||
Status: QrCodeStatusUnused,
|
||||
}
|
||||
if err := db.Create(&ownTenantQR).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.Transaction(func(tx *gorm.DB) error {
|
||||
_, err := deliverPendingQrCodes(tx, 202)
|
||||
return err
|
||||
}); err != nil {
|
||||
t.Fatalf("补发当前租户二维码失败: %v", err)
|
||||
}
|
||||
var usedOwnQR model.ChatQrCode
|
||||
if err := db.First(&usedOwnQR, ownTenantQR.ID).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if usedOwnQR.Status != QrCodeStatusUsed {
|
||||
t.Fatalf("当前租户二维码应被补发使用, status = %q", usedOwnQR.Status)
|
||||
}
|
||||
var unusedOtherQR model.ChatQrCode
|
||||
if err := db.First(&unusedOtherQR, otherTenantQR.ID).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if unusedOtherQR.Status != QrCodeStatusUnused {
|
||||
t.Fatalf("其他租户二维码仍不得被使用, status = %q", unusedOtherQR.Status)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnsureListingConversationIgnoresFixedQrAndUsesSitePool(t *testing.T) {
|
||||
db := setupQrCodeTestDB(t)
|
||||
site := model.DistributionSite{
|
||||
|
||||
Reference in New Issue
Block a user