fix: resolve P1 backend consistency issues

This commit is contained in:
richjohnrambo
2026-09-08 16:23:21 +08:00
parent 06945a4050
commit 0b3c0b1c78
13 changed files with 587 additions and 57 deletions
+37
View File
@@ -3,6 +3,7 @@ package main
import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"os"
@@ -941,6 +942,9 @@ func TestHandleBroadcastDataRejectsMentionAllByMember(t *testing.T) {
pud.modeWant = types.ModeCPublic
pud.modeGiven = types.ModeCPublic
helper.topic.perUser[helper.uids[0]] = pud
helper.ss.EXPECT().Get(types.TenantID(1), "grp-test", helper.uids[0], false).Return(&types.Subscription{
TenantID: 1, Topic: "grp-test", User: helper.uids[0].String(), ModeWant: types.ModeCPublic, ModeGiven: types.ModeCPublic,
}, nil)
from := helper.uids[0].UserId()
msg := &ClientComMessage{
@@ -963,6 +967,39 @@ func TestHandleBroadcastDataRejectsMentionAllByMember(t *testing.T) {
}
}
func TestValidateMessageReplacementChecksAuthorAndWindow(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
oldMessages := store.Messages
messages := mock_store.NewMockMessagesPersistenceInterface(ctrl)
store.Messages = messages
t.Cleanup(func() { store.Messages = oldMessages })
now := time.Date(2026, 9, 6, 10, 0, 0, 0, time.UTC)
topic := &Topic{tenantID: 7, name: "grpAlpha"}
author := types.Uid(42)
messages.EXPECT().GetOne(types.TenantID(7), "grpAlpha", int64(8)).Return(&types.Message{
Topic: "grpAlpha", SeqId: 8, From: author.String(), ObjHeader: types.ObjHeader{CreatedAt: now.Add(-time.Minute)},
}, nil)
if err := topic.validateMessageReplacement(author, map[string]any{"replace": ":8"}, now); err != nil {
t.Fatalf("valid replacement rejected: %v", err)
}
messages.EXPECT().GetOne(types.TenantID(7), "grpAlpha", int64(9)).Return(&types.Message{
Topic: "grpAlpha", SeqId: 9, From: types.Uid(99).String(), ObjHeader: types.ObjHeader{CreatedAt: now.Add(-time.Minute)},
}, nil)
if err := topic.validateMessageReplacement(author, map[string]any{"replace": ":9"}, now); !errors.Is(err, types.ErrPermissionDenied) {
t.Fatalf("replacement of peer message: got %v", err)
}
messages.EXPECT().GetOne(types.TenantID(7), "grpAlpha", int64(10)).Return(&types.Message{
Topic: "grpAlpha", SeqId: 10, From: author.String(), ObjHeader: types.ObjHeader{CreatedAt: now.Add(-6 * time.Minute)},
}, nil)
if err := topic.validateMessageReplacement(author, map[string]any{"replace": ":10"}, now); !errors.Is(err, types.ErrPermissionDenied) {
t.Fatalf("expired replacement: got %v", err)
}
}
func TestHandleBroadcastDataFiltersInvalidMentions(t *testing.T) {
numUsers := 2
helper := TopicTestHelper{}