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

Commit 44741aa

Browse files
author
Sean Quah
committed
Merge tag 'v1.69.0rc2' into develop
Synapse 1.69.0rc2 (2022-10-06) ============================== Please note that legacy Prometheus metric names are now deprecated and will be removed in Synapse 1.73.0. Server administrators should update their dashboards and alerting rules to avoid using the deprecated metric names. See the [upgrade notes](https://matrix-org.github.io/synapse/v1.69/upgrade.html#upgrading-to-v1690) for more details. Deprecations and Removals ------------------------- - Deprecate the `generate_short_term_login_token` method in favor of an async `create_login_token` method in the Module API. ([\#13842](#13842)) Internal Changes ---------------- - Ensure Synapse v1.69 works with upcoming database changes in v1.70. ([\#14045](#14045)) - Fix a bug introduced in Synapse v1.68.0 where messages could not be sent in rooms with non-integer `notifications` power level. ([\#14073](#14073)) - Temporarily pin build-system requirements to workaround an incompatibility with poetry-core 1.3.0. This will be reverted before the v1.69.0 release proper, see [\#14079](#14079). ([\#14080](#14080))
2 parents b753f63 + a98ac3c commit 44741aa

File tree

8 files changed

+186
-5
lines changed

8 files changed

+186
-5
lines changed

CHANGES.md

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
1-
Synapse 1.69.0rc1 (2022-10-04)
1+
Synapse 1.69.0rc2 (2022-10-06)
22
==============================
33

4-
54
Please note that legacy Prometheus metric names are now deprecated and will be removed in Synapse 1.73.0.
65
Server administrators should update their dashboards and alerting rules to avoid using the deprecated metric names.
76
See the [upgrade notes](https://matrix-org.github.io/synapse/v1.69/upgrade.html#upgrading-to-v1690) for more details.
87

98

9+
Deprecations and Removals
10+
-------------------------
11+
12+
- Deprecate the `generate_short_term_login_token` method in favor of an async `create_login_token` method in the Module API. ([\#13842](https://github.com/matrix-org/synapse/issues/13842))
13+
14+
15+
Internal Changes
16+
----------------
17+
18+
- Ensure Synapse v1.69 works with upcoming database changes in v1.70. ([\#14045](https://github.com/matrix-org/synapse/issues/14045))
19+
- Fix a bug introduced in Synapse v1.68.0 where messages could not be sent in rooms with non-integer `notifications` power level. ([\#14073](https://github.com/matrix-org/synapse/issues/14073))
20+
- Temporarily pin build-system requirements to workaround an incompatibility with poetry-core 1.3.0. This will be reverted before the v1.69.0 release proper, see [\#14079](https://github.com/matrix-org/synapse/issues/14079). ([\#14080](https://github.com/matrix-org/synapse/issues/14080))
21+
22+
23+
Synapse 1.69.0rc1 (2022-10-04)
24+
==============================
25+
1026
Features
1127
--------
1228

debian/changelog

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
matrix-synapse-py3 (1.69.0~rc2) stable; urgency=medium
2+
3+
* New Synapse release 1.69.0rc2.
4+
5+
-- Synapse Packaging team <[email protected]> Thu, 06 Oct 2022 14:45:00 +0100
6+
17
matrix-synapse-py3 (1.69.0~rc1) stable; urgency=medium
28

39
* The man page for the hash_password script has been updated to reflect

docs/upgrade.md

+33
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,39 @@ you may specify `enable_legacy_metrics: false` in your homeserver configuration.
128128
A list of affected metrics is available on the [Metrics How-to page](https://matrix-org.github.io/synapse/v1.69/metrics-howto.html?highlight=metrics%20deprecated#renaming-of-metrics--deprecation-of-old-names-in-12).
129129

130130

131+
## Deprecation of the `generate_short_term_login_token` module API method
132+
133+
The following method of the module API has been deprecated, and is scheduled to
134+
be remove in v1.71.0:
135+
136+
```python
137+
def generate_short_term_login_token(
138+
self,
139+
user_id: str,
140+
duration_in_ms: int = (2 * 60 * 1000),
141+
auth_provider_id: str = "",
142+
auth_provider_session_id: Optional[str] = None,
143+
) -> str:
144+
...
145+
```
146+
147+
It has been replaced by an asynchronous equivalent:
148+
149+
```python
150+
async def create_login_token(
151+
self,
152+
user_id: str,
153+
duration_in_ms: int = (2 * 60 * 1000),
154+
auth_provider_id: Optional[str] = None,
155+
auth_provider_session_id: Optional[str] = None,
156+
) -> str:
157+
...
158+
```
159+
160+
Synapse will log a warning when a module uses the deprecated method, to help
161+
administrators find modules using it.
162+
163+
131164
# Upgrading to v1.68.0
132165

133166
Two changes announced in the upgrade notes for v1.67.0 have now landed in v1.68.0.

mypy.ini

+3
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ disallow_untyped_defs = False
106106
[mypy-tests.handlers.test_user_directory]
107107
disallow_untyped_defs = True
108108

109+
[mypy-tests.push.test_bulk_push_rule_evaluator]
110+
disallow_untyped_defs = True
111+
109112
[mypy-tests.test_server]
110113
disallow_untyped_defs = True
111114

pyproject.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ manifest-path = "rust/Cargo.toml"
5757

5858
[tool.poetry]
5959
name = "matrix-synapse"
60-
version = "1.69.0rc1"
60+
version = "1.69.0rc2"
6161
description = "Homeserver for the Matrix decentralised comms protocol"
6262
authors = ["Matrix.org Team and Contributors <[email protected]>"]
6363
license = "Apache-2.0"
@@ -307,7 +307,7 @@ twine = "*"
307307
towncrier = ">=18.6.0rc1"
308308

309309
[build-system]
310-
requires = ["poetry-core>=1.0.0", "setuptools_rust>=1.3"]
310+
requires = ["poetry-core==1.2.0", "setuptools_rust==1.5.2"]
311311
build-backend = "poetry.core.masonry.api"
312312

313313

synapse/module_api/__init__.py

+42
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,40 @@ def record_user_external_id(
748748
)
749749
)
750750

751+
async def create_login_token(
752+
self,
753+
user_id: str,
754+
duration_in_ms: int = (2 * 60 * 1000),
755+
auth_provider_id: Optional[str] = None,
756+
auth_provider_session_id: Optional[str] = None,
757+
) -> str:
758+
"""Create a login token suitable for m.login.token authentication
759+
760+
Added in Synapse v1.69.0.
761+
762+
Args:
763+
user_id: gives the ID of the user that the token is for
764+
765+
duration_in_ms: the time that the token will be valid for
766+
767+
auth_provider_id: the ID of the SSO IdP that the user used to authenticate
768+
to get this token, if any. This is encoded in the token so that
769+
/login can report stats on number of successful logins by IdP.
770+
771+
auth_provider_session_id: The session ID got during login from the SSO IdP,
772+
if any.
773+
"""
774+
# The deprecated `generate_short_term_login_token` method defaulted to an empty
775+
# string for the `auth_provider_id` because of how the underlying macaroon was
776+
# generated. This will change to a proper NULL-able field when the tokens get
777+
# moved to the database.
778+
return self._hs.get_macaroon_generator().generate_short_term_login_token(
779+
user_id,
780+
auth_provider_id or "",
781+
auth_provider_session_id,
782+
duration_in_ms,
783+
)
784+
751785
def generate_short_term_login_token(
752786
self,
753787
user_id: str,
@@ -759,6 +793,9 @@ def generate_short_term_login_token(
759793
760794
Added in Synapse v1.9.0.
761795
796+
This was deprecated in Synapse v1.69.0 in favor of create_login_token, and will
797+
be removed in Synapse 1.71.0.
798+
762799
Args:
763800
user_id: gives the ID of the user that the token is for
764801
@@ -768,6 +805,11 @@ def generate_short_term_login_token(
768805
to get this token, if any. This is encoded in the token so that
769806
/login can report stats on number of successful logins by IdP.
770807
"""
808+
logger.warn(
809+
"A module configured on this server uses ModuleApi.generate_short_term_login_token(), "
810+
"which is deprecated in favor of ModuleApi.create_login_token(), and will be removed in "
811+
"Synapse 1.71.0",
812+
)
771813
return self._hs.get_macaroon_generator().generate_short_term_login_token(
772814
user_id,
773815
auth_provider_id,

synapse/push/bulk_push_rule_evaluator.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,18 @@ async def action_for_event_by_user(
294294
# the parent is part of a thread.
295295
thread_id = await self.store.get_thread_id(relation.parent_id) or "main"
296296

297+
# It's possible that old room versions have non-integer power levels (floats or
298+
# strings). Workaround this by explicitly converting to int.
299+
notification_levels = power_levels.get("notifications", {})
300+
if not event.room_version.msc3667_int_only_power_levels:
301+
for user_id, level in notification_levels.items():
302+
notification_levels[user_id] = int(level)
303+
297304
evaluator = PushRuleEvaluator(
298305
_flatten_dict(event),
299306
room_member_count,
300307
sender_power_level,
301-
power_levels.get("notifications", {}),
308+
notification_levels,
302309
relations,
303310
self._relations_match_enabled,
304311
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
from unittest.mock import patch
2+
3+
from synapse.api.room_versions import RoomVersions
4+
from synapse.push.bulk_push_rule_evaluator import BulkPushRuleEvaluator
5+
from synapse.rest import admin
6+
from synapse.rest.client import login, register, room
7+
from synapse.types import create_requester
8+
9+
from tests import unittest
10+
11+
12+
class TestBulkPushRuleEvaluator(unittest.HomeserverTestCase):
13+
14+
servlets = [
15+
admin.register_servlets_for_client_rest_resource,
16+
room.register_servlets,
17+
login.register_servlets,
18+
register.register_servlets,
19+
]
20+
21+
def test_action_for_event_by_user_handles_noninteger_power_levels(self) -> None:
22+
"""We should convert floats and strings to integers before passing to Rust.
23+
24+
Reproduces #14060.
25+
26+
A lack of validation: the gift that keeps on giving.
27+
"""
28+
# Create a new user and room.
29+
alice = self.register_user("alice", "pass")
30+
token = self.login(alice, "pass")
31+
32+
room_id = self.helper.create_room_as(
33+
alice, room_version=RoomVersions.V9.identifier, tok=token
34+
)
35+
36+
# Alter the power levels in that room to include stringy and floaty levels.
37+
# We need to suppress the validation logic or else it will reject these dodgy
38+
# values. (Presumably this validation was not always present.)
39+
event_creation_handler = self.hs.get_event_creation_handler()
40+
requester = create_requester(alice)
41+
with patch("synapse.events.validator.validate_canonicaljson"), patch(
42+
"synapse.events.validator.jsonschema.validate"
43+
):
44+
self.helper.send_state(
45+
room_id,
46+
"m.room.power_levels",
47+
{
48+
"users": {alice: "100"}, # stringy
49+
"notifications": {"room": 100.0}, # float
50+
},
51+
token,
52+
state_key="",
53+
)
54+
55+
# Create a new message event, and try to evaluate it under the dodgy
56+
# power level event.
57+
event, context = self.get_success(
58+
event_creation_handler.create_event(
59+
requester,
60+
{
61+
"type": "m.room.message",
62+
"room_id": room_id,
63+
"content": {
64+
"msgtype": "m.text",
65+
"body": "helo",
66+
},
67+
"sender": alice,
68+
},
69+
)
70+
)
71+
72+
bulk_evaluator = BulkPushRuleEvaluator(self.hs)
73+
# should not raise
74+
self.get_success(bulk_evaluator.action_for_event_by_user(event, context))

0 commit comments

Comments
 (0)