diff --git a/CHANGES.md b/CHANGES.md index f21d14d9e0..e1cfa7aeba 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,74 @@ +Synapse 1.37.0rc1 (2021-06-24) +============================== + +This release deprecates the current spam checker interface. See the [upgrade notes](https://matrix-org.github.io/synapse/develop/upgrade#deprecation-of-the-current-spam-checker-interface) for more information on how to update to the new generic module interface. + +This release also removes support for fetching and renewing TLS certificates using the ACME v1 protocol, which has been fully decommissioned by Let's Encrypt on June 1st 2021. Admins previously using this feature should use a [reverse proxy](https://matrix-org.github.io/synapse/develop/reverse_proxy.html) to handle TLS termination, or use an external ACME client (such as [certbot](https://certbot.eff.org/)) to retrieve a certificate and key and provide them to Synapse using the `tls_certificate_path` and `tls_private_key_path` configuration settings. + + +Features +-------- + +- Implement "room knocking" as per [MSC2403](https://github.com/matrix-org/matrix-doc/pull/2403). Contributed by @Sorunome and anoa. ([\#6739](https://github.com/matrix-org/synapse/issues/6739), [\#9359](https://github.com/matrix-org/synapse/issues/9359), [\#10167](https://github.com/matrix-org/synapse/issues/10167), [\#10212](https://github.com/matrix-org/synapse/issues/10212), [\#10227](https://github.com/matrix-org/synapse/issues/10227)) +- Add experimental support for backfilling history into rooms ([MSC2716](https://github.com/matrix-org/matrix-doc/pull/2716)). ([\#9247](https://github.com/matrix-org/synapse/issues/9247)) +- Implement a generic interface for third-party plugin modules. ([\#10062](https://github.com/matrix-org/synapse/issues/10062), [\#10206](https://github.com/matrix-org/synapse/issues/10206)) +- Implement config option `sso.update_profile_information` to sync SSO users' profile information with the identity provider each time they login. Currently only displayname is supported. ([\#10108](https://github.com/matrix-org/synapse/issues/10108)) +- Ensure that errors during startup are written to the logs and the console. ([\#10191](https://github.com/matrix-org/synapse/issues/10191)) + + +Bugfixes +-------- + +- Fix a bug introduced in Synapse v1.25.0 that prevented the `ip_range_whitelist` configuration option from working for federation and identity servers. Contributed by @mikure. ([\#10115](https://github.com/matrix-org/synapse/issues/10115)) +- Remove a broken import line in Synapse's `admin_cmd` worker. Broke in Synapse v1.33.0. ([\#10154](https://github.com/matrix-org/synapse/issues/10154)) +- Fix a bug introduced in Synapse v1.21.0 which could cause `/sync` to return immediately with an empty response. ([\#10157](https://github.com/matrix-org/synapse/issues/10157), [\#10158](https://github.com/matrix-org/synapse/issues/10158)) +- Fix a minor bug in the response to `/_matrix/client/r0/user/{user}/openid/request_token` causing `expires_in` to be a float instead of an integer. Contributed by @lukaslihotzki. ([\#10175](https://github.com/matrix-org/synapse/issues/10175)) +- Always require users to re-authenticate for dangerous operations: deactivating an account, modifying an account password, and adding 3PIDs. ([\#10184](https://github.com/matrix-org/synapse/issues/10184)) +- Fix a bug introduced in Synpase v1.7.2 where remote server count metrics collection would be incorrectly delayed on startup. Found by @heftig. ([\#10195](https://github.com/matrix-org/synapse/issues/10195)) +- Fix a bug introduced in Synapse v1.35.1 where an `allow` key of a `m.room.join_rules` event could be applied for incorrect room versions and configurations. ([\#10208](https://github.com/matrix-org/synapse/issues/10208)) +- Fix performance regression in responding to user key requests over federation. Introduced in Synapse v1.34.0rc1. ([\#10221](https://github.com/matrix-org/synapse/issues/10221)) + + +Improved Documentation +---------------------- + +- Add a new guide to decoding request logs. ([\#8436](https://github.com/matrix-org/synapse/issues/8436)) +- Mention in the sample homeserver config that you may need to configure max upload size in your reverse proxy. Contributed by @aaronraimist. ([\#10122](https://github.com/matrix-org/synapse/issues/10122)) +- Fix broken links in documentation. ([\#10180](https://github.com/matrix-org/synapse/issues/10180)) +- Deploy a snapshot of the documentation website upon each new Synapse release. ([\#10198](https://github.com/matrix-org/synapse/issues/10198)) + + +Deprecations and Removals +------------------------- + +- The current spam checker interface is deprecated in favour of a new generic modules system. See the [upgrade notes](https://matrix-org.github.io/synapse/develop/upgrade#deprecation-of-the-current-spam-checker-interface) for more information on how to update to the new system. ([\#10062](https://github.com/matrix-org/synapse/issues/10062), [\#10210](https://github.com/matrix-org/synapse/issues/10210), [\#10238](https://github.com/matrix-org/synapse/issues/10238)) +- Stop supporting the unstable spaces prefixes from MSC1772. ([\#10161](https://github.com/matrix-org/synapse/issues/10161)) +- Remove Synapse's support for automatically fetching and renewing certificates using the ACME v1 protocol. This protocol has been fully turned off by Let's Encrypt for existing installations on June 1st 2021. Admins previously using this feature should use a [reverse proxy](https://matrix-org.github.io/synapse/develop/reverse_proxy.html) to handle TLS termination, or use an external ACME client (such as [certbot](https://certbot.eff.org/)) to retrieve a certificate and key and provide them to Synapse using the `tls_certificate_path` and `tls_private_key_path` configuration settings. ([\#10194](https://github.com/matrix-org/synapse/issues/10194)) + + +Internal Changes +---------------- + +- Update the database schema versioning to support gradual migration away from legacy tables. ([\#9933](https://github.com/matrix-org/synapse/issues/9933)) +- Add type hints to the federation servlets. ([\#10080](https://github.com/matrix-org/synapse/issues/10080)) +- Improve OpenTracing for event persistence. ([\#10134](https://github.com/matrix-org/synapse/issues/10134), [\#10193](https://github.com/matrix-org/synapse/issues/10193)) +- Clean up the interface for injecting OpenTracing over HTTP. ([\#10143](https://github.com/matrix-org/synapse/issues/10143)) +- Limit the number of in-flight `/keys/query` requests from a single device. ([\#10144](https://github.com/matrix-org/synapse/issues/10144)) +- Refactor EventPersistenceQueue. ([\#10145](https://github.com/matrix-org/synapse/issues/10145)) +- Document `SYNAPSE_TEST_LOG_LEVEL` to see the logger output when running tests. ([\#10148](https://github.com/matrix-org/synapse/issues/10148)) +- Update the Complement build tags in GitHub Actions to test currently experimental features. ([\#10155](https://github.com/matrix-org/synapse/issues/10155)) +- Add a `synapse_federation_soft_failed_events_total` metric to track how often events are soft failed. ([\#10156](https://github.com/matrix-org/synapse/issues/10156)) +- Fetch the corresponding complement branch when performing CI. ([\#10160](https://github.com/matrix-org/synapse/issues/10160)) +- Add some developer documentation about boolean columns in database schemas. ([\#10164](https://github.com/matrix-org/synapse/issues/10164)) +- Add extra logging fields to better debug where events are being soft failed. ([\#10168](https://github.com/matrix-org/synapse/issues/10168)) +- Add debug logging for when we enter and exit `Measure` blocks. ([\#10183](https://github.com/matrix-org/synapse/issues/10183)) +- Improve comments in structured logging code. ([\#10188](https://github.com/matrix-org/synapse/issues/10188)) +- Update [MSC3083](https://github.com/matrix-org/matrix-doc/pull/3083) support with modifications from the MSC. ([\#10189](https://github.com/matrix-org/synapse/issues/10189)) +- Remove redundant DNS lookup limiter. ([\#10190](https://github.com/matrix-org/synapse/issues/10190)) +- Upgrade `black` linting tool to 21.6b0. ([\#10197](https://github.com/matrix-org/synapse/issues/10197)) +- Expose OpenTracing trace id in response headers. ([\#10199](https://github.com/matrix-org/synapse/issues/10199)) + + Synapse 1.36.0 (2021-06-15) =========================== diff --git a/changelog.d/10062.feature b/changelog.d/10062.feature deleted file mode 100644 index 97474f030c..0000000000 --- a/changelog.d/10062.feature +++ /dev/null @@ -1 +0,0 @@ -Standardised the module interface. diff --git a/changelog.d/10062.removal b/changelog.d/10062.removal deleted file mode 100644 index 617785df5f..0000000000 --- a/changelog.d/10062.removal +++ /dev/null @@ -1 +0,0 @@ -The current spam checker interface is deprecated in favour of a new generic modules system. See the [upgrade notes](https://github.com/matrix-org/synapse/blob/master/docs/upgrade.md#deprecation-of-the-current-spam-checker-interface) for more information on how to update to the new system. \ No newline at end of file diff --git a/changelog.d/10080.misc b/changelog.d/10080.misc deleted file mode 100644 index 9adb0fbd02..0000000000 --- a/changelog.d/10080.misc +++ /dev/null @@ -1 +0,0 @@ -Add type hints to the federation servlets. diff --git a/changelog.d/10108.feature b/changelog.d/10108.feature deleted file mode 100644 index 4930a5acf5..0000000000 --- a/changelog.d/10108.feature +++ /dev/null @@ -1 +0,0 @@ -Implement config option `sso.update_profile_information` to sync SSO users' profile information with the identity provider each time they login. Currently only displayname is supported. diff --git a/changelog.d/10115.bugfix b/changelog.d/10115.bugfix deleted file mode 100644 index e16f356e68..0000000000 --- a/changelog.d/10115.bugfix +++ /dev/null @@ -1 +0,0 @@ -Fix a bug introduced in Synapse v1.25.0 that prevented the `ip_range_whitelist` configuration option from working for federation and identity servers. Contributed by @mikure. diff --git a/changelog.d/10122.doc b/changelog.d/10122.doc deleted file mode 100644 index 07a0d2520d..0000000000 --- a/changelog.d/10122.doc +++ /dev/null @@ -1 +0,0 @@ -Mention in the sample homeserver config that you may need to configure max upload size in your reverse proxy. Contributed by @aaronraimist. diff --git a/changelog.d/10134.misc b/changelog.d/10134.misc deleted file mode 100644 index ce9702645d..0000000000 --- a/changelog.d/10134.misc +++ /dev/null @@ -1 +0,0 @@ -Improve OpenTracing for event persistence. diff --git a/changelog.d/10143.misc b/changelog.d/10143.misc deleted file mode 100644 index 37aa344db2..0000000000 --- a/changelog.d/10143.misc +++ /dev/null @@ -1 +0,0 @@ -Clean up the interface for injecting opentracing over HTTP. diff --git a/changelog.d/10144.misc b/changelog.d/10144.misc deleted file mode 100644 index fe96d645d7..0000000000 --- a/changelog.d/10144.misc +++ /dev/null @@ -1 +0,0 @@ -Limit the number of in-flight `/keys/query` requests from a single device. diff --git a/changelog.d/10145.misc b/changelog.d/10145.misc deleted file mode 100644 index 2f0c643b08..0000000000 --- a/changelog.d/10145.misc +++ /dev/null @@ -1 +0,0 @@ -Refactor EventPersistenceQueue. diff --git a/changelog.d/10148.misc b/changelog.d/10148.misc deleted file mode 100644 index 5066392d40..0000000000 --- a/changelog.d/10148.misc +++ /dev/null @@ -1 +0,0 @@ -Document `SYNAPSE_TEST_LOG_LEVEL` to see the logger output when running tests. diff --git a/changelog.d/10154.bugfix b/changelog.d/10154.bugfix deleted file mode 100644 index f70a3d47bc..0000000000 --- a/changelog.d/10154.bugfix +++ /dev/null @@ -1 +0,0 @@ -Remove a broken import line in Synapse's admin_cmd worker. Broke in 1.33.0. \ No newline at end of file diff --git a/changelog.d/10155.misc b/changelog.d/10155.misc deleted file mode 100644 index 27b98e7fed..0000000000 --- a/changelog.d/10155.misc +++ /dev/null @@ -1 +0,0 @@ -Update the Complement build tags in GitHub Actions to test currently experimental features. \ No newline at end of file diff --git a/changelog.d/10156.misc b/changelog.d/10156.misc deleted file mode 100644 index 92a188b87b..0000000000 --- a/changelog.d/10156.misc +++ /dev/null @@ -1 +0,0 @@ -Add `synapse_federation_soft_failed_events_total` metric to track how often events are soft failed. diff --git a/changelog.d/10157.bugfix b/changelog.d/10157.bugfix deleted file mode 100644 index 6eaaa05b80..0000000000 --- a/changelog.d/10157.bugfix +++ /dev/null @@ -1 +0,0 @@ -Fix a bug introduced in v1.21.0 which could cause `/sync` to return immediately with an empty response. diff --git a/changelog.d/10158.bugfix b/changelog.d/10158.bugfix deleted file mode 100644 index 6eaaa05b80..0000000000 --- a/changelog.d/10158.bugfix +++ /dev/null @@ -1 +0,0 @@ -Fix a bug introduced in v1.21.0 which could cause `/sync` to return immediately with an empty response. diff --git a/changelog.d/10160.misc b/changelog.d/10160.misc deleted file mode 100644 index 80f378130f..0000000000 --- a/changelog.d/10160.misc +++ /dev/null @@ -1 +0,0 @@ -Fetch the corresponding complement branch when performing CI. diff --git a/changelog.d/10161.removal b/changelog.d/10161.removal deleted file mode 100644 index d4411464c7..0000000000 --- a/changelog.d/10161.removal +++ /dev/null @@ -1 +0,0 @@ -Stop supporting the unstable spaces prefixes from MSC1772. diff --git a/changelog.d/10164.misc b/changelog.d/10164.misc deleted file mode 100644 index a98f1e7c7a..0000000000 --- a/changelog.d/10164.misc +++ /dev/null @@ -1 +0,0 @@ -Add some developer documentation about boolean columns in database schemas. diff --git a/changelog.d/10167.feature b/changelog.d/10167.feature deleted file mode 100644 index 9c41140194..0000000000 --- a/changelog.d/10167.feature +++ /dev/null @@ -1 +0,0 @@ -Implement "room knocking" as per [MSC2403](https://github.com/matrix-org/matrix-doc/pull/2403). Contributed by Sorunome and anoa. \ No newline at end of file diff --git a/changelog.d/10168.misc b/changelog.d/10168.misc deleted file mode 100644 index 5ca7b89806..0000000000 --- a/changelog.d/10168.misc +++ /dev/null @@ -1 +0,0 @@ -Add extra logging fields to better debug where events are being soft failed. diff --git a/changelog.d/10175.bugfix b/changelog.d/10175.bugfix deleted file mode 100644 index 42e8f749cc..0000000000 --- a/changelog.d/10175.bugfix +++ /dev/null @@ -1 +0,0 @@ -Fix a minor bug in the response to `/_matrix/client/r0/user/{user}/openid/request_token`. Contributed by @lukaslihotzki. diff --git a/changelog.d/10180.doc b/changelog.d/10180.doc deleted file mode 100644 index 1568450198..0000000000 --- a/changelog.d/10180.doc +++ /dev/null @@ -1 +0,0 @@ -Fix broken links in documentation. \ No newline at end of file diff --git a/changelog.d/10183.misc b/changelog.d/10183.misc deleted file mode 100644 index c0e01ad3db..0000000000 --- a/changelog.d/10183.misc +++ /dev/null @@ -1 +0,0 @@ -Add debug logging for when we enter and exit `Measure` blocks. diff --git a/changelog.d/10184.bugfix b/changelog.d/10184.bugfix deleted file mode 100644 index 6bf440d8f8..0000000000 --- a/changelog.d/10184.bugfix +++ /dev/null @@ -1 +0,0 @@ -Always require users to re-authenticate for dangerous operations: deactivating an account, modifying an account password, and adding 3PIDs. diff --git a/changelog.d/10188.misc b/changelog.d/10188.misc deleted file mode 100644 index c1ea81c21a..0000000000 --- a/changelog.d/10188.misc +++ /dev/null @@ -1 +0,0 @@ -Improve comments in structured logging code. diff --git a/changelog.d/10189.misc b/changelog.d/10189.misc deleted file mode 100644 index df0e636c7d..0000000000 --- a/changelog.d/10189.misc +++ /dev/null @@ -1 +0,0 @@ -Update MSC3083 support for modifications in the MSC. diff --git a/changelog.d/10190.misc b/changelog.d/10190.misc deleted file mode 100644 index 388ed3ffb6..0000000000 --- a/changelog.d/10190.misc +++ /dev/null @@ -1 +0,0 @@ -Remove redundant DNS lookup limiter. diff --git a/changelog.d/10191.feature b/changelog.d/10191.feature deleted file mode 100644 index 40f306c421..0000000000 --- a/changelog.d/10191.feature +++ /dev/null @@ -1 +0,0 @@ -Ensure that errors during startup are written to the logs and the console. diff --git a/changelog.d/10193.misc b/changelog.d/10193.misc deleted file mode 100644 index ce9702645d..0000000000 --- a/changelog.d/10193.misc +++ /dev/null @@ -1 +0,0 @@ -Improve OpenTracing for event persistence. diff --git a/changelog.d/10194.removal b/changelog.d/10194.removal deleted file mode 100644 index 74874df4eb..0000000000 --- a/changelog.d/10194.removal +++ /dev/null @@ -1 +0,0 @@ -Remove Synapse's support for automatically fetching and renewing certificates using the ACME v1 protocol. This protocol has been fully turned off by Let's Encrypt for existing install on June 1st 2021. Admins previously using this feature should use a [reverse proxy](https://matrix-org.github.io/synapse/develop/reverse_proxy.html) to handle TLS termination, or use an external ACME client (such as [certbot](https://certbot.eff.org/)) to retrieve a certificate and key and provide them to Synapse using the `tls_certificate_path` and `tls_private_key_path` configuration settings. diff --git a/changelog.d/10195.bugfix b/changelog.d/10195.bugfix deleted file mode 100644 index 01cab1bda8..0000000000 --- a/changelog.d/10195.bugfix +++ /dev/null @@ -1 +0,0 @@ -Fix a bug introduced in Synpase 1.7.2 where remote server count metrics collection would be incorrectly delayed on startup. Found by @heftig. \ No newline at end of file diff --git a/changelog.d/10197.misc b/changelog.d/10197.misc deleted file mode 100644 index cbb3b454be..0000000000 --- a/changelog.d/10197.misc +++ /dev/null @@ -1 +0,0 @@ -Upgrade `black` linting tool to 21.6b0. diff --git a/changelog.d/10198.doc b/changelog.d/10198.doc deleted file mode 100644 index 8d1aeab1a7..0000000000 --- a/changelog.d/10198.doc +++ /dev/null @@ -1 +0,0 @@ -Deploy a snapshot of the documentation website upon each new Synapse release. diff --git a/changelog.d/10199.misc b/changelog.d/10199.misc deleted file mode 100644 index 69b18aeacc..0000000000 --- a/changelog.d/10199.misc +++ /dev/null @@ -1 +0,0 @@ -Expose opentracing trace id in response headers. diff --git a/changelog.d/10206.feature b/changelog.d/10206.feature deleted file mode 100644 index 97474f030c..0000000000 --- a/changelog.d/10206.feature +++ /dev/null @@ -1 +0,0 @@ -Standardised the module interface. diff --git a/changelog.d/10208.bugfix b/changelog.d/10208.bugfix deleted file mode 100644 index 32b6465717..0000000000 --- a/changelog.d/10208.bugfix +++ /dev/null @@ -1 +0,0 @@ -Fix a bug introduced in v1.35.1 where an `allow` key of a `m.room.join_rules` event could be applied for incorrect room versions and configurations. diff --git a/changelog.d/10210.removal b/changelog.d/10210.removal deleted file mode 100644 index 5fb7bfb47e..0000000000 --- a/changelog.d/10210.removal +++ /dev/null @@ -1 +0,0 @@ -The current spam checker interface is deprecated in favour of a new generic modules system. See the [upgrade notes](https://github.com/matrix-org/synapse/blob/master/UPGRADE.rst#deprecation-of-the-current-spam-checker-interface) for more information on how to update to the new system. diff --git a/changelog.d/10212.feature b/changelog.d/10212.feature deleted file mode 100644 index 9c41140194..0000000000 --- a/changelog.d/10212.feature +++ /dev/null @@ -1 +0,0 @@ -Implement "room knocking" as per [MSC2403](https://github.com/matrix-org/matrix-doc/pull/2403). Contributed by Sorunome and anoa. \ No newline at end of file diff --git a/changelog.d/10221.bugfix b/changelog.d/10221.bugfix deleted file mode 100644 index 8853a9bf4e..0000000000 --- a/changelog.d/10221.bugfix +++ /dev/null @@ -1 +0,0 @@ -Fix performance regression in responding to user key requests over federation. Introduced in v1.34.0rc1. diff --git a/changelog.d/10227.feature b/changelog.d/10227.feature deleted file mode 100644 index 9c41140194..0000000000 --- a/changelog.d/10227.feature +++ /dev/null @@ -1 +0,0 @@ -Implement "room knocking" as per [MSC2403](https://github.com/matrix-org/matrix-doc/pull/2403). Contributed by Sorunome and anoa. \ No newline at end of file diff --git a/changelog.d/6739.feature b/changelog.d/6739.feature deleted file mode 100644 index 9c41140194..0000000000 --- a/changelog.d/6739.feature +++ /dev/null @@ -1 +0,0 @@ -Implement "room knocking" as per [MSC2403](https://github.com/matrix-org/matrix-doc/pull/2403). Contributed by Sorunome and anoa. \ No newline at end of file diff --git a/changelog.d/8436.doc b/changelog.d/8436.doc deleted file mode 100644 index 77fc098200..0000000000 --- a/changelog.d/8436.doc +++ /dev/null @@ -1 +0,0 @@ -Add a new guide to decoding request logs. diff --git a/changelog.d/9247.feature b/changelog.d/9247.feature deleted file mode 100644 index c687acf102..0000000000 --- a/changelog.d/9247.feature +++ /dev/null @@ -1 +0,0 @@ -Add experimental support for backfilling history into rooms ([MSC2716](https://github.com/matrix-org/matrix-doc/pull/2716)). diff --git a/changelog.d/9359.feature b/changelog.d/9359.feature deleted file mode 100644 index 9c41140194..0000000000 --- a/changelog.d/9359.feature +++ /dev/null @@ -1 +0,0 @@ -Implement "room knocking" as per [MSC2403](https://github.com/matrix-org/matrix-doc/pull/2403). Contributed by Sorunome and anoa. \ No newline at end of file diff --git a/changelog.d/9933.misc b/changelog.d/9933.misc deleted file mode 100644 index 0860026670..0000000000 --- a/changelog.d/9933.misc +++ /dev/null @@ -1 +0,0 @@ -Update the database schema versioning to support gradual migration away from legacy tables. diff --git a/synapse/__init__.py b/synapse/__init__.py index c3016fc6ed..6d1c6d6f72 100644 --- a/synapse/__init__.py +++ b/synapse/__init__.py @@ -47,7 +47,7 @@ try: except ImportError: pass -__version__ = "1.36.0" +__version__ = "1.37.0rc1" if bool(os.environ.get("SYNAPSE_TEST_PATCH_LOG_CONTEXTS", False)): # We import here so that we don't have to install a bunch of deps when diff --git a/synapse/events/spamcheck.py b/synapse/events/spamcheck.py index 45ec96dfc1..efec16c226 100644 --- a/synapse/events/spamcheck.py +++ b/synapse/events/spamcheck.py @@ -109,6 +109,8 @@ def load_legacy_spam_checkers(hs: "synapse.server.HomeServer"): if f is None: return None + wrapped_func = f + if f.__name__ == "check_registration_for_spam": checker_args = inspect.signature(f) if len(checker_args.parameters) == 3: @@ -133,19 +135,18 @@ def load_legacy_spam_checkers(hs: "synapse.server.HomeServer"): request_info, ) - f = wrapper + wrapped_func = wrapper elif len(checker_args.parameters) != 4: raise RuntimeError( "Bad signature for callback check_registration_for_spam", ) def run(*args, **kwargs): - # We've already made sure f is not None above, but mypy doesn't do well - # across function boundaries so we need to tell it f is definitely not - # None. - assert f is not None + # mypy doesn't do well across function boundaries so we need to tell it + # wrapped_func is definitely not None. + assert wrapped_func is not None - return maybe_awaitable(f(*args, **kwargs)) + return maybe_awaitable(wrapped_func(*args, **kwargs)) return run diff --git a/tests/handlers/test_register.py b/tests/handlers/test_register.py index c901003225..d3efb67e3e 100644 --- a/tests/handlers/test_register.py +++ b/tests/handlers/test_register.py @@ -17,6 +17,7 @@ from unittest.mock import Mock from synapse.api.auth import Auth from synapse.api.constants import UserTypes from synapse.api.errors import Codes, ResourceLimitError, SynapseError +from synapse.events.spamcheck import load_legacy_spam_checkers from synapse.spam_checker_api import RegistrationBehaviour from synapse.types import RoomAlias, RoomID, UserID, create_requester @@ -79,6 +80,39 @@ class BanBadIdPUser(TestSpamChecker): return RegistrationBehaviour.ALLOW +class TestLegacyRegistrationSpamChecker: + def __init__(self, config, api): + pass + + async def check_registration_for_spam( + self, + email_threepid, + username, + request_info, + ): + pass + + +class LegacyAllowAll(TestLegacyRegistrationSpamChecker): + async def check_registration_for_spam( + self, + email_threepid, + username, + request_info, + ): + return RegistrationBehaviour.ALLOW + + +class LegacyDenyAll(TestLegacyRegistrationSpamChecker): + async def check_registration_for_spam( + self, + email_threepid, + username, + request_info, + ): + return RegistrationBehaviour.DENY + + class RegistrationTestCase(unittest.HomeserverTestCase): """Tests the RegistrationHandler.""" @@ -95,6 +129,8 @@ class RegistrationTestCase(unittest.HomeserverTestCase): hs = self.setup_test_homeserver(config=hs_config) + load_legacy_spam_checkers(hs) + module_api = hs.get_module_api() for module, config in hs.config.modules.loaded_modules: module(config=config, api=module_api) @@ -535,6 +571,46 @@ class RegistrationTestCase(unittest.HomeserverTestCase): """A spam checker can deny registration, which results in an error.""" self.get_failure(self.handler.register_user(localpart="user"), SynapseError) + @override_config( + { + "spam_checker": [ + { + "module": TestSpamChecker.__module__ + ".LegacyAllowAll", + } + ] + } + ) + def test_spam_checker_legacy_allow(self): + """Tests that a legacy spam checker implementing the legacy 3-arg version of the + check_registration_for_spam callback is correctly called. + + In this test and the following one we test both success and failure to make sure + any failure comes from the spam checker (and not something else failing in the + call stack) and any success comes from the spam checker (and not because a + misconfiguration prevented it from being loaded). + """ + self.get_success(self.handler.register_user(localpart="user")) + + @override_config( + { + "spam_checker": [ + { + "module": TestSpamChecker.__module__ + ".LegacyDenyAll", + } + ] + } + ) + def test_spam_checker_legacy_deny(self): + """Tests that a legacy spam checker implementing the legacy 3-arg version of the + check_registration_for_spam callback is correctly called. + + In this test and the previous one we test both success and failure to make sure + any failure comes from the spam checker (and not something else failing in the + call stack) and any success comes from the spam checker (and not because a + misconfiguration prevented it from being loaded). + """ + self.get_failure(self.handler.register_user(localpart="user"), SynapseError) + @override_config( { "modules": [