summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--CONTRIBUTING.md271
-rw-r--r--changelog.d/9281.doc1
-rw-r--r--changelog.d/9390.doc1
-rw-r--r--changelog.d/9400.feature1
-rw-r--r--changelog.d/9408.misc1
-rw-r--r--changelog.d/9421.bugfix1
-rw-r--r--changelog.d/9425.bugfix1
-rw-r--r--changelog.d/9428.bugfix1
-rw-r--r--docs/admin_api/user_admin_api.rst9
-rw-r--r--docs/reverse_proxy.md8
-rw-r--r--docs/workers.md3
-rw-r--r--synapse/handlers/presence.py18
-rw-r--r--synapse/handlers/user_directory.py4
-rw-r--r--synapse/http/client.py26
-rw-r--r--synapse/storage/databases/main/__init__.py2
-rw-r--r--synapse/storage/databases/main/registration.py7
-rw-r--r--synapse/storage/databases/main/user_directory.py8
-rw-r--r--tests/http/test_client.py9
-rw-r--r--tests/rest/admin/test_user.py2
-rw-r--r--tests/storage/test_registration.py1
20 files changed, 250 insertions, 125 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md

index 1d7bb8f969..b6a70f7ffe 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md
@@ -1,4 +1,31 @@ -# Contributing code to Synapse +Welcome to Synapse + +This document aims to get you started with contributing to this repo! + +- [1. Who can contribute to Synapse?](#1-who-can-contribute-to-synapse) +- [2. What do I need?](#2-what-do-i-need) +- [3. Get the source.](#3-get-the-source) +- [4. Install the dependencies](#4-install-the-dependencies) + * [Under Unix (macOS, Linux, BSD, ...)](#under-unix-macos-linux-bsd-) + * [Under Windows](#under-windows) +- [5. Get in touch.](#5-get-in-touch) +- [6. Pick an issue.](#6-pick-an-issue) +- [7. Turn coffee and documentation into code and documentation!](#7-turn-coffee-and-documentation-into-code-and-documentation) +- [8. Test, test, test!](#8-test-test-test) + * [Run the linters.](#run-the-linters) + * [Run the unit tests.](#run-the-unit-tests) + * [Run the integration tests.](#run-the-integration-tests) +- [9. Submit your patch.](#9-submit-your-patch) + * [Changelog](#changelog) + + [How do I know what to call the changelog file before I create the PR?](#how-do-i-know-what-to-call-the-changelog-file-before-i-create-the-pr) + + [Debian changelog](#debian-changelog) + * [Sign off](#sign-off) +- [10. Turn feedback into better code.](#10-turn-feedback-into-better-code) +- [11. Find a new issue.](#11-find-a-new-issue) +- [Notes for maintainers on merging PRs etc](#notes-for-maintainers-on-merging-prs-etc) +- [Conclusion](#conclusion) + +# 1. Who can contribute to Synapse? Everyone is welcome to contribute code to [matrix.org projects](https://github.com/matrix-org), provided that they are willing to @@ -9,70 +36,179 @@ license the code under the same terms as the project's overall 'outbound' license - in our case, this is almost always Apache Software License v2 (see [LICENSE](LICENSE)). -## How to contribute +# 2. What do I need? + +The code of Synapse is written in Python 3. To do pretty much anything, you'll need [a recent version of Python 3](https://wiki.python.org/moin/BeginnersGuide/Download). + +The source code of Synapse is hosted on GitHub. You will also need [a recent version of git](https://github.com/git-guides/install-git). + +For some tests, you will need [a recent version of Docker](https://docs.docker.com/get-docker/). + + +# 3. Get the source. The preferred and easiest way to contribute changes is to fork the relevant -project on github, and then [create a pull request]( +project on GitHub, and then [create a pull request]( https://help.github.com/articles/using-pull-requests/) to ask us to pull your changes into our repo. -Some other points to follow: +Please base your changes on the `develop` branch. + +```sh +git clone git@github.com:YOUR_GITHUB_USER_NAME/synapse.git +git checkout develop +``` + +If you need help getting started with git, this is beyond the scope of the document, but you +can find many good git tutorials on the web. + +# 4. Install the dependencies - * Please base your changes on the `develop` branch. +## Under Unix (macOS, Linux, BSD, ...) - * Please follow the [code style requirements](#code-style). +Once you have installed Python 3 and added the source, please open a terminal and +setup a *virtualenv*, as follows: + +```sh +cd path/where/you/have/cloned/the/repository +python3 -m venv ./env +source ./env/bin/activate +pip install -e ".[all,lint,mypy,test]" +pip install tox +``` + +This will install the developer dependencies for the project. + +## Under Windows + +TBD - * Please include a [changelog entry](#changelog) with each PR. - * Please [sign off](#sign-off) your contribution. +# 5. Get in touch. - * Please keep an eye on the pull request for feedback from the [continuous - integration system](#continuous-integration-and-testing) and try to fix any - errors that come up. +Join our developer community on Matrix: #synapse-dev:matrix.org ! - * If you need to [update your PR](#updating-your-pull-request), just add new - commits to your branch rather than rebasing. -## Code style +# 6. Pick an issue. + +Fix your favorite problem or perhaps find a [Good First Issue](https://github.com/matrix-org/synapse/issues?q=is%3Aopen+is%3Aissue+label%3A%22Good+First+Issue%22) +to work on. + + +# 7. Turn coffee and documentation into code and documentation! Synapse's code style is documented [here](docs/code_style.md). Please follow it, including the conventions for the [sample configuration file](docs/code_style.md#configuration-file-format). -Many of the conventions are enforced by scripts which are run as part of the -[continuous integration system](#continuous-integration-and-testing). To help -check if you have followed the code style, you can run `scripts-dev/lint.sh` -locally. You'll need python 3.6 or later, and to install a number of tools: +There is a growing amount of documentation located in the [docs](docs) +directory. This documentation is intended primarily for sysadmins running their +own Synapse instance, as well as developers interacting externally with +Synapse. [docs/dev](docs/dev) exists primarily to house documentation for +Synapse developers. [docs/admin_api](docs/admin_api) houses documentation +regarding Synapse's Admin API, which is used mostly by sysadmins and external +service developers. -``` -# Install the dependencies -pip install -e ".[lint,mypy]" +If you add new files added to either of these folders, please use [GitHub-Flavoured +Markdown](https://guides.github.com/features/mastering-markdown/). + +Some documentation also exists in [Synapse's GitHub +Wiki](https://github.com/matrix-org/synapse/wiki), although this is primarily +contributed to by community authors. + + +# 8. Test, test, test! +<a name="test-test-test"></a> + +While you're developing and before submitting a patch, you'll +want to test your code. + +## Run the linters. + +The linters look at your code and do two things: + +- ensure that your code follows the coding style adopted by the project; +- catch a number of errors in your code. + +They're pretty fast, don't hesitate! -# Run the linter script +```sh +source ./env/bin/activate ./scripts-dev/lint.sh ``` -**Note that the script does not just test/check, but also reformats code, so you -may wish to ensure any new code is committed first**. +Note that this script *will modify your files* to fix styling errors. +Make sure that you have saved all your files. -By default, this script checks all files and can take some time; if you alter -only certain files, you might wish to specify paths as arguments to reduce the -run-time: +If you wish to restrict the linters to only the files changed since the last commit +(much faster!), you can instead run: +```sh +source ./env/bin/activate +./scripts-dev/lint.sh -d ``` + +Or if you know exactly which files you wish to lint, you can instead run: + +```sh +source ./env/bin/activate ./scripts-dev/lint.sh path/to/file1.py path/to/file2.py path/to/folder ``` -You can also provide the `-d` option, which will lint the files that have been -changed since the last git commit. This will often be significantly faster than -linting the whole codebase. +## Run the unit tests. + +The unit tests run parts of Synapse, including your changes, to see if anything +was broken. They are slower than the linters but will typically catch more errors. + +```sh +source ./env/bin/activate +trial tests +``` + +If you wish to only run *some* unit tests, you may specify +another module instead of `tests` - or a test class or a method: + +```sh +source ./env/bin/activate +trial tests.rest.admin.test_room tests.handlers.test_admin.ExfiltrateData.test_invite +``` + +If your tests fail, you may wish to look at the logs: + +```sh +less _trial_temp/test.log +``` + +## Run the integration tests. + +The integration tests are a more comprehensive suite of tests. They +run a full version of Synapse, including your changes, to check if +anything was broken. They are slower than the unit tests but will +typically catch more errors. + +The following command will let you run the integration test with the most common +configuration: + +```sh +$ docker run --rm -it -v /path/where/you/have/cloned/the/repository\:/src:ro -v /path/to/where/you/want/logs\:/logs matrixdotorg/sytest-synapse:py37 +``` + +This configuration should generally cover your needs. For more details about other configurations, see [documentation in the SyTest repo](https://github.com/matrix-org/sytest/blob/develop/docker/README.md). + -Before pushing new changes, ensure they don't produce linting errors. Commit any -files that were corrected. +# 9. Submit your patch. + +Once you're happy with your patch, it's time to prepare a Pull Request. + +To prepare a Pull Request, please: + +1. verify that [all the tests pass](#test-test-test), including the coding style; +2. [sign off](#sign-off) your contribution; +3. `git push` your commit to your fork of Synapse; +4. on GitHub, [create the Pull Request](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request); +5. add a [changelog entry](#changelog) and push it to your Pull Request; +6. for most contributors, that's all - however, if you are a member of the organization `matrix-org`, on GitHub, please request a review from `matrix.org / Synapse Core`. -Please ensure your changes match the cosmetic style of the existing project, -and **never** mix cosmetic and functional changes in the same commit, as it -makes it horribly hard to review otherwise. ## Changelog @@ -156,24 +292,6 @@ directory, you will need both a regular newsfragment *and* an entry in the debian changelog. (Though typically such changes should be submitted as two separate pull requests.) -## Documentation - -There is a growing amount of documentation located in the [docs](docs) -directory. This documentation is intended primarily for sysadmins running their -own Synapse instance, as well as developers interacting externally with -Synapse. [docs/dev](docs/dev) exists primarily to house documentation for -Synapse developers. [docs/admin_api](docs/admin_api) houses documentation -regarding Synapse's Admin API, which is used mostly by sysadmins and external -service developers. - -New files added to both folders should be written in [Github-Flavoured -Markdown](https://guides.github.com/features/mastering-markdown/), and attempts -should be made to migrate existing documents to markdown where possible. - -Some documentation also exists in [Synapse's Github -Wiki](https://github.com/matrix-org/synapse/wiki), although this is primarily -contributed to by community authors. - ## Sign off In order to have a concrete record that your contribution is intentional @@ -240,47 +358,36 @@ Git allows you to add this signoff automatically when using the `-s` flag to `git commit`, which uses the name and email set in your `user.name` and `user.email` git configs. -## Continuous integration and testing -[Buildkite](https://buildkite.com/matrix-dot-org/synapse) will automatically -run a series of checks and tests against any PR which is opened against the -project; if your change breaks the build, this will be shown in GitHub, with -links to the build results. If your build fails, please try to fix the errors -and update your branch. +# 10. Turn feedback into better code. + +Once the Pull Request is opened, you will see a few things: -To run unit tests in a local development environment, you can use: +1. our automated CI (Continuous Integration) pipeline will run (again) the linters, the unit tests, the integration tests and more; +2. one or more of the developers will take a look at your Pull Request and offer feedback. -- ``tox -e py35`` (requires tox to be installed by ``pip install tox``) - for SQLite-backed Synapse on Python 3.5. -- ``tox -e py36`` for SQLite-backed Synapse on Python 3.6. -- ``tox -e py36-postgres`` for PostgreSQL-backed Synapse on Python 3.6 - (requires a running local PostgreSQL with access to create databases). -- ``./test_postgresql.sh`` for PostgreSQL-backed Synapse on Python 3.5 - (requires Docker). Entirely self-contained, recommended if you don't want to - set up PostgreSQL yourself. +From this point, you should: -Docker images are available for running the integration tests (SyTest) locally, -see the [documentation in the SyTest repo]( -https://github.com/matrix-org/sytest/blob/develop/docker/README.md) for more -information. +1. Look at the results of the CI pipeline. + - If there is any error, fix the error. +2. If a developer has requested changes, make these changes and let us know if it is ready for a developer to review again. +3. Create a new commit with the changes. + - Please do NOT overwrite the history. New commits make the reviewer's life easier. + - Push this commits to your Pull Request. +4. Back to 1. -## Updating your pull request +Once both the CI and the developers are happy, the patch will be merged into Synapse and released shortly! -If you decide to make changes to your pull request - perhaps to address issues -raised in a review, or to fix problems highlighted by [continuous -integration](#continuous-integration-and-testing) - just add new commits to your -branch, and push to GitHub. The pull request will automatically be updated. +# 11. Find a new issue. -Please **avoid** rebasing your branch, especially once the PR has been -reviewed: doing so makes it very difficult for a reviewer to see what has -changed since a previous review. +By now, you know the drill! -## Notes for maintainers on merging PRs etc +# Notes for maintainers on merging PRs etc There are some notes for those with commit access to the project on how we manage git [here](docs/dev/git.md). -## Conclusion +# Conclusion That's it! Matrix is a very open and collaborative project as you might expect given our obsession with open communication. If we're going to successfully diff --git a/changelog.d/9281.doc b/changelog.d/9281.doc new file mode 100644
index 0000000000..4dea375f80 --- /dev/null +++ b/changelog.d/9281.doc
@@ -0,0 +1 @@ +Reorganizing CHANGELOG.md. \ No newline at end of file diff --git a/changelog.d/9390.doc b/changelog.d/9390.doc new file mode 100644
index 0000000000..8ed2aa8b6a --- /dev/null +++ b/changelog.d/9390.doc
@@ -0,0 +1 @@ +Add HTTP/2 support to the nginx example configuration. Contributed by David Vo. diff --git a/changelog.d/9400.feature b/changelog.d/9400.feature new file mode 100644
index 0000000000..3067c3907b --- /dev/null +++ b/changelog.d/9400.feature
@@ -0,0 +1 @@ +Add the shadow-banning status to the display user admin API. \ No newline at end of file diff --git a/changelog.d/9408.misc b/changelog.d/9408.misc new file mode 100644
index 0000000000..600bacbfe7 --- /dev/null +++ b/changelog.d/9408.misc
@@ -0,0 +1 @@ +Clean up an unused method in the presence handler code. \ No newline at end of file diff --git a/changelog.d/9421.bugfix b/changelog.d/9421.bugfix new file mode 100644
index 0000000000..b73ed5664c --- /dev/null +++ b/changelog.d/9421.bugfix
@@ -0,0 +1 @@ +Reduce the amount of memory used when generating the URL preview of a file that is larger than the `max_spider_size`. diff --git a/changelog.d/9425.bugfix b/changelog.d/9425.bugfix new file mode 100644
index 0000000000..f5b8857cdb --- /dev/null +++ b/changelog.d/9425.bugfix
@@ -0,0 +1 @@ +Fix a long-standing bug in the deduplication of old presence, resulting in no deduplication. \ No newline at end of file diff --git a/changelog.d/9428.bugfix b/changelog.d/9428.bugfix new file mode 100644
index 0000000000..132e35440a --- /dev/null +++ b/changelog.d/9428.bugfix
@@ -0,0 +1 @@ +Fix a bug introduced in v1.27.0: "TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType." related to the user directory. diff --git a/docs/admin_api/user_admin_api.rst b/docs/admin_api/user_admin_api.rst
index 1eb674939e..33dfbcfb49 100644 --- a/docs/admin_api/user_admin_api.rst +++ b/docs/admin_api/user_admin_api.rst
@@ -29,8 +29,9 @@ It returns a JSON body like the following: } ], "avatar_url": "<avatar_url>", - "admin": false, - "deactivated": false, + "admin": 0, + "deactivated": 0, + "shadow_banned": 0, "password_hash": "$2b$12$p9B4GkqYdRTPGD", "creation_ts": 1560432506, "appservice_id": null, @@ -150,6 +151,7 @@ A JSON body is returned with the following shape: "admin": 0, "user_type": null, "deactivated": 0, + "shadow_banned": 0, "displayname": "<User One>", "avatar_url": null }, { @@ -158,6 +160,7 @@ A JSON body is returned with the following shape: "admin": 1, "user_type": null, "deactivated": 0, + "shadow_banned": 0, "displayname": "<User Two>", "avatar_url": "<avatar_url>" } @@ -262,7 +265,7 @@ The following actions are performed when deactivating an user: - Reject all pending invites - Remove all account validity information related to the user -The following additional actions are performed during deactivation if``erase`` +The following additional actions are performed during deactivation if ``erase`` is set to ``true``: - Remove the user's display name diff --git a/docs/reverse_proxy.md b/docs/reverse_proxy.md
index c7020f2df3..04b6e24124 100644 --- a/docs/reverse_proxy.md +++ b/docs/reverse_proxy.md
@@ -40,12 +40,12 @@ the reverse proxy and the homeserver. ``` server { - listen 443 ssl; - listen [::]:443 ssl; + listen 443 ssl http2; + listen [::]:443 ssl http2; # For the federation port - listen 8448 ssl default_server; - listen [::]:8448 ssl default_server; + listen 8448 ssl http2 default_server; + listen [::]:8448 ssl http2 default_server; server_name matrix.example.com; diff --git a/docs/workers.md b/docs/workers.md
index 9bda0f8c23..e7bf9b8ce4 100644 --- a/docs/workers.md +++ b/docs/workers.md
@@ -276,7 +276,8 @@ using): Ensure that all SSO logins go to a single process. For multiple workers not handling the SSO endpoints properly, see -[#7530](https://github.com/matrix-org/synapse/issues/7530). +[#7530](https://github.com/matrix-org/synapse/issues/7530) and +[#9427](https://github.com/matrix-org/synapse/issues/9427). Note that a HTTP listener with `client` and `federation` resources must be configured in the `worker_listeners` option in the worker config. diff --git a/synapse/handlers/presence.py b/synapse/handlers/presence.py
index 7ba22d511f..fb85b19770 100644 --- a/synapse/handlers/presence.py +++ b/synapse/handlers/presence.py
@@ -349,10 +349,13 @@ class PresenceHandler(BasePresenceHandler): [self.user_to_current_state[user_id] for user_id in unpersisted] ) - async def _update_states(self, new_states): + async def _update_states(self, new_states: Iterable[UserPresenceState]) -> None: """Updates presence of users. Sets the appropriate timeouts. Pokes the notifier and federation if and only if the changed presence state should be sent to clients/servers. + + Args: + new_states: The new user presence state updates to process. """ now = self.clock.time_msec() @@ -368,7 +371,7 @@ class PresenceHandler(BasePresenceHandler): new_states_dict = {} for new_state in new_states: new_states_dict[new_state.user_id] = new_state - new_state = new_states_dict.values() + new_states = new_states_dict.values() for new_state in new_states: user_id = new_state.user_id @@ -657,17 +660,6 @@ class PresenceHandler(BasePresenceHandler): self._push_to_remotes(states) - async def notify_for_states(self, state, stream_id): - parties = await get_interested_parties(self.store, [state]) - room_ids_to_states, users_to_states = parties - - self.notifier.on_new_event( - "presence_key", - stream_id, - rooms=room_ids_to_states.keys(), - users=[UserID.from_string(u) for u in users_to_states], - ) - def _push_to_remotes(self, states): """Sends state updates to remote servers. diff --git a/synapse/handlers/user_directory.py b/synapse/handlers/user_directory.py
index 3dfb0a26c2..1a8340000a 100644 --- a/synapse/handlers/user_directory.py +++ b/synapse/handlers/user_directory.py
@@ -143,6 +143,10 @@ class UserDirectoryHandler(StateDeltasHandler): if self.pos is None: self.pos = await self.store.get_user_directory_stream_pos() + # If still None then the initial background update hasn't happened yet. + if self.pos is None: + return None + # Loop round handling deltas until we're up to date while True: with Measure(self.clock, "user_dir_delta"): diff --git a/synapse/http/client.py b/synapse/http/client.py
index d6e06967c8..a910548f1e 100644 --- a/synapse/http/client.py +++ b/synapse/http/client.py
@@ -56,7 +56,7 @@ from twisted.web.client import ( ) from twisted.web.http import PotentialDataLoss from twisted.web.http_headers import Headers -from twisted.web.iweb import IAgent, IBodyProducer, IResponse +from twisted.web.iweb import UNKNOWN_LENGTH, IAgent, IBodyProducer, IResponse from synapse.api.errors import Codes, HttpResponseException, SynapseError from synapse.http import QuieterFileBodyProducer, RequestTimedOutError, redact_uri @@ -406,6 +406,9 @@ class SimpleHttpClient: agent=self.agent, data=body_producer, headers=headers, + # Avoid buffering the body in treq since we do not reuse + # response bodies. + unbuffered=True, **self._extra_treq_args, ) # type: defer.Deferred @@ -700,18 +703,6 @@ class SimpleHttpClient: resp_headers = dict(response.headers.getAllRawHeaders()) - if ( - b"Content-Length" in resp_headers - and max_size - and int(resp_headers[b"Content-Length"][0]) > max_size - ): - logger.warning("Requested URL is too large > %r bytes" % (max_size,)) - raise SynapseError( - 502, - "Requested file is too large > %r bytes" % (max_size,), - Codes.TOO_LARGE, - ) - if response.code > 299: logger.warning("Got %d when downloading %s" % (response.code, url)) raise SynapseError(502, "Got error %d" % (response.code,), Codes.UNKNOWN) @@ -778,7 +769,9 @@ class _ReadBodyWithMaxSizeProtocol(protocol.Protocol): # in the meantime. if self.max_size is not None and self.length >= self.max_size: self.deferred.errback(BodyExceededMaxSize()) - self.transport.loseConnection() + # Close the connection (forcefully) since all the data will get + # discarded anyway. + self.transport.abortConnection() def connectionLost(self, reason: Failure) -> None: # If the maximum size was already exceeded, there's nothing to do. @@ -812,6 +805,11 @@ def read_body_with_max_size( Returns: A Deferred which resolves to the length of the read body. """ + # If the Content-Length header gives a size larger than the maximum allowed + # size, do not bother downloading the body. + if max_size is not None and response.length != UNKNOWN_LENGTH: + if response.length > max_size: + return defer.fail(BodyExceededMaxSize()) d = defer.Deferred() response.deliverBody(_ReadBodyWithMaxSizeProtocol(stream, d, max_size)) diff --git a/synapse/storage/databases/main/__init__.py b/synapse/storage/databases/main/__init__.py
index 5d0845588c..70b49854cf 100644 --- a/synapse/storage/databases/main/__init__.py +++ b/synapse/storage/databases/main/__init__.py
@@ -340,7 +340,7 @@ class DataStore( count = txn.fetchone()[0] sql = ( - "SELECT name, user_type, is_guest, admin, deactivated, displayname, avatar_url " + "SELECT name, user_type, is_guest, admin, deactivated, shadow_banned, displayname, avatar_url " + sql_base + " ORDER BY u.name LIMIT ? OFFSET ?" ) diff --git a/synapse/storage/databases/main/registration.py b/synapse/storage/databases/main/registration.py
index 915b656b7a..25d8dcb6ab 100644 --- a/synapse/storage/databases/main/registration.py +++ b/synapse/storage/databases/main/registration.py
@@ -119,6 +119,7 @@ class RegistrationWorkerStore(CacheInvalidationWorkerStore): "creation_ts", "user_type", "deactivated", + "shadow_banned", ], allow_none=True, desc="get_user_by_id", @@ -475,23 +476,25 @@ class RegistrationWorkerStore(CacheInvalidationWorkerStore): """ def set_shadow_banned_txn(txn): + user_id = user.to_string() self.db_pool.simple_update_one_txn( txn, table="users", - keyvalues={"name": user.to_string()}, + keyvalues={"name": user_id}, updatevalues={"shadow_banned": shadow_banned}, ) # In order for this to apply immediately, clear the cache for this user. tokens = self.db_pool.simple_select_onecol_txn( txn, table="access_tokens", - keyvalues={"user_id": user.to_string()}, + keyvalues={"user_id": user_id}, retcol="token", ) for token in tokens: self._invalidate_cache_and_stream( txn, self.get_user_by_access_token, (token,) ) + self._invalidate_cache_and_stream(txn, self.get_user_by_id, (user_id,)) await self.db_pool.runInteraction("set_shadow_banned", set_shadow_banned_txn) diff --git a/synapse/storage/databases/main/user_directory.py b/synapse/storage/databases/main/user_directory.py
index 467738285f..02ee15676c 100644 --- a/synapse/storage/databases/main/user_directory.py +++ b/synapse/storage/databases/main/user_directory.py
@@ -712,7 +712,13 @@ class UserDirectoryStore(UserDirectoryBackgroundUpdateStore): return {row["room_id"] for row in rows} - async def get_user_directory_stream_pos(self) -> int: + async def get_user_directory_stream_pos(self) -> Optional[int]: + """ + Get the stream ID of the user directory stream. + + Returns: + The stream token or None if the initial background update hasn't happened yet. + """ return await self.db_pool.simple_select_one_onecol( table="user_directory_stream_pos", keyvalues={}, diff --git a/tests/http/test_client.py b/tests/http/test_client.py
index f17c122e93..2d9b733be0 100644 --- a/tests/http/test_client.py +++ b/tests/http/test_client.py
@@ -18,6 +18,7 @@ from mock import Mock from twisted.python.failure import Failure from twisted.web.client import ResponseDone +from twisted.web.iweb import UNKNOWN_LENGTH from synapse.http.client import BodyExceededMaxSize, read_body_with_max_size @@ -27,12 +28,12 @@ from tests.unittest import TestCase class ReadBodyWithMaxSizeTests(TestCase): def setUp(self): """Start reading the body, returns the response, result and proto""" - self.response = Mock() + response = Mock(length=UNKNOWN_LENGTH) self.result = BytesIO() - self.deferred = read_body_with_max_size(self.response, self.result, 6) + self.deferred = read_body_with_max_size(response, self.result, 6) # Fish the protocol out of the response. - self.protocol = self.response.deliverBody.call_args[0][0] + self.protocol = response.deliverBody.call_args[0][0] self.protocol.transport = Mock() def _cleanup_error(self): @@ -88,7 +89,7 @@ class ReadBodyWithMaxSizeTests(TestCase): self.protocol.dataReceived(b"1234567890") self.assertIsInstance(self.deferred.result, Failure) self.assertIsInstance(self.deferred.result.value, BodyExceededMaxSize) - self.protocol.transport.loseConnection.assert_called_once() + self.protocol.transport.abortConnection.assert_called_once() # More data might have come in. self.protocol.dataReceived(b"1234567890") diff --git a/tests/rest/admin/test_user.py b/tests/rest/admin/test_user.py
index 7eb6f6317a..b8d354beb7 100644 --- a/tests/rest/admin/test_user.py +++ b/tests/rest/admin/test_user.py
@@ -769,6 +769,7 @@ class UsersListTestCase(unittest.HomeserverTestCase): self.assertIn("admin", u) self.assertIn("user_type", u) self.assertIn("deactivated", u) + self.assertIn("shadow_banned", u) self.assertIn("displayname", u) self.assertIn("avatar_url", u) @@ -1151,6 +1152,7 @@ class UserRestTestCase(unittest.HomeserverTestCase): self.assertEqual(False, channel.json_body["admin"]) self.assertEqual(False, channel.json_body["is_guest"]) self.assertEqual(False, channel.json_body["deactivated"]) + self.assertEqual(False, channel.json_body["shadow_banned"]) self.assertEqual("mxc://fibble/wibble", channel.json_body["avatar_url"]) @override_config( diff --git a/tests/storage/test_registration.py b/tests/storage/test_registration.py
index abbaed7cdc..4eb41c46e8 100644 --- a/tests/storage/test_registration.py +++ b/tests/storage/test_registration.py
@@ -52,6 +52,7 @@ class RegistrationStoreTestCase(unittest.TestCase): "creation_ts": 1000, "user_type": None, "deactivated": 0, + "shadow_banned": 0, }, (yield defer.ensureDeferred(self.store.get_user_by_id(self.user_id))), )