Synapse 1.41.0 (2021-08-24)
===========================
This release adds support for Debian 12 (Bookworm), but **removes support for Ubuntu 20.10 (Groovy Gorilla)**, which reached End of Life last month.
Note that when using workers the `/_synapse/admin/v1/users/{userId}/media` must now be handled by media workers. See the [upgrade notes](https://matrix-org.github.io/synapse/latest/upgrade.html) for more information.
Features
--------
- Enable room capabilities ([MSC3244](https://github.com/matrix-org/matrix-doc/pull/3244)) by default and set room version 8 as the preferred room version when creating restricted rooms. ([\#10571](https://github.com/matrix-org/synapse/issues/10571))
Synapse 1.41.0rc1 (2021-08-18)
==============================
Features
--------
- Add `get_userinfo_by_id` method to ModuleApi. ([\#9581](https://github.com/matrix-org/synapse/issues/9581))
- Initial local support for [MSC3266](https://github.com/matrix-org/synapse/pull/10394), Room Summary over the unstable `/rooms/{roomIdOrAlias}/summary` API. ([\#10394](https://github.com/matrix-org/synapse/issues/10394))
- Experimental support for [MSC3288](https://github.com/matrix-org/matrix-doc/pull/3288), sending `room_type` to the identity server for 3pid invites over the `/store-invite` API. ([\#10435](https://github.com/matrix-org/synapse/issues/10435))
- Add support for sending federation requests through a proxy. Contributed by @Bubu and @dklimpel. See the [upgrade notes](https://matrix-org.github.io/synapse/latest/upgrade.html) for more information. ([\#10596](https://github.com/matrix-org/synapse/issues/10596)). ([\#10475](https://github.com/matrix-org/synapse/issues/10475))
- Add support for "marker" events which makes historical events discoverable for servers that already have all of the scrollback history (part of [MSC2716](https://github.com/matrix-org/matrix-doc/pull/2716)). ([\#10498](https://github.com/matrix-org/synapse/issues/10498))
- Add a configuration setting for the time a `/sync` response is cached for. ([\#10513](https://github.com/matrix-org/synapse/issues/10513))
- The default logging handler for new installations is now `PeriodicallyFlushingMemoryHandler`, a buffered logging handler which periodically flushes itself. ([\#10518](https://github.com/matrix-org/synapse/issues/10518))
- Add support for new redaction rules for historical events specified in [MSC2716](https://github.com/matrix-org/matrix-doc/pull/2716). ([\#10538](https://github.com/matrix-org/synapse/issues/10538))
- Add a setting to disable TLS when sending email. ([\#10546](https://github.com/matrix-org/synapse/issues/10546))
- Add pagination to the spaces summary based on updates to [MSC2946](https://github.com/matrix-org/matrix-doc/pull/2946). ([\#10549](https://github.com/matrix-org/synapse/issues/10549), [\#10560](https://github.com/matrix-org/synapse/issues/10560), [\#10569](https://github.com/matrix-org/synapse/issues/10569), [\#10574](https://github.com/matrix-org/synapse/issues/10574), [\#10575](https://github.com/matrix-org/synapse/issues/10575), [\#10579](https://github.com/matrix-org/synapse/issues/10579), [\#10583](https://github.com/matrix-org/synapse/issues/10583))
- Admin API to delete several media for a specific user. Contributed by @dklimpel. ([\#10558](https://github.com/matrix-org/synapse/issues/10558), [\#10628](https://github.com/matrix-org/synapse/issues/10628))
- Add support for routing `/createRoom` to workers. ([\#10564](https://github.com/matrix-org/synapse/issues/10564))
- Update the Synapse Grafana dashboard. ([\#10570](https://github.com/matrix-org/synapse/issues/10570))
- Add an admin API (`GET /_synapse/admin/username_available`) to check if a username is available (regardless of registration settings). ([\#10578](https://github.com/matrix-org/synapse/issues/10578))
- Allow editing a user's `external_ids` via the "Edit User" admin API. Contributed by @dklimpel. ([\#10598](https://github.com/matrix-org/synapse/issues/10598))
- The Synapse manhole no longer needs coroutines to be wrapped in `defer.ensureDeferred`. ([\#10602](https://github.com/matrix-org/synapse/issues/10602))
- Add option to allow modules to run periodic tasks on all instances, rather than just the one configured to run background tasks. ([\#10638](https://github.com/matrix-org/synapse/issues/10638))
Bugfixes
--------
- Add some clarification to the sample config file. Contributed by @Kentokamoto. ([\#10129](https://github.com/matrix-org/synapse/issues/10129))
- Fix a long-standing bug where protocols which are not implemented by any appservices were incorrectly returned via `GET /_matrix/client/r0/thirdparty/protocols`. ([\#10532](https://github.com/matrix-org/synapse/issues/10532))
- Fix exceptions in logs when failing to get remote room list. ([\#10541](https://github.com/matrix-org/synapse/issues/10541))
- Fix longstanding bug which caused the user's presence "status message" to be reset when the user went offline. Contributed by @dklimpel. ([\#10550](https://github.com/matrix-org/synapse/issues/10550))
- Allow public rooms to be previewed in the spaces summary APIs from [MSC2946](https://github.com/matrix-org/matrix-doc/pull/2946). ([\#10580](https://github.com/matrix-org/synapse/issues/10580))
- Fix a bug introduced in v1.37.1 where an error could occur in the asynchronous processing of PDUs when the queue was empty. ([\#10592](https://github.com/matrix-org/synapse/issues/10592))
- Fix errors on /sync when read receipt data is a string. Only affects homeservers with the experimental flag for [MSC2285](https://github.com/matrix-org/matrix-doc/pull/2285) enabled. Contributed by @SimonBrandner. ([\#10606](https://github.com/matrix-org/synapse/issues/10606))
- Additional validation for the spaces summary API to avoid errors like `ValueError: Stop argument for islice() must be None or an integer`. The missing validation has existed since v1.31.0. ([\#10611](https://github.com/matrix-org/synapse/issues/10611))
- Revert behaviour introduced in v1.38.0 that strips `org.matrix.msc2732.device_unused_fallback_key_types` from `/sync` when its value is empty. This field should instead always be present according to [MSC2732](https://github.com/matrix-org/matrix-doc/blob/master/proposals/2732-olm-fallback-keys.md). ([\#10623](https://github.com/matrix-org/synapse/issues/10623))
Improved Documentation
----------------------
- Add documentation for configuring a forward proxy. ([\#10443](https://github.com/matrix-org/synapse/issues/10443))
- Updated the reverse proxy documentation to highlight the homserver configuration that is needed to make Synapse aware that is is intentionally reverse proxied. ([\#10551](https://github.com/matrix-org/synapse/issues/10551))
- Update CONTRIBUTING.md to fix index links and the instructions for SyTest in docker. ([\#10599](https://github.com/matrix-org/synapse/issues/10599))
Deprecations and Removals
-------------------------
- No longer build `.deb` packages for Ubuntu 20.10 Groovy Gorilla, which has now EOLed. ([\#10588](https://github.com/matrix-org/synapse/issues/10588))
- The `template_dir` configuration settings in the `sso`, `account_validity` and `email` sections of the configuration file are now deprecated in favour of the global `templates.custom_template_directory` setting. See the [upgrade notes](https://matrix-org.github.io/synapse/latest/upgrade.html) for more information. ([\#10596](https://github.com/matrix-org/synapse/issues/10596))
Internal Changes
----------------
- Improve event caching mechanism to avoid having multiple copies of an event in memory at a time. ([\#10119](https://github.com/matrix-org/synapse/issues/10119))
- Reduce errors in PostgreSQL logs due to concurrent serialization errors. ([\#10504](https://github.com/matrix-org/synapse/issues/10504))
- Include room ID in ignored EDU log messages. Contributed by @ilmari. ([\#10507](https://github.com/matrix-org/synapse/issues/10507))
- Add pagination to the spaces summary based on updates to [MSC2946](https://github.com/matrix-org/matrix-doc/pull/2946). ([\#10527](https://github.com/matrix-org/synapse/issues/10527), [\#10530](https://github.com/matrix-org/synapse/issues/10530))
- Fix CI to not break when run against branches rather than pull requests. ([\#10529](https://github.com/matrix-org/synapse/issues/10529))
- Mark all events stemming from the [MSC2716](https://github.com/matrix-org/matrix-doc/pull/2716) `/batch_send` endpoint as historical. ([\#10537](https://github.com/matrix-org/synapse/issues/10537))
- Clean up some of the federation event authentication code for clarity. ([\#10539](https://github.com/matrix-org/synapse/issues/10539), [\#10591](https://github.com/matrix-org/synapse/issues/10591))
- Convert `Transaction` and `Edu` objects to attrs. ([\#10542](https://github.com/matrix-org/synapse/issues/10542))
- Update `/batch_send` endpoint to only return `state_events` created by the `state_events_from_before` passed in. ([\#10552](https://github.com/matrix-org/synapse/issues/10552))
- Update contributing.md to warn against rebasing an open PR. ([\#10563](https://github.com/matrix-org/synapse/issues/10563))
- Remove the unused public rooms replication stream. ([\#10565](https://github.com/matrix-org/synapse/issues/10565))
- Clarify error message when failing to join a restricted room. ([\#10572](https://github.com/matrix-org/synapse/issues/10572))
- Remove references to BuildKite in favour of GitHub Actions. ([\#10573](https://github.com/matrix-org/synapse/issues/10573))
- Move `/batch_send` endpoint defined by [MSC2716](https://github.com/matrix-org/matrix-doc/pull/2716) to the `/v2_alpha` directory. ([\#10576](https://github.com/matrix-org/synapse/issues/10576))
- Allow multiple custom directories in `read_templates`. ([\#10587](https://github.com/matrix-org/synapse/issues/10587))
- Re-organize the `synapse.federation.transport.server` module to create smaller files. ([\#10590](https://github.com/matrix-org/synapse/issues/10590))
- Flatten the `synapse.rest.client` package by moving the contents of `v1` and `v2_alpha` into the parent. ([\#10600](https://github.com/matrix-org/synapse/issues/10600))
- Build Debian packages for Debian 12 (Bookworm). ([\#10612](https://github.com/matrix-org/synapse/issues/10612))
- Fix up a couple of links to the database schema documentation. ([\#10620](https://github.com/matrix-org/synapse/issues/10620))
- Fix a broken link to the upgrade notes. ([\#10631](https://github.com/matrix-org/synapse/issues/10631))
335 lines
13 KiB
Python
335 lines
13 KiB
Python
# Copyright 2019 New Vector Ltd
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
from unittest.mock import Mock
|
|
|
|
from synapse.api.constants import EventTypes
|
|
from synapse.rest import admin
|
|
from synapse.rest.client import login, room
|
|
from synapse.visibility import filter_events_for_client
|
|
|
|
from tests import unittest
|
|
|
|
one_hour_ms = 3600000
|
|
one_day_ms = one_hour_ms * 24
|
|
|
|
|
|
class RetentionTestCase(unittest.HomeserverTestCase):
|
|
servlets = [
|
|
admin.register_servlets,
|
|
login.register_servlets,
|
|
room.register_servlets,
|
|
]
|
|
|
|
def make_homeserver(self, reactor, clock):
|
|
config = self.default_config()
|
|
config["default_room_version"] = "1"
|
|
config["retention"] = {
|
|
"enabled": True,
|
|
"default_policy": {
|
|
"min_lifetime": one_day_ms,
|
|
"max_lifetime": one_day_ms * 3,
|
|
},
|
|
"allowed_lifetime_min": one_day_ms,
|
|
"allowed_lifetime_max": one_day_ms * 3,
|
|
}
|
|
|
|
self.hs = self.setup_test_homeserver(config=config)
|
|
|
|
return self.hs
|
|
|
|
def prepare(self, reactor, clock, homeserver):
|
|
self.user_id = self.register_user("user", "password")
|
|
self.token = self.login("user", "password")
|
|
|
|
self.store = self.hs.get_datastore()
|
|
self.serializer = self.hs.get_event_client_serializer()
|
|
self.clock = self.hs.get_clock()
|
|
|
|
def test_retention_event_purged_with_state_event(self):
|
|
"""Tests that expired events are correctly purged when the room's retention policy
|
|
is defined by a state event.
|
|
"""
|
|
room_id = self.helper.create_room_as(self.user_id, tok=self.token)
|
|
|
|
# Set the room's retention period to 2 days.
|
|
lifetime = one_day_ms * 2
|
|
self.helper.send_state(
|
|
room_id=room_id,
|
|
event_type=EventTypes.Retention,
|
|
body={"max_lifetime": lifetime},
|
|
tok=self.token,
|
|
)
|
|
|
|
self._test_retention_event_purged(room_id, one_day_ms * 1.5)
|
|
|
|
def test_retention_event_purged_with_state_event_outside_allowed(self):
|
|
"""Tests that the server configuration can override the policy for a room when
|
|
running the purge jobs.
|
|
"""
|
|
room_id = self.helper.create_room_as(self.user_id, tok=self.token)
|
|
|
|
# Set a max_lifetime higher than the maximum allowed value.
|
|
self.helper.send_state(
|
|
room_id=room_id,
|
|
event_type=EventTypes.Retention,
|
|
body={"max_lifetime": one_day_ms * 4},
|
|
tok=self.token,
|
|
)
|
|
|
|
# Check that the event is purged after waiting for the maximum allowed duration
|
|
# instead of the one specified in the room's policy.
|
|
self._test_retention_event_purged(room_id, one_day_ms * 1.5)
|
|
|
|
# Set a max_lifetime lower than the minimum allowed value.
|
|
self.helper.send_state(
|
|
room_id=room_id,
|
|
event_type=EventTypes.Retention,
|
|
body={"max_lifetime": one_hour_ms},
|
|
tok=self.token,
|
|
)
|
|
|
|
# Check that the event is purged after waiting for the minimum allowed duration
|
|
# instead of the one specified in the room's policy.
|
|
self._test_retention_event_purged(room_id, one_day_ms * 0.5)
|
|
|
|
def test_retention_event_purged_without_state_event(self):
|
|
"""Tests that expired events are correctly purged when the room's retention policy
|
|
is defined by the server's configuration's default retention policy.
|
|
"""
|
|
room_id = self.helper.create_room_as(self.user_id, tok=self.token)
|
|
|
|
self._test_retention_event_purged(room_id, one_day_ms * 2)
|
|
|
|
def test_visibility(self):
|
|
"""Tests that synapse.visibility.filter_events_for_client correctly filters out
|
|
outdated events
|
|
"""
|
|
store = self.hs.get_datastore()
|
|
storage = self.hs.get_storage()
|
|
room_id = self.helper.create_room_as(self.user_id, tok=self.token)
|
|
events = []
|
|
|
|
# Send a first event, which should be filtered out at the end of the test.
|
|
resp = self.helper.send(room_id=room_id, body="1", tok=self.token)
|
|
|
|
# Get the event from the store so that we end up with a FrozenEvent that we can
|
|
# give to filter_events_for_client. We need to do this now because the event won't
|
|
# be in the database anymore after it has expired.
|
|
events.append(self.get_success(store.get_event(resp.get("event_id"))))
|
|
|
|
# Advance the time by 2 days. We're using the default retention policy, therefore
|
|
# after this the first event will still be valid.
|
|
self.reactor.advance(one_day_ms * 2 / 1000)
|
|
|
|
# Send another event, which shouldn't get filtered out.
|
|
resp = self.helper.send(room_id=room_id, body="2", tok=self.token)
|
|
|
|
valid_event_id = resp.get("event_id")
|
|
|
|
events.append(self.get_success(store.get_event(valid_event_id)))
|
|
|
|
# Advance the time by another 2 days. After this, the first event should be
|
|
# outdated but not the second one.
|
|
self.reactor.advance(one_day_ms * 2 / 1000)
|
|
|
|
# Run filter_events_for_client with our list of FrozenEvents.
|
|
filtered_events = self.get_success(
|
|
filter_events_for_client(storage, self.user_id, events)
|
|
)
|
|
|
|
# We should only get one event back.
|
|
self.assertEqual(len(filtered_events), 1, filtered_events)
|
|
# That event should be the second, not outdated event.
|
|
self.assertEqual(filtered_events[0].event_id, valid_event_id, filtered_events)
|
|
|
|
def _test_retention_event_purged(self, room_id: str, increment: float):
|
|
"""Run the following test scenario to test the message retention policy support:
|
|
|
|
1. Send event 1
|
|
2. Increment time by `increment`
|
|
3. Send event 2
|
|
4. Increment time by `increment`
|
|
5. Check that event 1 has been purged
|
|
6. Check that event 2 has not been purged
|
|
7. Check that state events that were sent before event 1 aren't purged.
|
|
The main reason for sending a second event is because currently Synapse won't
|
|
purge the latest message in a room because it would otherwise result in a lack of
|
|
forward extremities for this room. It's also a good thing to ensure the purge jobs
|
|
aren't too greedy and purge messages they shouldn't.
|
|
|
|
Args:
|
|
room_id: The ID of the room to test retention in.
|
|
increment: The number of milliseconds to advance the clock each time. Must be
|
|
defined so that events in the room aren't purged if they are `increment`
|
|
old but are purged if they are `increment * 2` old.
|
|
"""
|
|
# Get the create event to, later, check that we can still access it.
|
|
message_handler = self.hs.get_message_handler()
|
|
create_event = self.get_success(
|
|
message_handler.get_room_data(
|
|
self.user_id, room_id, EventTypes.Create, state_key=""
|
|
)
|
|
)
|
|
|
|
# Send a first event to the room. This is the event we'll want to be purged at the
|
|
# end of the test.
|
|
resp = self.helper.send(room_id=room_id, body="1", tok=self.token)
|
|
|
|
expired_event_id = resp.get("event_id")
|
|
|
|
# Check that we can retrieve the event.
|
|
expired_event = self.get_event(expired_event_id)
|
|
self.assertEqual(
|
|
expired_event.get("content", {}).get("body"), "1", expired_event
|
|
)
|
|
|
|
# Advance the time.
|
|
self.reactor.advance(increment / 1000)
|
|
|
|
# Send another event. We need this because the purge job won't purge the most
|
|
# recent event in the room.
|
|
resp = self.helper.send(room_id=room_id, body="2", tok=self.token)
|
|
|
|
valid_event_id = resp.get("event_id")
|
|
|
|
# Advance the time again. Now our first event should have expired but our second
|
|
# one should still be kept.
|
|
self.reactor.advance(increment / 1000)
|
|
|
|
# Check that the first event has been purged from the database, i.e. that we
|
|
# can't retrieve it anymore, because it has expired.
|
|
self.get_event(expired_event_id, expect_none=True)
|
|
|
|
# Check that the event that hasn't expired can still be retrieved.
|
|
valid_event = self.get_event(valid_event_id)
|
|
self.assertEqual(valid_event.get("content", {}).get("body"), "2", valid_event)
|
|
|
|
# Check that we can still access state events that were sent before the event that
|
|
# has been purged.
|
|
self.get_event(room_id, create_event.event_id)
|
|
|
|
def get_event(self, event_id, expect_none=False):
|
|
event = self.get_success(self.store.get_event(event_id, allow_none=True))
|
|
|
|
if expect_none:
|
|
self.assertIsNone(event)
|
|
return {}
|
|
|
|
self.assertIsNotNone(event)
|
|
|
|
time_now = self.clock.time_msec()
|
|
serialized = self.get_success(self.serializer.serialize_event(event, time_now))
|
|
|
|
return serialized
|
|
|
|
|
|
class RetentionNoDefaultPolicyTestCase(unittest.HomeserverTestCase):
|
|
servlets = [
|
|
admin.register_servlets,
|
|
login.register_servlets,
|
|
room.register_servlets,
|
|
]
|
|
|
|
def make_homeserver(self, reactor, clock):
|
|
config = self.default_config()
|
|
config["default_room_version"] = "1"
|
|
config["retention"] = {
|
|
"enabled": True,
|
|
}
|
|
|
|
mock_federation_client = Mock(spec=["backfill"])
|
|
|
|
self.hs = self.setup_test_homeserver(
|
|
config=config,
|
|
federation_client=mock_federation_client,
|
|
)
|
|
return self.hs
|
|
|
|
def prepare(self, reactor, clock, homeserver):
|
|
self.user_id = self.register_user("user", "password")
|
|
self.token = self.login("user", "password")
|
|
|
|
def test_no_default_policy(self):
|
|
"""Tests that an event doesn't get expired if there is neither a default retention
|
|
policy nor a policy specific to the room.
|
|
"""
|
|
room_id = self.helper.create_room_as(self.user_id, tok=self.token)
|
|
|
|
self._test_retention(room_id)
|
|
|
|
def test_state_policy(self):
|
|
"""Tests that an event gets correctly expired if there is no default retention
|
|
policy but there's a policy specific to the room.
|
|
"""
|
|
room_id = self.helper.create_room_as(self.user_id, tok=self.token)
|
|
|
|
# Set the maximum lifetime to 35 days so that the first event gets expired but not
|
|
# the second one.
|
|
self.helper.send_state(
|
|
room_id=room_id,
|
|
event_type=EventTypes.Retention,
|
|
body={"max_lifetime": one_day_ms * 35},
|
|
tok=self.token,
|
|
)
|
|
|
|
self._test_retention(room_id, expected_code_for_first_event=404)
|
|
|
|
def _test_retention(self, room_id, expected_code_for_first_event=200):
|
|
# Send a first event to the room. This is the event we'll want to be purged at the
|
|
# end of the test.
|
|
resp = self.helper.send(room_id=room_id, body="1", tok=self.token)
|
|
|
|
first_event_id = resp.get("event_id")
|
|
|
|
# Check that we can retrieve the event.
|
|
expired_event = self.get_event(room_id, first_event_id)
|
|
self.assertEqual(
|
|
expired_event.get("content", {}).get("body"), "1", expired_event
|
|
)
|
|
|
|
# Advance the time by a month.
|
|
self.reactor.advance(one_day_ms * 30 / 1000)
|
|
|
|
# Send another event. We need this because the purge job won't purge the most
|
|
# recent event in the room.
|
|
resp = self.helper.send(room_id=room_id, body="2", tok=self.token)
|
|
|
|
second_event_id = resp.get("event_id")
|
|
|
|
# Advance the time by another month.
|
|
self.reactor.advance(one_day_ms * 30 / 1000)
|
|
|
|
# Check if the event has been purged from the database.
|
|
first_event = self.get_event(
|
|
room_id, first_event_id, expected_code=expected_code_for_first_event
|
|
)
|
|
|
|
if expected_code_for_first_event == 200:
|
|
self.assertEqual(
|
|
first_event.get("content", {}).get("body"), "1", first_event
|
|
)
|
|
|
|
# Check that the event that hasn't been purged can still be retrieved.
|
|
second_event = self.get_event(room_id, second_event_id)
|
|
self.assertEqual(second_event.get("content", {}).get("body"), "2", second_event)
|
|
|
|
def get_event(self, room_id, event_id, expected_code=200):
|
|
url = "/_matrix/client/r0/rooms/%s/event/%s" % (room_id, event_id)
|
|
|
|
channel = self.make_request("GET", url, access_token=self.token)
|
|
|
|
self.assertEqual(channel.code, expected_code, channel.result)
|
|
|
|
return channel.json_body
|