From 15deea338c1c81bf93ef9eb5651019110f3a78d2 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Wed, 11 May 2022 06:17:02 -0500 Subject: [PATCH] Add test to make sure `/messages` behaves as expected for non-existent `room_id`'s (#369) * Add test to make sure /messages behaves as expected for non-existent room_ids Tests for Synapse regression fix: https://github.com/matrix-org/synapse/pull/12683 Issue: https://github.com/matrix-org/synapse/issues/12678 * Explain why 403 * Remove dendrite skip Co-authored-by: Kegan Dougal --- tests/csapi/room_messages_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/csapi/room_messages_test.go b/tests/csapi/room_messages_test.go index e5410668..eba09ca8 100644 --- a/tests/csapi/room_messages_test.go +++ b/tests/csapi/room_messages_test.go @@ -59,6 +59,24 @@ func TestSendAndFetchMessage(t *testing.T) { }) } +// With a non-existent room_id, GET /rooms/:room_id/messages returns 403 +// forbidden ("You aren't a member of the room"). +func TestFetchMessagesFromNonExistentRoom(t *testing.T) { + deployment := Deploy(t, b.BlueprintAlice) + defer deployment.Destroy(t) + + alice := deployment.Client(t, "hs1", "@alice:hs1") + roomID := "!does-not-exist:hs1" + + // then request messages from the room + queryParams := url.Values{} + queryParams.Set("dir", "b") + res := alice.DoFunc(t, "GET", []string{"_matrix", "client", "r0", "rooms", roomID, "messages"}, client.WithQueries(queryParams)) + must.MatchResponse(t, res, match.HTTPResponse{ + StatusCode: http.StatusForbidden, + }) +} + // sytest: PUT /rooms/:room_id/send/:event_type/:txn_id sends a message // sytest: PUT /rooms/:room_id/send/:event_type/:txn_id deduplicates the same txn id func TestSendMessageWithTxn(t *testing.T) {