Skip to content

Commit 0ca3730

Browse files
authored
Merge pull request #462 from matrix-org/shay/no_redact
Add a test to verify that redactions are sent out over federation without having the original event
2 parents b9753e0 + d6dea53 commit 0ca3730

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

internal/client/client.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,16 @@ func (c *CSAPI) SendEventSynced(t *testing.T, roomID string, e b.Event) string {
196196
return eventID
197197
}
198198

199+
// SendRedaction sends a redaction request. Will fail if the returned HTTP request code is not 200
200+
func (c *CSAPI) SendRedaction(t *testing.T, roomID string, e b.Event, eventID string) string {
201+
t.Helper()
202+
c.txnID++
203+
paths := []string{"_matrix", "client", "v3", "rooms", roomID, "redact", eventID, strconv.Itoa(c.txnID)}
204+
res := c.MustDoFunc(t, "PUT", paths, WithJSONBody(t, e.Content))
205+
body := ParseJSON(t, res)
206+
return GetJSONFieldStr(t, body, "event_id")
207+
}
208+
199209
// Perform a single /sync request with the given request options. To sync until something happens,
200210
// see `MustSyncUntil`.
201211
//

tests/federation_redaction_test.go

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package tests
2+
3+
import (
4+
"github.com/matrix-org/complement/internal/b"
5+
"github.com/matrix-org/complement/internal/federation"
6+
"github.com/matrix-org/complement/runtime"
7+
"github.com/matrix-org/gomatrixserverlib"
8+
"testing"
9+
"time"
10+
)
11+
12+
// test that a redaction is sent out over federation even if we don't have the original event
13+
func TestFederationRedactSendsWithoutEvent(t *testing.T) {
14+
runtime.SkipIf(t, runtime.Dendrite)
15+
16+
deployment := Deploy(t, b.BlueprintAlice)
17+
defer deployment.Destroy(t)
18+
19+
alice := deployment.Client(t, "hs1", "@alice:hs1")
20+
21+
waiter := NewWaiter()
22+
wantEventType := "m.room.redaction"
23+
24+
// create a remote homeserver
25+
srv := federation.NewServer(t, deployment,
26+
federation.HandleKeyRequests(),
27+
federation.HandleMakeSendJoinRequests(),
28+
federation.HandleTransactionRequests(
29+
// listen for PDU events in transactions
30+
func(ev *gomatrixserverlib.Event) {
31+
defer waiter.Finish()
32+
33+
if ev.Type() != wantEventType {
34+
t.Errorf("Wrong event type, got %s want %s", ev.Type(), wantEventType)
35+
}
36+
},
37+
nil,
38+
),
39+
)
40+
cancel := srv.Listen()
41+
defer cancel()
42+
43+
// create username
44+
charlie := srv.UserID("charlie")
45+
46+
ver := alice.GetDefaultRoomVersion(t)
47+
48+
// the remote homeserver creates a public room allowing anyone to redact
49+
initalEvents := federation.InitialRoomEvents(ver, charlie)
50+
plEvent := initalEvents[2]
51+
plEvent.Content["redact"] = 0
52+
serverRoom := srv.MustMakeRoom(t, ver, initalEvents)
53+
roomAlias := srv.MakeAliasMapping("flibble", serverRoom.RoomID)
54+
55+
// the local homeserver joins the room
56+
alice.JoinRoom(t, roomAlias, []string{srv.ServerName()})
57+
58+
// inject event to redact in the room
59+
badEvent := srv.MustCreateEvent(t, serverRoom, b.Event{
60+
Type: "m.room.message",
61+
Sender: charlie,
62+
Content: map[string]interface{}{
63+
"body": "666",
64+
},
65+
})
66+
serverRoom.AddEvent(badEvent)
67+
68+
eventID := badEvent.EventID()
69+
fullServerName := srv.ServerName()
70+
eventToRedact := eventID + ":" + fullServerName
71+
72+
// the client sends a request to the local homeserver to send the redaction
73+
res := alice.SendRedaction(t, serverRoom.RoomID, b.Event{Type: wantEventType, Content: map[string]interface{}{
74+
"msgtype": "m.room.redaction"},
75+
Redacts: eventToRedact}, eventToRedact)
76+
77+
// wait for redaction to arrive at remote homeserver
78+
waiter.Wait(t, 1*time.Second)
79+
80+
// Check that the last event in the room is now the redaction
81+
lastEvent := serverRoom.Timeline[len(serverRoom.Timeline)-1]
82+
lastEventType := lastEvent.Type()
83+
wantedType := "m.room.redaction"
84+
if lastEventType != wantedType {
85+
t.Fatalf("Incorrent event type %s, wanted m.room.redaction.", lastEventType)
86+
}
87+
88+
// check that the event id of the redaction sent by alice is the same as the redaction event in the room
89+
if res != lastEvent.EventID() {
90+
t.Fatalf("Incorrent event id %s, wanted %s.", res, lastEvent.EventID())
91+
}
92+
93+
}

0 commit comments

Comments
 (0)