From 792b0657d2862381bc50685b13edc3a108fbd0a5 Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Wed, 25 Sep 2024 10:22:24 -0400 Subject: [PATCH] Always check the errcode in failure responses --- tests/rest/client/test_owned_state.py | 56 +++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/tests/rest/client/test_owned_state.py b/tests/rest/client/test_owned_state.py index e1022dd7a3b..5fb57676762 100644 --- a/tests/rest/client/test_owned_state.py +++ b/tests/rest/client/test_owned_state.py @@ -68,7 +68,7 @@ def test_user_can_set_state_with_own_userid_key(self) -> None: ) def test_room_creator_cannot_set_state_with_own_suffixed_key(self) -> None: - self.helper.send_state( + body = self.helper.send_state( self.room_id, _STATE_EVENT_TEST_TYPE, {}, @@ -77,8 +77,14 @@ def test_room_creator_cannot_set_state_with_own_suffixed_key(self) -> None: expect_code=HTTPStatus.FORBIDDEN, ) + self.assertEqual( + body["errcode"], + Codes.FORBIDDEN, + body, + ) + def test_room_creator_cannot_set_state_with_other_userid_key(self) -> None: - self.helper.send_state( + body = self.helper.send_state( self.room_id, _STATE_EVENT_TEST_TYPE, {}, @@ -87,8 +93,14 @@ def test_room_creator_cannot_set_state_with_other_userid_key(self) -> None: expect_code=HTTPStatus.FORBIDDEN, ) + self.assertEqual( + body["errcode"], + Codes.FORBIDDEN, + body, + ) + def test_room_creator_cannot_set_state_with_other_suffixed_key(self) -> None: - self.helper.send_state( + body = self.helper.send_state( self.room_id, _STATE_EVENT_TEST_TYPE, {}, @@ -97,6 +109,12 @@ def test_room_creator_cannot_set_state_with_other_suffixed_key(self) -> None: expect_code=HTTPStatus.FORBIDDEN, ) + self.assertEqual( + body["errcode"], + Codes.FORBIDDEN, + body, + ) + def test_room_creator_cannot_set_state_with_nonmember_userid_key(self) -> None: body = self.helper.send_state( self.room_id, @@ -183,7 +201,7 @@ def test_room_creator_can_set_state_with_other_suffixed_key(self) -> None: ) def test_user_cannot_set_state_with_other_userid_key(self) -> None: - self.helper.send_state( + body = self.helper.send_state( self.room_id, _STATE_EVENT_TEST_TYPE, {}, @@ -192,8 +210,14 @@ def test_user_cannot_set_state_with_other_userid_key(self) -> None: expect_code=HTTPStatus.FORBIDDEN, ) + self.assertEqual( + body["errcode"], + Codes.FORBIDDEN, + body, + ) + def test_user_cannot_set_state_with_other_suffixed_key(self) -> None: - self.helper.send_state( + body = self.helper.send_state( self.room_id, _STATE_EVENT_TEST_TYPE, {}, @@ -202,8 +226,14 @@ def test_user_cannot_set_state_with_other_suffixed_key(self) -> None: expect_code=HTTPStatus.FORBIDDEN, ) + self.assertEqual( + body["errcode"], + Codes.FORBIDDEN, + body, + ) + def test_user_cannot_set_state_with_unseparated_suffixed_key(self) -> None: - self.helper.send_state( + body = self.helper.send_state( self.room_id, _STATE_EVENT_TEST_TYPE, {}, @@ -212,8 +242,14 @@ def test_user_cannot_set_state_with_unseparated_suffixed_key(self) -> None: expect_code=HTTPStatus.FORBIDDEN, ) + self.assertEqual( + body["errcode"], + Codes.FORBIDDEN, + body, + ) + def test_user_cannot_set_state_with_misplaced_userid_in_key(self) -> None: - self.helper.send_state( + body = self.helper.send_state( self.room_id, _STATE_EVENT_TEST_TYPE, {}, @@ -223,6 +259,12 @@ def test_user_cannot_set_state_with_misplaced_userid_in_key(self) -> None: expect_code=HTTPStatus.FORBIDDEN, ) + self.assertEqual( + body["errcode"], + Codes.FORBIDDEN, + body, + ) + def test_room_creator_can_set_state_with_nonmember_userid_key(self) -> None: self.helper.send_state( self.room_id,