Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ func (c *CSAPI) SendRedaction(t ct.TestLike, roomID string, content map[string]i
return c.Do(t, "PUT", paths, WithJSONBody(t, content))
}

// MustGetStateEvent returns the event content for the given state event. Fails the test if the state event does not exist.
// MustGetStateEventContent returns the event content for the given state event. Fails the test if the state event does not exist.
func (c *CSAPI) MustGetStateEventContent(t ct.TestLike, roomID, eventType, stateKey string) (content gjson.Result) {
t.Helper()
res := c.GetStateEventContent(t, roomID, eventType, stateKey)
Expand All @@ -468,12 +468,27 @@ func (c *CSAPI) MustGetStateEventContent(t ct.TestLike, roomID, eventType, state
return gjson.ParseBytes(body)
}

// GetStateEvent returns the event content for the given state event. Use this form to detect absence via 404.
// GetStateEventContent returns the event content for the given state event. Use this form to detect absence via 404.
func (c *CSAPI) GetStateEventContent(t ct.TestLike, roomID, eventType, stateKey string) *http.Response {
t.Helper()
return c.Do(t, "GET", []string{"_matrix", "client", "v3", "rooms", roomID, "state", eventType, stateKey})
}

// MustGetEvent returns the event content for the given state event. Fails the test if the state event does not exist.
func (c *CSAPI) MustGetEvent(t ct.TestLike, roomID, eventID string) (eventJson gjson.Result) {
t.Helper()
res := c.GetEvent(t, roomID, eventID)
mustRespond2xx(t, res)
body := ParseJSON(t, res)
return gjson.ParseBytes(body)
}

// GetEvent returns the event JSON. Use this form to detect absence via 404.
func (c *CSAPI) GetEvent(t ct.TestLike, roomID, eventID string) *http.Response {
t.Helper()
return c.Do(t, "GET", []string{"_matrix", "client", "v3", "rooms", roomID, "event", eventID})
}

// MustSendTyping marks this user as typing until the timeout is reached. If isTyping is false, timeout is ignored.
func (c *CSAPI) MustSendTyping(t ct.TestLike, roomID string, isTyping bool, timeoutMillis int) {
res := c.SendTyping(t, roomID, isTyping, timeoutMillis)
Expand Down
60 changes: 60 additions & 0 deletions tests/csapi/redact_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package csapi_tests

import (
"testing"

"github.com/matrix-org/complement"
"github.com/matrix-org/complement/b"
"github.com/matrix-org/complement/helpers"
"github.com/matrix-org/complement/match"
"github.com/matrix-org/complement/must"
)

// Test `PUT /_matrix/client/v3/rooms/{roomId}/redact/{eventId}/{txnId} ` (redactions)
func TestRedact(t *testing.T) {
deployment := complement.Deploy(t, 1)
defer deployment.Destroy(t)

alice := deployment.Register(t, "hs1", helpers.RegistrationOpts{
LocalpartSuffix: "alice",
})
bob := deployment.Register(t, "hs1", helpers.RegistrationOpts{
LocalpartSuffix: "bob",
})

// Alice creates the room
roomID := alice.MustCreateRoom(t, map[string]interface{}{
// Just making it easier for everyone to join
"preset": "public_chat",
})
// Bob joins the room
bob.MustJoinRoom(t, roomID, nil)

t.Run("Event content is redacted", func(t *testing.T) {
// Alice creates an event
expectedEventContent := map[string]interface{}{
"msgtype": "m.text",
"body": "expected message body",
}
eventIDToRedact := alice.SendEventSynced(t, roomID, b.Event{
Type: "m.room.message",
Content:expectedEventContent,
})

// Bob can see the event content
eventJsonBefore := bob.MustGetEvent(t, roomID, eventIDToRedact)
must.MatchGJSON(t, eventJsonBefore, match.JSONKeyEqual("content", expectedEventContent))

// Alice redacts the event
alice.MustSendRedaction(t, roomID, map[string]interface{}{
"reason": "reasons...",
}, eventIDToRedact)

// Bob can no longer see the event content
eventJsonAfter := bob.MustGetEvent(t, roomID, eventIDToRedact)
must.MatchGJSON(t, eventJsonAfter, match.JSONKeyEqual("content", map[string]interface{}{
// no content
}))
})

}
Loading