|
15 | 15 | """Tests REST events for /tags paths."""
|
16 | 16 |
|
17 | 17 | from http import HTTPStatus
|
| 18 | +from urllib import parse as urlparse |
18 | 19 |
|
19 | 20 | import synapse.rest.admin
|
20 | 21 | from synapse.rest.client import login, room, tags
|
@@ -93,3 +94,68 @@ def test_put_tag_fails_if_room_does_not_exist(self) -> None:
|
93 | 94 | )
|
94 | 95 | # Check that the request failed with the correct error
|
95 | 96 | self.assertEqual(channel.code, HTTPStatus.FORBIDDEN, channel.result)
|
| 97 | + |
| 98 | + def test_put_tag_fails_if_tag_is_too_long(self) -> None: |
| 99 | + """ |
| 100 | + Test that a user cannot add a tag to a room that is longer than the 255 bytes |
| 101 | + allowed by the matrix specification. |
| 102 | + """ |
| 103 | + user1_id = self.register_user("user1", "pass") |
| 104 | + user1_tok = self.login(user1_id, "pass") |
| 105 | + room_id = self.helper.create_room_as(user1_id, tok=user1_tok) |
| 106 | + # create a string which is larger than 255 bytes |
| 107 | + tag = "X" * 300 |
| 108 | + |
| 109 | + # Make the request |
| 110 | + channel = self.make_request( |
| 111 | + "PUT", |
| 112 | + f"/user/{user1_id}/rooms/{room_id}/tags/{tag}", |
| 113 | + content={"order": 0.5}, |
| 114 | + access_token=user1_tok, |
| 115 | + ) |
| 116 | + # Check that the request failed |
| 117 | + self.assertEqual(channel.code, HTTPStatus.BAD_REQUEST, channel.result) |
| 118 | + |
| 119 | + def test_put_tag_fails_if_tag_is_too_long_with_graphemes(self) -> None: |
| 120 | + """ |
| 121 | + Test that a user cannot add a tag to a room that contains graphemes which are in total |
| 122 | + longer than the 255 bytes allowed by the matrix specification. |
| 123 | + """ |
| 124 | + user1_id = self.register_user("user1", "pass") |
| 125 | + user1_tok = self.login(user1_id, "pass") |
| 126 | + room_id = self.helper.create_room_as(user1_id, tok=user1_tok) |
| 127 | + # create a string which is larger than 255 bytes (275) |
| 128 | + tag = "👩🚒" * 25 |
| 129 | + |
| 130 | + # Make the request |
| 131 | + channel = self.make_request( |
| 132 | + "PUT", |
| 133 | + f"/user/{user1_id}/rooms/{room_id}/tags/" |
| 134 | + + urlparse.quote(tag.encode("utf-8")), |
| 135 | + content={"order": 0.5}, |
| 136 | + access_token=user1_tok, |
| 137 | + ) |
| 138 | + # Check that the request failed |
| 139 | + self.assertEqual(channel.code, HTTPStatus.BAD_REQUEST, channel.result) |
| 140 | + |
| 141 | + def test_put_tag_succeeds_with_graphemes(self) -> None: |
| 142 | + """ |
| 143 | + Test that a user can add a tag to a room that contains graphemes which are in total |
| 144 | + less than the 255 bytes allowed by the matrix specification. |
| 145 | + """ |
| 146 | + user1_id = self.register_user("user1", "pass") |
| 147 | + user1_tok = self.login(user1_id, "pass") |
| 148 | + room_id = self.helper.create_room_as(user1_id, tok=user1_tok) |
| 149 | + # create a string of acceptable length (220 bytes) |
| 150 | + tag = "👩🚒" * 20 |
| 151 | + |
| 152 | + # Make the request |
| 153 | + channel = self.make_request( |
| 154 | + "PUT", |
| 155 | + f"/user/{user1_id}/rooms/{room_id}/tags/" |
| 156 | + + urlparse.quote(tag.encode("utf-8")), |
| 157 | + content={"order": 0.5}, |
| 158 | + access_token=user1_tok, |
| 159 | + ) |
| 160 | + # Check that the request succeeded |
| 161 | + self.assertEqual(channel.code, HTTPStatus.OK, channel.result) |
0 commit comments