Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Also test that bad values are rejected by event auth
Browse files Browse the repository at this point in the history
  • Loading branch information
David Robertson committed Jan 30, 2023
1 parent 289983c commit 698c288
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion tests/test_event_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

import unittest
from typing import Collection, Dict, Iterable, List, Optional
from typing import Any, Collection, Dict, Iterable, List, Optional

from parameterized import parameterized

Expand Down Expand Up @@ -728,6 +728,31 @@ def test_room_v10_rejects_string_power_levels(self) -> None:
pl_event.room_version, pl_event2, {("fake_type", "fake_key"): pl_event}
)

def test_room_v10_rejects_other_non_integer_power_levels(self) -> None:
def create_event(pl_event_content: Dict[str, Any]) -> EventBase:
return make_event_from_dict(
{
"room_id": TEST_ROOM_ID,
**_maybe_get_event_id_dict_for_room_version(RoomVersions.V10),
"type": "m.room.power_levels",
"sender": "@test:test.com",
"state_key": "",
"content": pl_event_content,
"signatures": {"test.com": {"ed25519:0": "some9signature"}},
},
room_version=RoomVersions.V10,
)

contents: Iterable[Dict[str, Any]] = [
{"notifications": {"room": None}},
{"users": {"@alice:wonderland": []}},
{"users_default": {}},
]
for content in contents:
event = create_event(content)
with self.assertRaises(SynapseError):
event_auth._check_power_levels(event.room_version, event, {})


# helpers for making events
TEST_DOMAIN = "example.com"
Expand Down

0 comments on commit 698c288

Please sign in to comment.