mirror of
https://mau.dev/maunium/synapse.git
synced 2024-10-01 01:36:05 -04:00
Add support for room version 10 (#13220)
This commit is contained in:
parent
2341032cf2
commit
ad5761b65c
1
changelog.d/13220.feature
Normal file
1
changelog.d/13220.feature
Normal file
@ -0,0 +1 @@
|
|||||||
|
Add support for room version 10.
|
@ -84,6 +84,8 @@ class RoomVersion:
|
|||||||
# MSC3787: Adds support for a `knock_restricted` join rule, mixing concepts of
|
# MSC3787: Adds support for a `knock_restricted` join rule, mixing concepts of
|
||||||
# knocks and restricted join rules into the same join condition.
|
# knocks and restricted join rules into the same join condition.
|
||||||
msc3787_knock_restricted_join_rule: bool
|
msc3787_knock_restricted_join_rule: bool
|
||||||
|
# MSC3667: Enforce integer power levels
|
||||||
|
msc3667_int_only_power_levels: bool
|
||||||
|
|
||||||
|
|
||||||
class RoomVersions:
|
class RoomVersions:
|
||||||
@ -103,6 +105,7 @@ class RoomVersions:
|
|||||||
msc2716_historical=False,
|
msc2716_historical=False,
|
||||||
msc2716_redactions=False,
|
msc2716_redactions=False,
|
||||||
msc3787_knock_restricted_join_rule=False,
|
msc3787_knock_restricted_join_rule=False,
|
||||||
|
msc3667_int_only_power_levels=False,
|
||||||
)
|
)
|
||||||
V2 = RoomVersion(
|
V2 = RoomVersion(
|
||||||
"2",
|
"2",
|
||||||
@ -120,6 +123,7 @@ class RoomVersions:
|
|||||||
msc2716_historical=False,
|
msc2716_historical=False,
|
||||||
msc2716_redactions=False,
|
msc2716_redactions=False,
|
||||||
msc3787_knock_restricted_join_rule=False,
|
msc3787_knock_restricted_join_rule=False,
|
||||||
|
msc3667_int_only_power_levels=False,
|
||||||
)
|
)
|
||||||
V3 = RoomVersion(
|
V3 = RoomVersion(
|
||||||
"3",
|
"3",
|
||||||
@ -137,6 +141,7 @@ class RoomVersions:
|
|||||||
msc2716_historical=False,
|
msc2716_historical=False,
|
||||||
msc2716_redactions=False,
|
msc2716_redactions=False,
|
||||||
msc3787_knock_restricted_join_rule=False,
|
msc3787_knock_restricted_join_rule=False,
|
||||||
|
msc3667_int_only_power_levels=False,
|
||||||
)
|
)
|
||||||
V4 = RoomVersion(
|
V4 = RoomVersion(
|
||||||
"4",
|
"4",
|
||||||
@ -154,6 +159,7 @@ class RoomVersions:
|
|||||||
msc2716_historical=False,
|
msc2716_historical=False,
|
||||||
msc2716_redactions=False,
|
msc2716_redactions=False,
|
||||||
msc3787_knock_restricted_join_rule=False,
|
msc3787_knock_restricted_join_rule=False,
|
||||||
|
msc3667_int_only_power_levels=False,
|
||||||
)
|
)
|
||||||
V5 = RoomVersion(
|
V5 = RoomVersion(
|
||||||
"5",
|
"5",
|
||||||
@ -171,6 +177,7 @@ class RoomVersions:
|
|||||||
msc2716_historical=False,
|
msc2716_historical=False,
|
||||||
msc2716_redactions=False,
|
msc2716_redactions=False,
|
||||||
msc3787_knock_restricted_join_rule=False,
|
msc3787_knock_restricted_join_rule=False,
|
||||||
|
msc3667_int_only_power_levels=False,
|
||||||
)
|
)
|
||||||
V6 = RoomVersion(
|
V6 = RoomVersion(
|
||||||
"6",
|
"6",
|
||||||
@ -188,6 +195,7 @@ class RoomVersions:
|
|||||||
msc2716_historical=False,
|
msc2716_historical=False,
|
||||||
msc2716_redactions=False,
|
msc2716_redactions=False,
|
||||||
msc3787_knock_restricted_join_rule=False,
|
msc3787_knock_restricted_join_rule=False,
|
||||||
|
msc3667_int_only_power_levels=False,
|
||||||
)
|
)
|
||||||
MSC2176 = RoomVersion(
|
MSC2176 = RoomVersion(
|
||||||
"org.matrix.msc2176",
|
"org.matrix.msc2176",
|
||||||
@ -205,6 +213,7 @@ class RoomVersions:
|
|||||||
msc2716_historical=False,
|
msc2716_historical=False,
|
||||||
msc2716_redactions=False,
|
msc2716_redactions=False,
|
||||||
msc3787_knock_restricted_join_rule=False,
|
msc3787_knock_restricted_join_rule=False,
|
||||||
|
msc3667_int_only_power_levels=False,
|
||||||
)
|
)
|
||||||
V7 = RoomVersion(
|
V7 = RoomVersion(
|
||||||
"7",
|
"7",
|
||||||
@ -222,6 +231,7 @@ class RoomVersions:
|
|||||||
msc2716_historical=False,
|
msc2716_historical=False,
|
||||||
msc2716_redactions=False,
|
msc2716_redactions=False,
|
||||||
msc3787_knock_restricted_join_rule=False,
|
msc3787_knock_restricted_join_rule=False,
|
||||||
|
msc3667_int_only_power_levels=False,
|
||||||
)
|
)
|
||||||
V8 = RoomVersion(
|
V8 = RoomVersion(
|
||||||
"8",
|
"8",
|
||||||
@ -239,6 +249,7 @@ class RoomVersions:
|
|||||||
msc2716_historical=False,
|
msc2716_historical=False,
|
||||||
msc2716_redactions=False,
|
msc2716_redactions=False,
|
||||||
msc3787_knock_restricted_join_rule=False,
|
msc3787_knock_restricted_join_rule=False,
|
||||||
|
msc3667_int_only_power_levels=False,
|
||||||
)
|
)
|
||||||
V9 = RoomVersion(
|
V9 = RoomVersion(
|
||||||
"9",
|
"9",
|
||||||
@ -256,6 +267,7 @@ class RoomVersions:
|
|||||||
msc2716_historical=False,
|
msc2716_historical=False,
|
||||||
msc2716_redactions=False,
|
msc2716_redactions=False,
|
||||||
msc3787_knock_restricted_join_rule=False,
|
msc3787_knock_restricted_join_rule=False,
|
||||||
|
msc3667_int_only_power_levels=False,
|
||||||
)
|
)
|
||||||
MSC2716v3 = RoomVersion(
|
MSC2716v3 = RoomVersion(
|
||||||
"org.matrix.msc2716v3",
|
"org.matrix.msc2716v3",
|
||||||
@ -273,6 +285,7 @@ class RoomVersions:
|
|||||||
msc2716_historical=True,
|
msc2716_historical=True,
|
||||||
msc2716_redactions=True,
|
msc2716_redactions=True,
|
||||||
msc3787_knock_restricted_join_rule=False,
|
msc3787_knock_restricted_join_rule=False,
|
||||||
|
msc3667_int_only_power_levels=False,
|
||||||
)
|
)
|
||||||
MSC3787 = RoomVersion(
|
MSC3787 = RoomVersion(
|
||||||
"org.matrix.msc3787",
|
"org.matrix.msc3787",
|
||||||
@ -290,6 +303,25 @@ class RoomVersions:
|
|||||||
msc2716_historical=False,
|
msc2716_historical=False,
|
||||||
msc2716_redactions=False,
|
msc2716_redactions=False,
|
||||||
msc3787_knock_restricted_join_rule=True,
|
msc3787_knock_restricted_join_rule=True,
|
||||||
|
msc3667_int_only_power_levels=False,
|
||||||
|
)
|
||||||
|
V10 = RoomVersion(
|
||||||
|
"10",
|
||||||
|
RoomDisposition.STABLE,
|
||||||
|
EventFormatVersions.V3,
|
||||||
|
StateResolutionVersions.V2,
|
||||||
|
enforce_key_validity=True,
|
||||||
|
special_case_aliases_auth=False,
|
||||||
|
strict_canonicaljson=True,
|
||||||
|
limit_notifications_power_levels=True,
|
||||||
|
msc2176_redaction_rules=False,
|
||||||
|
msc3083_join_rules=True,
|
||||||
|
msc3375_redaction_rules=True,
|
||||||
|
msc2403_knocking=True,
|
||||||
|
msc2716_historical=False,
|
||||||
|
msc2716_redactions=False,
|
||||||
|
msc3787_knock_restricted_join_rule=True,
|
||||||
|
msc3667_int_only_power_levels=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -308,6 +340,7 @@ KNOWN_ROOM_VERSIONS: Dict[str, RoomVersion] = {
|
|||||||
RoomVersions.V9,
|
RoomVersions.V9,
|
||||||
RoomVersions.MSC2716v3,
|
RoomVersions.MSC2716v3,
|
||||||
RoomVersions.MSC3787,
|
RoomVersions.MSC3787,
|
||||||
|
RoomVersions.V10,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -740,6 +740,32 @@ def _check_power_levels(
|
|||||||
except Exception:
|
except Exception:
|
||||||
raise SynapseError(400, "Not a valid power level: %s" % (v,))
|
raise SynapseError(400, "Not a valid power level: %s" % (v,))
|
||||||
|
|
||||||
|
# Reject events with stringy power levels if required by room version
|
||||||
|
if (
|
||||||
|
event.type == EventTypes.PowerLevels
|
||||||
|
and room_version_obj.msc3667_int_only_power_levels
|
||||||
|
):
|
||||||
|
for k, v in event.content.items():
|
||||||
|
if k in {
|
||||||
|
"users_default",
|
||||||
|
"events_default",
|
||||||
|
"state_default",
|
||||||
|
"ban",
|
||||||
|
"redact",
|
||||||
|
"kick",
|
||||||
|
"invite",
|
||||||
|
}:
|
||||||
|
if not isinstance(v, int):
|
||||||
|
raise SynapseError(400, f"{v!r} must be an integer.")
|
||||||
|
if k in {"events", "notifications", "users"}:
|
||||||
|
if not isinstance(v, dict) or not all(
|
||||||
|
isinstance(v, int) for v in v.values()
|
||||||
|
):
|
||||||
|
raise SynapseError(
|
||||||
|
400,
|
||||||
|
f"{v!r} must be a dict wherein all the values are integers.",
|
||||||
|
)
|
||||||
|
|
||||||
key = (event.type, event.state_key)
|
key = (event.type, event.state_key)
|
||||||
current_state = auth_events.get(key)
|
current_state = auth_events.get(key)
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ from parameterized import parameterized
|
|||||||
|
|
||||||
from synapse import event_auth
|
from synapse import event_auth
|
||||||
from synapse.api.constants import EventContentFields
|
from synapse.api.constants import EventContentFields
|
||||||
from synapse.api.errors import AuthError
|
from synapse.api.errors import AuthError, SynapseError
|
||||||
from synapse.api.room_versions import EventFormatVersions, RoomVersion, RoomVersions
|
from synapse.api.room_versions import EventFormatVersions, RoomVersion, RoomVersions
|
||||||
from synapse.events import EventBase, make_event_from_dict
|
from synapse.events import EventBase, make_event_from_dict
|
||||||
from synapse.storage.databases.main.events_worker import EventRedactBehaviour
|
from synapse.storage.databases.main.events_worker import EventRedactBehaviour
|
||||||
@ -689,6 +689,45 @@ class EventAuthTestCase(unittest.TestCase):
|
|||||||
auth_events.values(),
|
auth_events.values(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_room_v10_rejects_string_power_levels(self) -> None:
|
||||||
|
pl_event_content = {"users_default": "42"}
|
||||||
|
pl_event = 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,
|
||||||
|
)
|
||||||
|
|
||||||
|
pl_event2_content = {"events": {"m.room.name": "42", "m.room.power_levels": 42}}
|
||||||
|
pl_event2 = 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_event2_content,
|
||||||
|
"signatures": {"test.com": {"ed25519:0": "some9signature"}},
|
||||||
|
},
|
||||||
|
room_version=RoomVersions.V10,
|
||||||
|
)
|
||||||
|
|
||||||
|
with self.assertRaises(SynapseError):
|
||||||
|
event_auth._check_power_levels(
|
||||||
|
pl_event.room_version, pl_event, {("fake_type", "fake_key"): pl_event2}
|
||||||
|
)
|
||||||
|
|
||||||
|
with self.assertRaises(SynapseError):
|
||||||
|
event_auth._check_power_levels(
|
||||||
|
pl_event.room_version, pl_event2, {("fake_type", "fake_key"): pl_event}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# helpers for making events
|
# helpers for making events
|
||||||
TEST_DOMAIN = "example.com"
|
TEST_DOMAIN = "example.com"
|
||||||
|
Loading…
Reference in New Issue
Block a user