Skip to content

Commit 4da40dc

Browse files
committed
requested changes
1 parent 33e6d7b commit 4da40dc

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

internal/client/client.go

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

199-
func (c *CSAPI) SendRedaction(t *testing.T, roomID string, e b.Event, eventID string) {
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 {
200201
t.Helper()
201202
c.txnID++
202203
paths := []string{"_matrix", "client", "v3", "rooms", roomID, "redact", eventID, strconv.Itoa(c.txnID)}
203-
c.MustDoFunc(t, "PUT", paths, WithJSONBody(t, e.Content))
204+
res := c.MustDoFunc(t, "PUT", paths, WithJSONBody(t, e.Content))
205+
body := ParseJSON(t, res)
206+
return GetJSONFieldStr(t, body, "event_id")
204207
}
205208

206209
// Perform a single /sync request with the given request options. To sync until something happens,

tests/federation_redaction_test.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,16 @@ import (
55
"github.com/matrix-org/complement/internal/docker"
66
"github.com/matrix-org/complement/internal/federation"
77
"github.com/matrix-org/gomatrixserverlib"
8-
"os"
98
"testing"
109
"time"
1110
)
1211

1312
// test that a redaction is sent out over federation even if we don't have the original event
1413
func TestFederationRedactSendsWithoutEvent(t *testing.T) {
15-
os.Setenv("COMPLEMENT_DEBUG", "1")
1614
deployment := Deploy(t, b.BlueprintAlice)
1715
defer deployment.Destroy(t)
1816

19-
roxy := deployment.RegisterUser(t, "hs1", "roxy", "verygoodpass", true)
17+
alice := deployment.Client(t, "hs1", "@alice:hs1")
2018

2119
waiter := NewWaiter()
2220
wantEventType := "m.room.redaction"
@@ -43,17 +41,17 @@ func TestFederationRedactSendsWithoutEvent(t *testing.T) {
4341
// create username
4442
charlie := srv.UserID("charlie")
4543

46-
ver := roxy.GetDefaultRoomVersion(t)
44+
ver := alice.GetDefaultRoomVersion(t)
4745

48-
// the remote homeserver creates a public room
46+
// the remote homeserver creates a public room allowing anyone to redact
4947
initalEvents := federation.InitialRoomEvents(ver, charlie)
5048
plEvent := initalEvents[2]
5149
plEvent.Content["redact"] = 0
5250
serverRoom := srv.MustMakeRoom(t, ver, initalEvents)
5351
roomAlias := srv.MakeAliasMapping("flibble", serverRoom.RoomID)
5452

5553
// the local homeserver joins the room
56-
roxy.JoinRoom(t, roomAlias, []string{docker.HostnameRunningComplement})
54+
alice.JoinRoom(t, roomAlias, []string{docker.HostnameRunningComplement})
5755

5856
// inject event to redact in the room
5957
badEvent := srv.MustCreateEvent(t, serverRoom, b.Event{
@@ -70,7 +68,7 @@ func TestFederationRedactSendsWithoutEvent(t *testing.T) {
7068
eventToRedact := eventID + ":" + fullServerName
7169

7270
// the client sends a request to the local homeserver to send the redaction
73-
roxy.SendRedaction(t, serverRoom.RoomID, b.Event{Type: wantEventType, Content: map[string]interface{}{
71+
res := alice.SendRedaction(t, serverRoom.RoomID, b.Event{Type: wantEventType, Content: map[string]interface{}{
7472
"msgtype": "m.room.redaction"},
7573
Redacts: eventToRedact}, eventToRedact)
7674

@@ -82,6 +80,12 @@ func TestFederationRedactSendsWithoutEvent(t *testing.T) {
8280
lastEventType := lastEvent.Type()
8381
wantedType := "m.room.redaction"
8482
if lastEventType != wantedType {
85-
t.Fatalf("Incorrent event type, wanted m.room.redaction.")
83+
t.Fatalf("Incorrent event type %s, wanted m.room.redaction.", lastEventType)
8684
}
85+
86+
// check that the event id of the redaction sent by alice is the same as the redaction event in the room
87+
if res != lastEvent.EventID() {
88+
t.Fatalf("Incorrent event id %s, wanted %s.", res, lastEvent.EventID())
89+
}
90+
8791
}

0 commit comments

Comments
 (0)