mirror of
https://github.com/element-hq/synapse
synced 2024-09-17 20:05:10 +00:00
Merge branch 'develop' into madlittlemods/11850-migrate-to-opentelemetry
Conflicts: synapse/logging/opentracing.py tests/logging/test_opentracing.py
This commit is contained in:
commit
7024d7b86e
99 changed files with 1747 additions and 1039 deletions
74
CHANGES.md
74
CHANGES.md
|
@ -1,3 +1,77 @@
|
|||
Synapse 1.65.0rc1 (2022-08-09)
|
||||
==============================
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
- Add support for stable prefixes for [MSC2285 (private read receipts)](https://github.com/matrix-org/matrix-spec-proposals/pull/2285). ([\#13273](https://github.com/matrix-org/synapse/issues/13273))
|
||||
- Add new unstable error codes `ORG.MATRIX.MSC3848.ALREADY_JOINED`, `ORG.MATRIX.MSC3848.NOT_JOINED`, and `ORG.MATRIX.MSC3848.INSUFFICIENT_POWER` described in [MSC3848](https://github.com/matrix-org/matrix-spec-proposals/pull/3848). ([\#13343](https://github.com/matrix-org/synapse/issues/13343))
|
||||
- Use stable prefixes for [MSC3827](https://github.com/matrix-org/matrix-spec-proposals/pull/3827). ([\#13370](https://github.com/matrix-org/synapse/issues/13370))
|
||||
- Add a new module API method to translate a room alias into a room ID. ([\#13428](https://github.com/matrix-org/synapse/issues/13428))
|
||||
- Add a new module API method to create a room. ([\#13429](https://github.com/matrix-org/synapse/issues/13429))
|
||||
- Add remote join capability to the module API's `update_room_membership` method (in a backwards compatible manner). ([\#13441](https://github.com/matrix-org/synapse/issues/13441))
|
||||
|
||||
|
||||
Bugfixes
|
||||
--------
|
||||
|
||||
- Update the version of the LDAP3 auth provider module included in the `matrixdotorg/synapse` DockerHub images and the Debian packages hosted on packages.matrix.org to 0.2.2. This version fixes a regression in the module. ([\#13470](https://github.com/matrix-org/synapse/issues/13470))
|
||||
- Fix a bug introduced in Synapse v1.41.0 where the `/hierarchy` API returned non-standard information (a `room_id` field under each entry in `children_state`). ([\#13365](https://github.com/matrix-org/synapse/issues/13365))
|
||||
- Fix a bug introduced in Synapse 0.24.0 that would respond with the wrong error status code to `/joined_members` requests when the requester is not a current member of the room. Contributed by @andrewdoh. ([\#13374](https://github.com/matrix-org/synapse/issues/13374))
|
||||
- Fix bug in handling of typing events for appservices. Contributed by Nick @ Beeper (@fizzadar). ([\#13392](https://github.com/matrix-org/synapse/issues/13392))
|
||||
- Fix a bug introduced in Synapse 1.57.0 where rooms listed in `exclude_rooms_from_sync` in the configuration file would not be properly excluded from incremental syncs. ([\#13408](https://github.com/matrix-org/synapse/issues/13408))
|
||||
- Fix a bug in the experimental faster-room-joins support which could cause it to get stuck in an infinite loop. ([\#13353](https://github.com/matrix-org/synapse/issues/13353))
|
||||
- Faster room joins: fix a bug which caused rejected events to become un-rejected during state syncing. ([\#13413](https://github.com/matrix-org/synapse/issues/13413))
|
||||
- Faster room joins: fix error when running out of servers to sync partial state with, so that Synapse raises the intended error instead. ([\#13432](https://github.com/matrix-org/synapse/issues/13432))
|
||||
|
||||
|
||||
Updates to the Docker image
|
||||
---------------------------
|
||||
|
||||
- Make Docker images build on armv7 by installing cryptography dependencies in the 'requirements' stage. Contributed by Jasper Spaans. ([\#13372](https://github.com/matrix-org/synapse/issues/13372))
|
||||
|
||||
|
||||
Improved Documentation
|
||||
----------------------
|
||||
|
||||
- Update the 'registration tokens' page to acknowledge that the relevant MSC was merged into version 1.2 of the Matrix specification. Contributed by @moan0s. ([\#11897](https://github.com/matrix-org/synapse/issues/11897))
|
||||
- Document which HTTP resources support gzip compression. ([\#13221](https://github.com/matrix-org/synapse/issues/13221))
|
||||
- Add steps describing how to elevate an existing user to administrator by manipulating the database. ([\#13230](https://github.com/matrix-org/synapse/issues/13230))
|
||||
- Fix wrong headline for `url_preview_accept_language` in documentation. ([\#13437](https://github.com/matrix-org/synapse/issues/13437))
|
||||
- Remove redundant 'Contents' section from the Configuration Manual. Contributed by @dklimpel. ([\#13438](https://github.com/matrix-org/synapse/issues/13438))
|
||||
- Update documentation for config setting `macaroon_secret_key`. ([\#13443](https://github.com/matrix-org/synapse/issues/13443))
|
||||
- Update outdated information on `sso_mapping_providers` documentation. ([\#13449](https://github.com/matrix-org/synapse/issues/13449))
|
||||
- Fix example code in module documentation of `password_auth_provider_callbacks`. ([\#13450](https://github.com/matrix-org/synapse/issues/13450))
|
||||
- Make the configuration for the cache clearer. ([\#13481](https://github.com/matrix-org/synapse/issues/13481))
|
||||
|
||||
|
||||
Internal Changes
|
||||
----------------
|
||||
|
||||
- Extend the release script to automatically push a new SyTest branch, rather than having that be a manual process. ([\#12978](https://github.com/matrix-org/synapse/issues/12978))
|
||||
- Make minor clarifications to the error messages given when we fail to join a room via any server. ([\#13160](https://github.com/matrix-org/synapse/issues/13160))
|
||||
- Enable Complement CI tests in the 'latest deps' test run. ([\#13213](https://github.com/matrix-org/synapse/issues/13213))
|
||||
- Fix long-standing bugged logic which was never hit in `get_pdu` asking every remote destination even after it finds an event. ([\#13346](https://github.com/matrix-org/synapse/issues/13346))
|
||||
- Faster room joins: avoid blocking when pulling events with partially missing prev events. ([\#13355](https://github.com/matrix-org/synapse/issues/13355))
|
||||
- Instrument `/messages` for understandable traces in Jaeger. ([\#13368](https://github.com/matrix-org/synapse/issues/13368))
|
||||
- Remove an unused argument to `get_relations_for_event`. ([\#13383](https://github.com/matrix-org/synapse/issues/13383))
|
||||
- Add a `merge-back` command to the release script, which automates merging the correct branches after a release. ([\#13393](https://github.com/matrix-org/synapse/issues/13393))
|
||||
- Adding missing type hints to tests. ([\#13397](https://github.com/matrix-org/synapse/issues/13397))
|
||||
- Faster Room Joins: don't leave a stuck room partial state flag if the join fails. ([\#13403](https://github.com/matrix-org/synapse/issues/13403))
|
||||
- Refactor `_resolve_state_at_missing_prevs` to compute an `EventContext` instead. ([\#13404](https://github.com/matrix-org/synapse/issues/13404), [\#13431](https://github.com/matrix-org/synapse/issues/13431))
|
||||
- Faster Room Joins: prevent Synapse from answering federated join requests for a room which it has not fully joined yet. ([\#13416](https://github.com/matrix-org/synapse/issues/13416))
|
||||
- Re-enable running Complement tests against Synapse with workers. ([\#13420](https://github.com/matrix-org/synapse/issues/13420))
|
||||
- Prevent unnecessary lookups to any external `get_event` cache. Contributed by Nick @ Beeper (@fizzadar). ([\#13435](https://github.com/matrix-org/synapse/issues/13435))
|
||||
- Add some tracing to give more insight into local room joins. ([\#13439](https://github.com/matrix-org/synapse/issues/13439))
|
||||
- Rename class `RateLimitConfig` to `RatelimitSettings` and `FederationRateLimitConfig` to `FederationRatelimitSettings`. ([\#13442](https://github.com/matrix-org/synapse/issues/13442))
|
||||
- Add some comments about how event push actions are stored. ([\#13445](https://github.com/matrix-org/synapse/issues/13445), [\#13455](https://github.com/matrix-org/synapse/issues/13455))
|
||||
- Improve rebuild speed for the "synapse-workers" docker image. ([\#13447](https://github.com/matrix-org/synapse/issues/13447))
|
||||
- Fix `@tag_args` being off-by-one with the arguments when tagging a span (tracing). ([\#13452](https://github.com/matrix-org/synapse/issues/13452))
|
||||
- Update type of `EventContext.rejected`. ([\#13460](https://github.com/matrix-org/synapse/issues/13460))
|
||||
- Use literals in place of `HTTPStatus` constants in tests. ([\#13463](https://github.com/matrix-org/synapse/issues/13463), [\#13469](https://github.com/matrix-org/synapse/issues/13469))
|
||||
- Correct a misnamed argument in state res v2 internals. ([\#13467](https://github.com/matrix-org/synapse/issues/13467))
|
||||
|
||||
|
||||
Synapse 1.64.0 (2022-08-02)
|
||||
===========================
|
||||
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
Extend the release script to automatically push a new SyTest branch, rather than having that be a manual process.
|
|
@ -1 +0,0 @@
|
|||
Make minor clarifications to the error messages given when we fail to join a room via any server.
|
|
@ -1 +0,0 @@
|
|||
Enable Complement CI tests in the 'latest deps' test run.
|
|
@ -1 +0,0 @@
|
|||
Document which HTTP resources support gzip compression.
|
|
@ -1 +0,0 @@
|
|||
Add steps describing how to elevate an existing user to administrator by manipulating the database.
|
|
@ -1 +0,0 @@
|
|||
Add new unstable error codes `ORG.MATRIX.MSC3848.ALREADY_JOINED`, `ORG.MATRIX.MSC3848.NOT_JOINED`, and `ORG.MATRIX.MSC3848.INSUFFICIENT_POWER` described in MSC3848.
|
|
@ -1 +0,0 @@
|
|||
Fix long-standing bugged logic which was never hit in `get_pdu` asking every remote destination even after it finds an event.
|
|
@ -1 +0,0 @@
|
|||
Fix a bug in the experimental faster-room-joins support which could cause it to get stuck in an infinite loop.
|
|
@ -1 +0,0 @@
|
|||
Faster room joins: avoid blocking when pulling events with partially missing prev events.
|
|
@ -1 +0,0 @@
|
|||
Fix a bug introduced in Synapse v1.41.0 where the `/hierarchy` API returned non-standard information (a `room_id` field under each entry in `children_state`).
|
|
@ -1 +0,0 @@
|
|||
Instrument `/messages` for understandable traces in Jaeger.
|
|
@ -1 +0,0 @@
|
|||
Use stable prefixes for [MSC3827](https://github.com/matrix-org/matrix-spec-proposals/pull/3827).
|
|
@ -1 +0,0 @@
|
|||
Make docker images build on armv7 by installing cryptography dependencies in the "requirements" stage. Contributed by Jasper Spaans.
|
|
@ -1 +0,0 @@
|
|||
Fix a bug introduced in Synapse 0.24.0 that would respond with the wrong error status code to `/joined_members` requests when the requester is not a current member of the room. Contributed by @andrewdoh.
|
|
@ -1 +0,0 @@
|
|||
Remove an unused argument to `get_relations_for_event`.
|
|
@ -1 +0,0 @@
|
|||
Fix bug in handling of typing events for appservices. Contributed by Nick @ Beeper (@fizzadar).
|
|
@ -1 +0,0 @@
|
|||
Add a `merge-back` command to the release script, which automates merging the correct branches after a release.
|
|
@ -1 +0,0 @@
|
|||
Adding missing type hints to tests.
|
|
@ -1 +0,0 @@
|
|||
Faster Room Joins: don't leave a stuck room partial state flag if the join fails.
|
|
@ -1 +0,0 @@
|
|||
Refactor `_resolve_state_at_missing_prevs` to compute an `EventContext` instead.
|
|
@ -1 +0,0 @@
|
|||
Faster room joins: fix a bug which caused rejected events to become un-rejected during state syncing.
|
|
@ -1 +0,0 @@
|
|||
Re-enable running Complement tests against Synapse with workers.
|
|
@ -1 +0,0 @@
|
|||
Add a module API method to translate a room alias into a room ID.
|
|
@ -1 +0,0 @@
|
|||
Refactor `_resolve_state_at_missing_prevs` to compute an `EventContext` instead.
|
|
@ -1 +0,0 @@
|
|||
Faster room joins: Fix error when running out of servers to sync partial state with, so that Synapse raises the intended error instead.
|
|
@ -1 +0,0 @@
|
|||
Fix wrong headline for `url_preview_accept_language` in documentation.
|
|
@ -1 +0,0 @@
|
|||
Remove redundant 'Contents' section from the Configuration Manual. Contributed by @dklimpel.
|
|
@ -1 +0,0 @@
|
|||
Add some tracing to give more insight into local room joins.
|
|
@ -1 +0,0 @@
|
|||
Rename class `RateLimitConfig` to `RatelimitSettings` and `FederationRateLimitConfig` to `FederationRatelimitSettings`.
|
|
@ -1 +0,0 @@
|
|||
Update documentation for config setting `macaroon_secret_key`.
|
1
changelog.d/13453.misc
Normal file
1
changelog.d/13453.misc
Normal file
|
@ -0,0 +1 @@
|
|||
Allow use of both `@trace` and `@tag_args` stacked on the same function (tracing).
|
1
changelog.d/13471.misc
Normal file
1
changelog.d/13471.misc
Normal file
|
@ -0,0 +1 @@
|
|||
Clean-up tests for notifications.
|
1
changelog.d/13479.misc
Normal file
1
changelog.d/13479.misc
Normal file
|
@ -0,0 +1 @@
|
|||
Use literals in place of `HTTPStatus` constants in tests.
|
6
debian/changelog
vendored
6
debian/changelog
vendored
|
@ -1,3 +1,9 @@
|
|||
matrix-synapse-py3 (1.65.0~rc1) stable; urgency=medium
|
||||
|
||||
* New Synapse release 1.65.0rc1.
|
||||
|
||||
-- Synapse Packaging team <packages@matrix.org> Tue, 09 Aug 2022 11:39:29 +0100
|
||||
|
||||
matrix-synapse-py3 (1.64.0) stable; urgency=medium
|
||||
|
||||
* New Synapse release 1.64.0.
|
||||
|
|
|
@ -1,39 +1,62 @@
|
|||
# syntax=docker/dockerfile:1
|
||||
# Inherit from the official Synapse docker image
|
||||
|
||||
ARG SYNAPSE_VERSION=latest
|
||||
|
||||
# first of all, we create a base image with an nginx which we can copy into the
|
||||
# target image. For repeated rebuilds, this is much faster than apt installing
|
||||
# each time.
|
||||
|
||||
FROM debian:bullseye-slim AS deps_base
|
||||
RUN \
|
||||
--mount=type=cache,target=/var/cache/apt,sharing=locked \
|
||||
--mount=type=cache,target=/var/lib/apt,sharing=locked \
|
||||
apt-get update -qq && \
|
||||
DEBIAN_FRONTEND=noninteractive apt-get install -yqq --no-install-recommends \
|
||||
redis-server nginx-light
|
||||
|
||||
# Similarly, a base to copy the redis server from.
|
||||
#
|
||||
# The redis docker image has fewer dynamic libraries than the debian package,
|
||||
# which makes it much easier to copy (but we need to make sure we use an image
|
||||
# based on the same debian version as the synapse image, to make sure we get
|
||||
# the expected version of libc.
|
||||
FROM redis:6-bullseye AS redis_base
|
||||
|
||||
# now build the final image, based on the the regular Synapse docker image
|
||||
FROM matrixdotorg/synapse:$SYNAPSE_VERSION
|
||||
|
||||
# Install deps
|
||||
RUN \
|
||||
--mount=type=cache,target=/var/cache/apt,sharing=locked \
|
||||
--mount=type=cache,target=/var/lib/apt,sharing=locked \
|
||||
apt-get update -qq && \
|
||||
DEBIAN_FRONTEND=noninteractive apt-get install -yqq --no-install-recommends \
|
||||
redis-server nginx-light
|
||||
# Install supervisord with pip instead of apt, to avoid installing a second
|
||||
# copy of python.
|
||||
RUN --mount=type=cache,target=/root/.cache/pip \
|
||||
pip install supervisor~=4.2
|
||||
RUN mkdir -p /etc/supervisor/conf.d
|
||||
|
||||
# Install supervisord with pip instead of apt, to avoid installing a second
|
||||
# copy of python.
|
||||
RUN --mount=type=cache,target=/root/.cache/pip \
|
||||
pip install supervisor~=4.2
|
||||
# Copy over redis and nginx
|
||||
COPY --from=redis_base /usr/local/bin/redis-server /usr/local/bin
|
||||
|
||||
# Disable the default nginx sites
|
||||
RUN rm /etc/nginx/sites-enabled/default
|
||||
COPY --from=deps_base /usr/sbin/nginx /usr/sbin
|
||||
COPY --from=deps_base /usr/share/nginx /usr/share/nginx
|
||||
COPY --from=deps_base /usr/lib/nginx /usr/lib/nginx
|
||||
COPY --from=deps_base /etc/nginx /etc/nginx
|
||||
RUN rm /etc/nginx/sites-enabled/default
|
||||
RUN mkdir /var/log/nginx /var/lib/nginx
|
||||
RUN chown www-data /var/log/nginx /var/lib/nginx
|
||||
|
||||
# Copy Synapse worker, nginx and supervisord configuration template files
|
||||
COPY ./docker/conf-workers/* /conf/
|
||||
# Copy Synapse worker, nginx and supervisord configuration template files
|
||||
COPY ./docker/conf-workers/* /conf/
|
||||
|
||||
# Copy a script to prefix log lines with the supervisor program name
|
||||
COPY ./docker/prefix-log /usr/local/bin/
|
||||
# Copy a script to prefix log lines with the supervisor program name
|
||||
COPY ./docker/prefix-log /usr/local/bin/
|
||||
|
||||
# Expose nginx listener port
|
||||
EXPOSE 8080/tcp
|
||||
# Expose nginx listener port
|
||||
EXPOSE 8080/tcp
|
||||
|
||||
# A script to read environment variables and create the necessary
|
||||
# files to run the desired worker configuration. Will start supervisord.
|
||||
COPY ./docker/configure_workers_and_start.py /configure_workers_and_start.py
|
||||
ENTRYPOINT ["/configure_workers_and_start.py"]
|
||||
# A script to read environment variables and create the necessary
|
||||
# files to run the desired worker configuration. Will start supervisord.
|
||||
COPY ./docker/configure_workers_and_start.py /configure_workers_and_start.py
|
||||
ENTRYPOINT ["/configure_workers_and_start.py"]
|
||||
|
||||
# Replace the healthcheck with one which checks *all* the workers. The script
|
||||
# is generated by configure_workers_and_start.py.
|
||||
HEALTHCHECK --start-period=5s --interval=15s --timeout=5s \
|
||||
CMD /bin/sh /healthcheck.sh
|
||||
# Replace the healthcheck with one which checks *all* the workers. The script
|
||||
# is generated by configure_workers_and_start.py.
|
||||
HEALTHCHECK --start-period=5s --interval=15s --timeout=5s \
|
||||
CMD /bin/sh /healthcheck.sh
|
||||
|
|
|
@ -19,7 +19,7 @@ username=www-data
|
|||
autorestart=true
|
||||
|
||||
[program:redis]
|
||||
command=/usr/local/bin/prefix-log /usr/bin/redis-server /etc/redis/redis.conf --daemonize no
|
||||
command=/usr/local/bin/prefix-log /usr/local/bin/redis-server
|
||||
priority=1
|
||||
stdout_logfile=/dev/stdout
|
||||
stdout_logfile_maxbytes=0
|
||||
|
|
|
@ -263,7 +263,7 @@ class MyAuthProvider:
|
|||
return None
|
||||
|
||||
if self.credentials.get(username) == login_dict.get("my_field"):
|
||||
return self.api.get_qualified_user_id(username)
|
||||
return (self.api.get_qualified_user_id(username), None)
|
||||
|
||||
async def check_pass(
|
||||
self,
|
||||
|
@ -280,5 +280,5 @@ class MyAuthProvider:
|
|||
return None
|
||||
|
||||
if self.credentials.get(username) == login_dict.get("password"):
|
||||
return self.api.get_qualified_user_id(username)
|
||||
return (self.api.get_qualified_user_id(username), None)
|
||||
```
|
||||
|
|
|
@ -22,7 +22,7 @@ choose their own username.
|
|||
In the first case - where users are automatically allocated a Matrix ID - it is
|
||||
the responsibility of the mapping provider to normalise the SSO attributes and
|
||||
map them to a valid Matrix ID. The [specification for Matrix
|
||||
IDs](https://matrix.org/docs/spec/appendices#user-identifiers) has some
|
||||
IDs](https://spec.matrix.org/latest/appendices/#user-identifiers) has some
|
||||
information about what is considered valid.
|
||||
|
||||
If the mapping provider does not assign a Matrix ID, then Synapse will
|
||||
|
@ -37,9 +37,10 @@ as Synapse). The Synapse config is then modified to point to the mapping provide
|
|||
## OpenID Mapping Providers
|
||||
|
||||
The OpenID mapping provider can be customized by editing the
|
||||
`oidc_config.user_mapping_provider.module` config option.
|
||||
[`oidc_providers.user_mapping_provider.module`](usage/configuration/config_documentation.md#oidc_providers)
|
||||
config option.
|
||||
|
||||
`oidc_config.user_mapping_provider.config` allows you to provide custom
|
||||
`oidc_providers.user_mapping_provider.config` allows you to provide custom
|
||||
configuration options to the module. Check with the module's documentation for
|
||||
what options it provides (if any). The options listed by default are for the
|
||||
user mapping provider built in to Synapse. If using a custom module, you should
|
||||
|
@ -58,7 +59,7 @@ A custom mapping provider must specify the following methods:
|
|||
- This method should have the `@staticmethod` decoration.
|
||||
- Arguments:
|
||||
- `config` - A `dict` representing the parsed content of the
|
||||
`oidc_config.user_mapping_provider.config` homeserver config option.
|
||||
`oidc_providers.user_mapping_provider.config` homeserver config option.
|
||||
Runs on homeserver startup. Providers should extract and validate
|
||||
any option values they need here.
|
||||
- Whatever is returned will be passed back to the user mapping provider module's
|
||||
|
@ -102,7 +103,7 @@ A custom mapping provider must specify the following methods:
|
|||
will be returned as part of the response during a successful login.
|
||||
|
||||
Note that care should be taken to not overwrite any of the parameters
|
||||
usually returned as part of the [login response](https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-login).
|
||||
usually returned as part of the [login response](https://spec.matrix.org/latest/client-server-api/#post_matrixclientv3login).
|
||||
|
||||
### Default OpenID Mapping Provider
|
||||
|
||||
|
@ -113,7 +114,8 @@ specified in the config. It is located at
|
|||
## SAML Mapping Providers
|
||||
|
||||
The SAML mapping provider can be customized by editing the
|
||||
`saml2_config.user_mapping_provider.module` config option.
|
||||
[`saml2_config.user_mapping_provider.module`](docs/usage/configuration/config_documentation.md#saml2_config)
|
||||
config option.
|
||||
|
||||
`saml2_config.user_mapping_provider.config` allows you to provide custom
|
||||
configuration options to the module. Check with the module's documentation for
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
This API allows you to manage tokens which can be used to authenticate
|
||||
registration requests, as proposed in
|
||||
[MSC3231](https://github.com/matrix-org/matrix-doc/blob/main/proposals/3231-token-authenticated-registration.md).
|
||||
[MSC3231](https://github.com/matrix-org/matrix-doc/blob/main/proposals/3231-token-authenticated-registration.md)
|
||||
and stabilised in version 1.2 of the Matrix specification.
|
||||
To use it, you will need to enable the `registration_requires_token` config
|
||||
option, and authenticate by providing an `access_token` for a server admin:
|
||||
see [Admin API](../../usage/administration/admin_api).
|
||||
Note that this API is still experimental; not all clients may support it yet.
|
||||
see [Admin API](../admin_api).
|
||||
|
||||
|
||||
## Registration token objects
|
||||
|
|
|
@ -1057,26 +1057,26 @@ allow_device_name_lookup_over_federation: true
|
|||
---
|
||||
## Caching ##
|
||||
|
||||
Options related to caching
|
||||
Options related to caching.
|
||||
|
||||
---
|
||||
### `event_cache_size`
|
||||
|
||||
The number of events to cache in memory. Not affected by
|
||||
`caches.global_factor`. Defaults to 10K.
|
||||
`caches.global_factor` and is not part of the `caches` section. Defaults to 10K.
|
||||
|
||||
Example configuration:
|
||||
```yaml
|
||||
event_cache_size: 15K
|
||||
```
|
||||
---
|
||||
### `cache` and associated values
|
||||
### `caches` and associated values
|
||||
|
||||
A cache 'factor' is a multiplier that can be applied to each of
|
||||
Synapse's caches in order to increase or decrease the maximum
|
||||
number of entries that can be stored.
|
||||
|
||||
Caching can be configured through the following sub-options:
|
||||
`caches` can be configured through the following sub-options:
|
||||
|
||||
* `global_factor`: Controls the global cache factor, which is the default cache factor
|
||||
for all caches if a specific factor for that cache is not otherwise
|
||||
|
@ -1138,6 +1138,7 @@ Caching can be configured through the following sub-options:
|
|||
|
||||
Example configuration:
|
||||
```yaml
|
||||
event_cache_size: 15K
|
||||
caches:
|
||||
global_factor: 1.0
|
||||
per_cache_factors:
|
||||
|
|
6
poetry.lock
generated
6
poetry.lock
generated
|
@ -551,7 +551,7 @@ dev = ["twine (==4.0.1)", "build (==0.8.0)", "isort (==5.9.3)", "flake8 (==4.0.1
|
|||
|
||||
[[package]]
|
||||
name = "matrix-synapse-ldap3"
|
||||
version = "0.2.1"
|
||||
version = "0.2.2"
|
||||
description = "An LDAP3 auth provider for Synapse"
|
||||
category = "main"
|
||||
optional = true
|
||||
|
@ -2164,8 +2164,8 @@ matrix-common = [
|
|||
{file = "matrix_common-1.2.1.tar.gz", hash = "sha256:a99dcf02a6bd95b24a5a61b354888a2ac92bf2b4b839c727b8dd9da2cdfa3853"},
|
||||
]
|
||||
matrix-synapse-ldap3 = [
|
||||
{file = "matrix-synapse-ldap3-0.2.1.tar.gz", hash = "sha256:bfb4390f4a262ffb0d6f057ff3aeb1e46d4e52ff420a064d795fb4f555f00285"},
|
||||
{file = "matrix_synapse_ldap3-0.2.1-py3-none-any.whl", hash = "sha256:1b3310a60f1d06466f35905a269b6df95747fd1305f2b7fe638f373963b2aa2c"},
|
||||
{file = "matrix-synapse-ldap3-0.2.2.tar.gz", hash = "sha256:b388d95693486eef69adaefd0fd9e84463d52fe17b0214a00efcaa669b73cb74"},
|
||||
{file = "matrix_synapse_ldap3-0.2.2-py3-none-any.whl", hash = "sha256:66ee4c85d7952c6c27fd04c09cdfdf4847b8e8b7d6a7ada6ba1100013bda060f"},
|
||||
]
|
||||
mccabe = [
|
||||
{file = "mccabe-0.6.1-py2.py3-none-any.whl", hash = "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42"},
|
||||
|
|
|
@ -54,7 +54,7 @@ skip_gitignore = true
|
|||
|
||||
[tool.poetry]
|
||||
name = "matrix-synapse"
|
||||
version = "1.64.0"
|
||||
version = "1.65.0rc1"
|
||||
description = "Homeserver for the Matrix decentralised comms protocol"
|
||||
authors = ["Matrix.org Team and Contributors <packages@matrix.org>"]
|
||||
license = "Apache-2.0"
|
||||
|
|
|
@ -260,7 +260,8 @@ class GuestAccess:
|
|||
|
||||
class ReceiptTypes:
|
||||
READ: Final = "m.read"
|
||||
READ_PRIVATE: Final = "org.matrix.msc2285.read.private"
|
||||
READ_PRIVATE: Final = "m.read.private"
|
||||
UNSTABLE_READ_PRIVATE: Final = "org.matrix.msc2285.read.private"
|
||||
FULLY_READ: Final = "m.fully_read"
|
||||
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ class ExperimentalConfig(Config):
|
|||
# MSC2716 (importing historical messages)
|
||||
self.msc2716_enabled: bool = experimental.get("msc2716_enabled", False)
|
||||
|
||||
# MSC2285 (private read receipts)
|
||||
# MSC2285 (unstable private read receipts)
|
||||
self.msc2285_enabled: bool = experimental.get("msc2285_enabled", False)
|
||||
|
||||
# MSC3244 (room version capabilities)
|
||||
|
|
|
@ -11,11 +11,10 @@
|
|||
# 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 typing import TYPE_CHECKING, List, Optional, Tuple, Union
|
||||
from typing import TYPE_CHECKING, List, Optional, Tuple
|
||||
|
||||
import attr
|
||||
from frozendict import frozendict
|
||||
from typing_extensions import Literal
|
||||
|
||||
from synapse.appservice import ApplicationService
|
||||
from synapse.events import EventBase
|
||||
|
@ -33,7 +32,7 @@ class EventContext:
|
|||
Holds information relevant to persisting an event
|
||||
|
||||
Attributes:
|
||||
rejected: A rejection reason if the event was rejected, else False
|
||||
rejected: A rejection reason if the event was rejected, else None
|
||||
|
||||
_state_group: The ID of the state group for this event. Note that state events
|
||||
are persisted with a state group which includes the new event, so this is
|
||||
|
@ -85,7 +84,7 @@ class EventContext:
|
|||
"""
|
||||
|
||||
_storage: "StorageControllers"
|
||||
rejected: Union[Literal[False], str] = False
|
||||
rejected: Optional[str] = None
|
||||
_state_group: Optional[int] = None
|
||||
state_group_before_event: Optional[int] = None
|
||||
_state_delta_due_to_event: Optional[StateMap[str]] = None
|
||||
|
|
|
@ -843,8 +843,25 @@ class FederationServer(FederationBase):
|
|||
Codes.BAD_JSON,
|
||||
)
|
||||
|
||||
# Note that get_room_version throws if the room does not exist here.
|
||||
room_version = await self.store.get_room_version(room_id)
|
||||
|
||||
if await self.store.is_partial_state_room(room_id):
|
||||
# If our server is still only partially joined, we can't give a complete
|
||||
# response to /send_join, /send_knock or /send_leave.
|
||||
# This is because we will not be able to provide the server list (for partial
|
||||
# joins) or the full state (for full joins).
|
||||
# Return a 404 as we would if we weren't in the room at all.
|
||||
logger.info(
|
||||
f"Rejecting /send_{membership_type} to %s because it's a partial state room",
|
||||
room_id,
|
||||
)
|
||||
raise SynapseError(
|
||||
404,
|
||||
f"Unable to handle /send_{membership_type} right now; this server is not fully joined.",
|
||||
errcode=Codes.NOT_FOUND,
|
||||
)
|
||||
|
||||
if membership_type == Membership.KNOCK and not room_version.msc2403_knocking:
|
||||
raise SynapseError(
|
||||
403,
|
||||
|
|
|
@ -754,6 +754,23 @@ class FederationHandler:
|
|||
# (and return a 404 otherwise)
|
||||
room_version = await self.store.get_room_version(room_id)
|
||||
|
||||
if await self.store.is_partial_state_room(room_id):
|
||||
# If our server is still only partially joined, we can't give a complete
|
||||
# response to /make_join, so return a 404 as we would if we weren't in the
|
||||
# room at all.
|
||||
# The main reason we can't respond properly is that we need to know about
|
||||
# the auth events for the join event that we would return.
|
||||
# We also should not bother entertaining the /make_join since we cannot
|
||||
# handle the /send_join.
|
||||
logger.info(
|
||||
"Rejecting /make_join to %s because it's a partial state room", room_id
|
||||
)
|
||||
raise SynapseError(
|
||||
404,
|
||||
"Unable to handle /make_join right now; this server is not fully joined.",
|
||||
errcode=Codes.NOT_FOUND,
|
||||
)
|
||||
|
||||
# now check that we are *still* in the room
|
||||
is_in_room = await self._event_auth_handler.check_host_in_room(
|
||||
room_id, self.server_name
|
||||
|
|
|
@ -143,8 +143,8 @@ class InitialSyncHandler:
|
|||
joined_rooms,
|
||||
to_key=int(now_token.receipt_key),
|
||||
)
|
||||
if self.hs.config.experimental.msc2285_enabled:
|
||||
receipt = ReceiptEventSource.filter_out_private_receipts(receipt, user_id)
|
||||
|
||||
receipt = ReceiptEventSource.filter_out_private_receipts(receipt, user_id)
|
||||
|
||||
tags_by_room = await self.store.get_tags_for_user(user_id)
|
||||
|
||||
|
@ -456,11 +456,8 @@ class InitialSyncHandler:
|
|||
)
|
||||
if not receipts:
|
||||
return []
|
||||
if self.hs.config.experimental.msc2285_enabled:
|
||||
receipts = ReceiptEventSource.filter_out_private_receipts(
|
||||
receipts, user_id
|
||||
)
|
||||
return receipts
|
||||
|
||||
return ReceiptEventSource.filter_out_private_receipts(receipts, user_id)
|
||||
|
||||
presence, receipts, (messages, token) = await make_deferred_yieldable(
|
||||
gather_results(
|
||||
|
|
|
@ -163,7 +163,10 @@ class ReceiptsHandler:
|
|||
if not is_new:
|
||||
return
|
||||
|
||||
if self.federation_sender and receipt_type != ReceiptTypes.READ_PRIVATE:
|
||||
if self.federation_sender and receipt_type not in (
|
||||
ReceiptTypes.READ_PRIVATE,
|
||||
ReceiptTypes.UNSTABLE_READ_PRIVATE,
|
||||
):
|
||||
await self.federation_sender.send_read_receipt(receipt)
|
||||
|
||||
|
||||
|
@ -203,24 +206,38 @@ class ReceiptEventSource(EventSource[int, JsonDict]):
|
|||
for event_id, orig_event_content in room.get("content", {}).items():
|
||||
event_content = orig_event_content
|
||||
# If there are private read receipts, additional logic is necessary.
|
||||
if ReceiptTypes.READ_PRIVATE in event_content:
|
||||
if (
|
||||
ReceiptTypes.READ_PRIVATE in event_content
|
||||
or ReceiptTypes.UNSTABLE_READ_PRIVATE in event_content
|
||||
):
|
||||
# Make a copy without private read receipts to avoid leaking
|
||||
# other user's private read receipts..
|
||||
event_content = {
|
||||
receipt_type: receipt_value
|
||||
for receipt_type, receipt_value in event_content.items()
|
||||
if receipt_type != ReceiptTypes.READ_PRIVATE
|
||||
if receipt_type
|
||||
not in (
|
||||
ReceiptTypes.READ_PRIVATE,
|
||||
ReceiptTypes.UNSTABLE_READ_PRIVATE,
|
||||
)
|
||||
}
|
||||
|
||||
# Copy the current user's private read receipt from the
|
||||
# original content, if it exists.
|
||||
user_private_read_receipt = orig_event_content[
|
||||
ReceiptTypes.READ_PRIVATE
|
||||
].get(user_id, None)
|
||||
user_private_read_receipt = orig_event_content.get(
|
||||
ReceiptTypes.READ_PRIVATE, {}
|
||||
).get(user_id, None)
|
||||
if user_private_read_receipt:
|
||||
event_content[ReceiptTypes.READ_PRIVATE] = {
|
||||
user_id: user_private_read_receipt
|
||||
}
|
||||
user_unstable_private_read_receipt = orig_event_content.get(
|
||||
ReceiptTypes.UNSTABLE_READ_PRIVATE, {}
|
||||
).get(user_id, None)
|
||||
if user_unstable_private_read_receipt:
|
||||
event_content[ReceiptTypes.UNSTABLE_READ_PRIVATE] = {
|
||||
user_id: user_unstable_private_read_receipt
|
||||
}
|
||||
|
||||
# Include the event if there is at least one non-private read
|
||||
# receipt or the current user has a private read receipt.
|
||||
|
@ -256,10 +273,9 @@ class ReceiptEventSource(EventSource[int, JsonDict]):
|
|||
room_ids, from_key=from_key, to_key=to_key
|
||||
)
|
||||
|
||||
if self.config.experimental.msc2285_enabled:
|
||||
events = ReceiptEventSource.filter_out_private_receipts(
|
||||
events, user.to_string()
|
||||
)
|
||||
events = ReceiptEventSource.filter_out_private_receipts(
|
||||
events, user.to_string()
|
||||
)
|
||||
|
||||
return events, to_key
|
||||
|
||||
|
|
|
@ -1541,15 +1541,13 @@ class SyncHandler:
|
|||
ignored_users = await self.store.ignored_users(user_id)
|
||||
if since_token:
|
||||
room_changes = await self._get_rooms_changed(
|
||||
sync_result_builder, ignored_users, self.rooms_to_exclude
|
||||
sync_result_builder, ignored_users
|
||||
)
|
||||
tags_by_room = await self.store.get_updated_tags(
|
||||
user_id, since_token.account_data_key
|
||||
)
|
||||
else:
|
||||
room_changes = await self._get_all_rooms(
|
||||
sync_result_builder, ignored_users, self.rooms_to_exclude
|
||||
)
|
||||
room_changes = await self._get_all_rooms(sync_result_builder, ignored_users)
|
||||
tags_by_room = await self.store.get_tags_for_user(user_id)
|
||||
|
||||
log_kv({"rooms_changed": len(room_changes.room_entries)})
|
||||
|
@ -1628,13 +1626,14 @@ class SyncHandler:
|
|||
self,
|
||||
sync_result_builder: "SyncResultBuilder",
|
||||
ignored_users: FrozenSet[str],
|
||||
excluded_rooms: List[str],
|
||||
) -> _RoomChanges:
|
||||
"""Determine the changes in rooms to report to the user.
|
||||
|
||||
This function is a first pass at generating the rooms part of the sync response.
|
||||
It determines which rooms have changed during the sync period, and categorises
|
||||
them into four buckets: "knock", "invite", "join" and "leave".
|
||||
them into four buckets: "knock", "invite", "join" and "leave". It also excludes
|
||||
from that list any room that appears in the list of rooms to exclude from sync
|
||||
results in the server configuration.
|
||||
|
||||
1. Finds all membership changes for the user in the sync period (from
|
||||
`since_token` up to `now_token`).
|
||||
|
@ -1660,7 +1659,7 @@ class SyncHandler:
|
|||
# _have_rooms_changed. We could keep the results in memory to avoid a
|
||||
# second query, at the cost of more complicated source code.
|
||||
membership_change_events = await self.store.get_membership_changes_for_user(
|
||||
user_id, since_token.room_key, now_token.room_key, excluded_rooms
|
||||
user_id, since_token.room_key, now_token.room_key, self.rooms_to_exclude
|
||||
)
|
||||
|
||||
mem_change_events_by_room_id: Dict[str, List[EventBase]] = {}
|
||||
|
@ -1867,7 +1866,6 @@ class SyncHandler:
|
|||
self,
|
||||
sync_result_builder: "SyncResultBuilder",
|
||||
ignored_users: FrozenSet[str],
|
||||
ignored_rooms: List[str],
|
||||
) -> _RoomChanges:
|
||||
"""Returns entries for all rooms for the user.
|
||||
|
||||
|
@ -1889,7 +1887,7 @@ class SyncHandler:
|
|||
room_list = await self.store.get_rooms_for_local_user_where_membership_is(
|
||||
user_id=user_id,
|
||||
membership_list=Membership.LIST,
|
||||
excluded_rooms=ignored_rooms,
|
||||
excluded_rooms=self.rooms_to_exclude,
|
||||
)
|
||||
|
||||
room_entries = []
|
||||
|
@ -2155,7 +2153,9 @@ class SyncHandler:
|
|||
raise Exception("Unrecognized rtype: %r", room_builder.rtype)
|
||||
|
||||
async def get_rooms_for_user_at(
|
||||
self, user_id: str, room_key: RoomStreamToken
|
||||
self,
|
||||
user_id: str,
|
||||
room_key: RoomStreamToken,
|
||||
) -> FrozenSet[str]:
|
||||
"""Get set of joined rooms for a user at the given stream ordering.
|
||||
|
||||
|
@ -2181,7 +2181,12 @@ class SyncHandler:
|
|||
# If the membership's stream ordering is after the given stream
|
||||
# ordering, we need to go and work out if the user was in the room
|
||||
# before.
|
||||
# We also need to check whether the room should be excluded from sync
|
||||
# responses as per the homeserver config.
|
||||
for joined_room in joined_rooms:
|
||||
if joined_room.room_id in self.rooms_to_exclude:
|
||||
continue
|
||||
|
||||
if not joined_room.event_pos.persisted_after(room_key):
|
||||
joined_room_ids.add(joined_room.room_id)
|
||||
continue
|
||||
|
|
|
@ -789,67 +789,110 @@ def extract_text_map(
|
|||
# Tracing decorators
|
||||
|
||||
|
||||
def trace_with_opname(opname: str) -> Callable[[Callable[P, R]], Callable[P, R]]:
|
||||
def _custom_sync_async_decorator(
|
||||
func: Callable[P, R],
|
||||
wrapping_logic: Callable[[Callable[P, R], Any, Any], ContextManager[None]],
|
||||
) -> Callable[P, R]:
|
||||
"""
|
||||
Decorates a function that is sync or async (coroutines), or that returns a Twisted
|
||||
`Deferred`. The custom business logic of the decorator goes in `wrapping_logic`.
|
||||
|
||||
Example usage:
|
||||
```py
|
||||
# Decorator to time the function and log it out
|
||||
def duration(func: Callable[P, R]) -> Callable[P, R]:
|
||||
@contextlib.contextmanager
|
||||
def _wrapping_logic(func: Callable[P, R], *args: P.args, **kwargs: P.kwargs) -> Generator[None, None, None]:
|
||||
start_ts = time.time()
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
end_ts = time.time()
|
||||
duration = end_ts - start_ts
|
||||
logger.info("%s took %s seconds", func.__name__, duration)
|
||||
return _custom_sync_async_decorator(func, _wrapping_logic)
|
||||
```
|
||||
|
||||
Args:
|
||||
func: The function to be decorated
|
||||
wrapping_logic: The business logic of your custom decorator.
|
||||
This should be a ContextManager so you are able to run your logic
|
||||
before/after the function as desired.
|
||||
"""
|
||||
|
||||
if inspect.iscoroutinefunction(func):
|
||||
|
||||
@wraps(func)
|
||||
async def _wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
|
||||
with wrapping_logic(func, *args, **kwargs):
|
||||
return await func(*args, **kwargs) # type: ignore[misc]
|
||||
|
||||
else:
|
||||
# The other case here handles both sync functions and those
|
||||
# decorated with inlineDeferred.
|
||||
@wraps(func)
|
||||
def _wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
|
||||
scope = wrapping_logic(func, *args, **kwargs)
|
||||
scope.__enter__()
|
||||
|
||||
try:
|
||||
result = func(*args, **kwargs)
|
||||
if isinstance(result, defer.Deferred):
|
||||
|
||||
def call_back(result: R) -> R:
|
||||
scope.__exit__(None, None, None)
|
||||
return result
|
||||
|
||||
def err_back(result: R) -> R:
|
||||
scope.__exit__(None, None, None)
|
||||
return result
|
||||
|
||||
result.addCallbacks(call_back, err_back)
|
||||
|
||||
else:
|
||||
if inspect.isawaitable(result):
|
||||
logger.error(
|
||||
"@trace may not have wrapped %s correctly! "
|
||||
"The function is not async but returned a %s.",
|
||||
func.__qualname__,
|
||||
type(result).__name__,
|
||||
)
|
||||
|
||||
scope.__exit__(None, None, None)
|
||||
|
||||
return result
|
||||
|
||||
except Exception as e:
|
||||
scope.__exit__(type(e), None, e.__traceback__)
|
||||
raise
|
||||
|
||||
return _wrapper # type: ignore[return-value]
|
||||
|
||||
|
||||
def trace_with_opname(
|
||||
opname: str,
|
||||
*,
|
||||
tracer: Optional["opentelemetry.trace.Tracer"] = None,
|
||||
) -> Callable[[Callable[P, R]], Callable[P, R]]:
|
||||
"""
|
||||
Decorator to trace a function with a custom opname.
|
||||
|
||||
See the module's doc string for usage examples.
|
||||
|
||||
"""
|
||||
# type-ignore: mypy bug, see https://github.com/python/mypy/issues/12909
|
||||
@contextlib.contextmanager # type: ignore[arg-type]
|
||||
def _wrapping_logic(
|
||||
func: Callable[P, R], *args: P.args, **kwargs: P.kwargs
|
||||
) -> Generator[None, None, None]:
|
||||
with start_active_span(opname, tracer=tracer):
|
||||
yield
|
||||
|
||||
def decorator(func: Callable[P, R]) -> Callable[P, R]:
|
||||
if opentelemetry is None:
|
||||
return func # type: ignore[unreachable]
|
||||
def _decorator(func: Callable[P, R]) -> Callable[P, R]:
|
||||
if not opentelemetry:
|
||||
return func
|
||||
|
||||
if inspect.iscoroutinefunction(func):
|
||||
return _custom_sync_async_decorator(func, _wrapping_logic)
|
||||
|
||||
@wraps(func)
|
||||
async def _trace_inner(*args: P.args, **kwargs: P.kwargs) -> R:
|
||||
with start_active_span(opname):
|
||||
return await func(*args, **kwargs) # type: ignore[misc]
|
||||
|
||||
else:
|
||||
# The other case here handles both sync functions and those
|
||||
# decorated with inlineDeferred.
|
||||
@wraps(func)
|
||||
def _trace_inner(*args: P.args, **kwargs: P.kwargs) -> R:
|
||||
scope = start_active_span(opname)
|
||||
scope.__enter__()
|
||||
|
||||
try:
|
||||
result = func(*args, **kwargs)
|
||||
if isinstance(result, defer.Deferred):
|
||||
|
||||
def call_back(result: R) -> R:
|
||||
scope.__exit__(None, None, None)
|
||||
return result
|
||||
|
||||
def err_back(result: R) -> R:
|
||||
scope.__exit__(None, None, None)
|
||||
return result
|
||||
|
||||
result.addCallbacks(call_back, err_back)
|
||||
|
||||
else:
|
||||
if inspect.isawaitable(result):
|
||||
logger.error(
|
||||
"@trace may not have wrapped %s correctly! "
|
||||
"The function is not async but returned a %s.",
|
||||
func.__qualname__,
|
||||
type(result).__name__,
|
||||
)
|
||||
|
||||
scope.__exit__(None, None, None)
|
||||
|
||||
return result
|
||||
|
||||
except Exception as e:
|
||||
scope.__exit__(type(e), None, e.__traceback__)
|
||||
raise
|
||||
|
||||
return _trace_inner # type: ignore[return-value]
|
||||
|
||||
return decorator
|
||||
return _decorator
|
||||
|
||||
|
||||
def trace(func: Callable[P, R]) -> Callable[P, R]:
|
||||
|
@ -872,16 +915,25 @@ def tag_args(func: Callable[P, R]) -> Callable[P, R]:
|
|||
if not opentelemetry:
|
||||
return func
|
||||
|
||||
@wraps(func)
|
||||
def _tag_args_inner(*args: P.args, **kwargs: P.kwargs) -> R:
|
||||
# type-ignore: mypy bug, see https://github.com/python/mypy/issues/12909
|
||||
@contextlib.contextmanager # type: ignore[arg-type]
|
||||
def _wrapping_logic(
|
||||
func: Callable[P, R], *args: P.args, **kwargs: P.kwargs
|
||||
) -> Generator[None, None, None]:
|
||||
argspec = inspect.getfullargspec(func)
|
||||
for i, arg in enumerate(argspec.args[1:]):
|
||||
set_attribute("ARG_" + arg, str(args[i])) # type: ignore[index]
|
||||
# We use `[1:]` to skip the `self` object reference and `start=1` to
|
||||
# make the index line up with `argspec.args`.
|
||||
#
|
||||
# FIXME: We could update this to handle any type of function by ignoring the
|
||||
# first argument only if it's named `self` or `cls`. This isn't fool-proof
|
||||
# but handles the idiomatic cases.
|
||||
for i, arg in enumerate(args[1:], start=1): # type: ignore[index]
|
||||
set_attribute("ARG_" + argspec.args[i], str(arg))
|
||||
set_attribute("args", str(args[len(argspec.args) :])) # type: ignore[index]
|
||||
set_attribute("kwargs", str(kwargs))
|
||||
return func(*args, **kwargs)
|
||||
yield
|
||||
|
||||
return _tag_args_inner
|
||||
return _custom_sync_async_decorator(func, _wrapping_logic)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
|
|
|
@ -929,10 +929,12 @@ class ModuleApi:
|
|||
room_id: str,
|
||||
new_membership: str,
|
||||
content: Optional[JsonDict] = None,
|
||||
remote_room_hosts: Optional[List[str]] = None,
|
||||
) -> EventBase:
|
||||
"""Updates the membership of a user to the given value.
|
||||
|
||||
Added in Synapse v1.46.0.
|
||||
Changed in Synapse v1.65.0: Added the 'remote_room_hosts' parameter.
|
||||
|
||||
Args:
|
||||
sender: The user performing the membership change. Must be a user local to
|
||||
|
@ -946,6 +948,7 @@ class ModuleApi:
|
|||
https://spec.matrix.org/unstable/client-server-api/#mroommember for the
|
||||
list of allowed values.
|
||||
content: Additional values to include in the resulting event's content.
|
||||
remote_room_hosts: Remote servers to use for remote joins/knocks/etc.
|
||||
|
||||
Returns:
|
||||
The newly created membership event.
|
||||
|
@ -1005,15 +1008,12 @@ class ModuleApi:
|
|||
room_id=room_id,
|
||||
action=new_membership,
|
||||
content=content,
|
||||
remote_room_hosts=remote_room_hosts,
|
||||
)
|
||||
|
||||
# Try to retrieve the resulting event.
|
||||
event = await self._hs.get_datastores().main.get_event(event_id)
|
||||
|
||||
# update_membership is supposed to always return after the event has been
|
||||
# successfully persisted.
|
||||
assert event is not None
|
||||
|
||||
return event
|
||||
|
||||
async def create_and_send_event_into_room(self, event_dict: JsonDict) -> EventBase:
|
||||
|
@ -1476,6 +1476,57 @@ class ModuleApi:
|
|||
|
||||
return room_id.to_string(), hosts
|
||||
|
||||
async def create_room(
|
||||
self,
|
||||
user_id: str,
|
||||
config: JsonDict,
|
||||
ratelimit: bool = True,
|
||||
creator_join_profile: Optional[JsonDict] = None,
|
||||
) -> Tuple[str, Optional[str]]:
|
||||
"""Creates a new room.
|
||||
|
||||
Added in Synapse v1.65.0.
|
||||
|
||||
Args:
|
||||
user_id:
|
||||
The user who requested the room creation.
|
||||
config : A dict of configuration options. See "Request body" of:
|
||||
https://spec.matrix.org/latest/client-server-api/#post_matrixclientv3createroom
|
||||
ratelimit: set to False to disable the rate limiter for this specific operation.
|
||||
|
||||
creator_join_profile:
|
||||
Set to override the displayname and avatar for the creating
|
||||
user in this room. If unset, displayname and avatar will be
|
||||
derived from the user's profile. If set, should contain the
|
||||
values to go in the body of the 'join' event (typically
|
||||
`avatar_url` and/or `displayname`.
|
||||
|
||||
Returns:
|
||||
A tuple containing: 1) the room ID (str), 2) if an alias was requested,
|
||||
the room alias (str), otherwise None if no alias was requested.
|
||||
|
||||
Raises:
|
||||
ResourceLimitError if server is blocked to some resource being
|
||||
exceeded.
|
||||
RuntimeError if the user_id does not refer to a local user.
|
||||
SynapseError if the user_id is invalid, room ID couldn't be stored, or
|
||||
something went horribly wrong.
|
||||
"""
|
||||
if not self.is_mine(user_id):
|
||||
raise RuntimeError(
|
||||
"Tried to create a room as a user that isn't local to this homeserver",
|
||||
)
|
||||
|
||||
requester = create_requester(user_id)
|
||||
room_id_and_alias, _ = await self._hs.get_room_creation_handler().create_room(
|
||||
requester=requester,
|
||||
config=config,
|
||||
ratelimit=ratelimit,
|
||||
creator_join_profile=creator_join_profile,
|
||||
)
|
||||
|
||||
return room_id_and_alias["room_id"], room_id_and_alias.get("room_alias", None)
|
||||
|
||||
|
||||
class PublicRoomListManager:
|
||||
"""Contains methods for adding to, removing from and querying whether a room
|
||||
|
|
|
@ -416,7 +416,10 @@ class FederationSenderHandler:
|
|||
if not self._is_mine_id(receipt.user_id):
|
||||
continue
|
||||
# Private read receipts never get sent over federation.
|
||||
if receipt.receipt_type == ReceiptTypes.READ_PRIVATE:
|
||||
if receipt.receipt_type in (
|
||||
ReceiptTypes.READ_PRIVATE,
|
||||
ReceiptTypes.UNSTABLE_READ_PRIVATE,
|
||||
):
|
||||
continue
|
||||
receipt_info = ReadReceipt(
|
||||
receipt.room_id,
|
||||
|
|
|
@ -58,7 +58,12 @@ class NotificationsServlet(RestServlet):
|
|||
)
|
||||
|
||||
receipts_by_room = await self.store.get_receipts_for_user_with_orderings(
|
||||
user_id, [ReceiptTypes.READ, ReceiptTypes.READ_PRIVATE]
|
||||
user_id,
|
||||
[
|
||||
ReceiptTypes.READ,
|
||||
ReceiptTypes.READ_PRIVATE,
|
||||
ReceiptTypes.UNSTABLE_READ_PRIVATE,
|
||||
],
|
||||
)
|
||||
|
||||
notif_event_ids = [pa.event_id for pa in push_actions]
|
||||
|
|
|
@ -40,9 +40,13 @@ class ReadMarkerRestServlet(RestServlet):
|
|||
self.read_marker_handler = hs.get_read_marker_handler()
|
||||
self.presence_handler = hs.get_presence_handler()
|
||||
|
||||
self._known_receipt_types = {ReceiptTypes.READ, ReceiptTypes.FULLY_READ}
|
||||
self._known_receipt_types = {
|
||||
ReceiptTypes.READ,
|
||||
ReceiptTypes.FULLY_READ,
|
||||
ReceiptTypes.READ_PRIVATE,
|
||||
}
|
||||
if hs.config.experimental.msc2285_enabled:
|
||||
self._known_receipt_types.add(ReceiptTypes.READ_PRIVATE)
|
||||
self._known_receipt_types.add(ReceiptTypes.UNSTABLE_READ_PRIVATE)
|
||||
|
||||
async def on_POST(
|
||||
self, request: SynapseRequest, room_id: str
|
||||
|
|
|
@ -44,11 +44,13 @@ class ReceiptRestServlet(RestServlet):
|
|||
self.read_marker_handler = hs.get_read_marker_handler()
|
||||
self.presence_handler = hs.get_presence_handler()
|
||||
|
||||
self._known_receipt_types = {ReceiptTypes.READ}
|
||||
self._known_receipt_types = {
|
||||
ReceiptTypes.READ,
|
||||
ReceiptTypes.READ_PRIVATE,
|
||||
ReceiptTypes.FULLY_READ,
|
||||
}
|
||||
if hs.config.experimental.msc2285_enabled:
|
||||
self._known_receipt_types.update(
|
||||
(ReceiptTypes.READ_PRIVATE, ReceiptTypes.FULLY_READ)
|
||||
)
|
||||
self._known_receipt_types.add(ReceiptTypes.UNSTABLE_READ_PRIVATE)
|
||||
|
||||
async def on_POST(
|
||||
self, request: SynapseRequest, room_id: str, receipt_type: str, event_id: str
|
||||
|
|
|
@ -94,6 +94,7 @@ class VersionsRestServlet(RestServlet):
|
|||
# Supports the busy presence state described in MSC3026.
|
||||
"org.matrix.msc3026.busy_presence": self.config.experimental.msc3026_enabled,
|
||||
# Supports receiving private read receipts as per MSC2285
|
||||
"org.matrix.msc2285.stable": True, # TODO: Remove when MSC2285 becomes a part of the spec
|
||||
"org.matrix.msc2285": self.config.experimental.msc2285_enabled,
|
||||
# Supports filtering of /publicRooms by room type as per MSC3827
|
||||
"org.matrix.msc3827.stable": True,
|
||||
|
|
|
@ -434,7 +434,7 @@ async def _add_event_and_auth_chain_to_graph(
|
|||
event_id: str,
|
||||
event_map: Dict[str, EventBase],
|
||||
state_res_store: StateResolutionStore,
|
||||
auth_diff: Set[str],
|
||||
full_conflicted_set: Set[str],
|
||||
) -> None:
|
||||
"""Helper function for _reverse_topological_power_sort that add the event
|
||||
and its auth chain (that is in the auth diff) to the graph
|
||||
|
@ -445,7 +445,7 @@ async def _add_event_and_auth_chain_to_graph(
|
|||
event_id: Event to add to the graph
|
||||
event_map
|
||||
state_res_store
|
||||
auth_diff: Set of event IDs that are in the auth difference.
|
||||
full_conflicted_set: Set of event IDs that are in the full conflicted set.
|
||||
"""
|
||||
|
||||
state = [event_id]
|
||||
|
@ -455,7 +455,7 @@ async def _add_event_and_auth_chain_to_graph(
|
|||
|
||||
event = await _get_event(room_id, eid, event_map, state_res_store)
|
||||
for aid in event.auth_event_ids():
|
||||
if aid in auth_diff:
|
||||
if aid in full_conflicted_set:
|
||||
if aid not in graph:
|
||||
state.append(aid)
|
||||
|
||||
|
@ -468,7 +468,7 @@ async def _reverse_topological_power_sort(
|
|||
event_ids: Iterable[str],
|
||||
event_map: Dict[str, EventBase],
|
||||
state_res_store: StateResolutionStore,
|
||||
auth_diff: Set[str],
|
||||
full_conflicted_set: Set[str],
|
||||
) -> List[str]:
|
||||
"""Returns a list of the event_ids sorted by reverse topological ordering,
|
||||
and then by power level and origin_server_ts
|
||||
|
@ -479,7 +479,7 @@ async def _reverse_topological_power_sort(
|
|||
event_ids: The events to sort
|
||||
event_map
|
||||
state_res_store
|
||||
auth_diff: Set of event IDs that are in the auth difference.
|
||||
full_conflicted_set: Set of event IDs that are in the full conflicted set.
|
||||
|
||||
Returns:
|
||||
The sorted list
|
||||
|
@ -488,7 +488,7 @@ async def _reverse_topological_power_sort(
|
|||
graph: Dict[str, Set[str]] = {}
|
||||
for idx, event_id in enumerate(event_ids, start=1):
|
||||
await _add_event_and_auth_chain_to_graph(
|
||||
graph, room_id, event_id, event_map, state_res_store, auth_diff
|
||||
graph, room_id, event_id, event_map, state_res_store, full_conflicted_set
|
||||
)
|
||||
|
||||
# We await occasionally when we're working with large data sets to
|
||||
|
|
|
@ -12,6 +12,67 @@
|
|||
# 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.
|
||||
|
||||
"""Responsible for storing and fetching push actions / notifications.
|
||||
|
||||
There are two main uses for push actions:
|
||||
1. Sending out push to a user's device; and
|
||||
2. Tracking per-room per-user notification counts (used in sync requests).
|
||||
|
||||
For the former we simply use the `event_push_actions` table, which contains all
|
||||
the calculated actions for a given user (which were calculated by the
|
||||
`BulkPushRuleEvaluator`).
|
||||
|
||||
For the latter we could simply count the number of rows in `event_push_actions`
|
||||
table for a given room/user, but in practice this is *very* heavyweight when
|
||||
there were a large number of notifications (due to e.g. the user never reading a
|
||||
room). Plus, keeping all push actions indefinitely uses a lot of disk space.
|
||||
|
||||
To fix these issues, we add a new table `event_push_summary` that tracks
|
||||
per-user per-room counts of all notifications that happened before a stream
|
||||
ordering S. Thus, to get the notification count for a user / room we can simply
|
||||
query a single row in `event_push_summary` and count the number of rows in
|
||||
`event_push_actions` with a stream ordering larger than S (and as long as S is
|
||||
"recent", the number of rows needing to be scanned will be small).
|
||||
|
||||
The `event_push_summary` table is updated via a background job that periodically
|
||||
chooses a new stream ordering S' (usually the latest stream ordering), counts
|
||||
all notifications in `event_push_actions` between the existing S and S', and
|
||||
adds them to the existing counts in `event_push_summary`.
|
||||
|
||||
This allows us to delete old rows from `event_push_actions` once those rows have
|
||||
been counted and added to `event_push_summary` (we call this process
|
||||
"rotation").
|
||||
|
||||
|
||||
We need to handle when a user sends a read receipt to the room. Again this is
|
||||
done as a background process. For each receipt we clear the row in
|
||||
`event_push_summary` and count the number of notifications in
|
||||
`event_push_actions` that happened after the receipt but before S, and insert
|
||||
that count into `event_push_summary` (If the receipt happened *after* S then we
|
||||
simply clear the `event_push_summary`.)
|
||||
|
||||
Note that its possible that if the read receipt is for an old event the relevant
|
||||
`event_push_actions` rows will have been rotated and we get the wrong count
|
||||
(it'll be too low). We accept this as a rare edge case that is unlikely to
|
||||
impact the user much (since the vast majority of read receipts will be for the
|
||||
latest event).
|
||||
|
||||
The last complication is to handle the race where we request the notifications
|
||||
counts after a user sends a read receipt into the room, but *before* the
|
||||
background update handles the receipt (without any special handling the counts
|
||||
would be outdated). We fix this by including in `event_push_summary` the read
|
||||
receipt we used when updating `event_push_summary`, and every time we query the
|
||||
table we check if that matches the most recent read receipt in the room. If yes,
|
||||
continue as above, if not we simply query the `event_push_actions` table
|
||||
directly.
|
||||
|
||||
Since read receipts are almost always for recent events, scanning the
|
||||
`event_push_actions` table in this case is unlikely to be a problem. Even if it
|
||||
is a problem, it is temporary until the background job handles the new read
|
||||
receipt.
|
||||
"""
|
||||
|
||||
import logging
|
||||
from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, Union, cast
|
||||
|
||||
|
@ -19,7 +80,7 @@ import attr
|
|||
|
||||
from synapse.api.constants import ReceiptTypes
|
||||
from synapse.metrics.background_process_metrics import wrap_as_background_process
|
||||
from synapse.storage._base import SQLBaseStore, db_to_json
|
||||
from synapse.storage._base import SQLBaseStore, db_to_json, make_in_list_sql_clause
|
||||
from synapse.storage.database import (
|
||||
DatabasePool,
|
||||
LoggingDatabaseConnection,
|
||||
|
@ -198,7 +259,11 @@ class EventPushActionsWorkerStore(ReceiptsWorkerStore, StreamWorkerStore, SQLBas
|
|||
txn,
|
||||
user_id,
|
||||
room_id,
|
||||
receipt_types=(ReceiptTypes.READ, ReceiptTypes.READ_PRIVATE),
|
||||
receipt_types=(
|
||||
ReceiptTypes.READ,
|
||||
ReceiptTypes.READ_PRIVATE,
|
||||
ReceiptTypes.UNSTABLE_READ_PRIVATE,
|
||||
),
|
||||
)
|
||||
|
||||
stream_ordering = None
|
||||
|
@ -265,7 +330,7 @@ class EventPushActionsWorkerStore(ReceiptsWorkerStore, StreamWorkerStore, SQLBas
|
|||
counts.notify_count += row[1]
|
||||
counts.unread_count += row[2]
|
||||
|
||||
# Next we need to count highlights, which aren't summarized
|
||||
# Next we need to count highlights, which aren't summarised
|
||||
sql = """
|
||||
SELECT COUNT(*) FROM event_push_actions
|
||||
WHERE user_id = ?
|
||||
|
@ -280,7 +345,7 @@ class EventPushActionsWorkerStore(ReceiptsWorkerStore, StreamWorkerStore, SQLBas
|
|||
|
||||
# Finally we need to count push actions that aren't included in the
|
||||
# summary returned above, e.g. recent events that haven't been
|
||||
# summarized yet, or the summary is empty due to a recent read receipt.
|
||||
# summarised yet, or the summary is empty due to a recent read receipt.
|
||||
stream_ordering = max(stream_ordering, summary_stream_ordering)
|
||||
notify_count, unread_count = self._get_notif_unread_count_for_user_room(
|
||||
txn, room_id, user_id, stream_ordering
|
||||
|
@ -304,6 +369,17 @@ class EventPushActionsWorkerStore(ReceiptsWorkerStore, StreamWorkerStore, SQLBas
|
|||
|
||||
Does not consult `event_push_summary` table, which may include push
|
||||
actions that have been deleted from `event_push_actions` table.
|
||||
|
||||
Args:
|
||||
txn: The database transaction.
|
||||
room_id: The room ID to get unread counts for.
|
||||
user_id: The user ID to get unread counts for.
|
||||
stream_ordering: The (exclusive) minimum stream ordering to consider.
|
||||
max_stream_ordering: The (inclusive) maximum stream ordering to consider.
|
||||
If this is not given, then no maximum is applied.
|
||||
|
||||
Return:
|
||||
A tuple of the notif count and unread count in the given range.
|
||||
"""
|
||||
|
||||
# If there have been no events in the room since the stream ordering,
|
||||
|
@ -376,6 +452,7 @@ class EventPushActionsWorkerStore(ReceiptsWorkerStore, StreamWorkerStore, SQLBas
|
|||
The list will be ordered by ascending stream_ordering.
|
||||
The list will have between 0~limit entries.
|
||||
"""
|
||||
|
||||
# find rooms that have a read receipt in them and return the next
|
||||
# push actions
|
||||
def get_after_receipt(
|
||||
|
@ -383,28 +460,41 @@ class EventPushActionsWorkerStore(ReceiptsWorkerStore, StreamWorkerStore, SQLBas
|
|||
) -> List[Tuple[str, str, int, str, bool]]:
|
||||
# find rooms that have a read receipt in them and return the next
|
||||
# push actions
|
||||
sql = (
|
||||
"SELECT ep.event_id, ep.room_id, ep.stream_ordering, ep.actions,"
|
||||
" ep.highlight "
|
||||
" FROM ("
|
||||
" SELECT room_id,"
|
||||
" MAX(stream_ordering) as stream_ordering"
|
||||
" FROM events"
|
||||
" INNER JOIN receipts_linearized USING (room_id, event_id)"
|
||||
" WHERE receipt_type = 'm.read' AND user_id = ?"
|
||||
" GROUP BY room_id"
|
||||
") AS rl,"
|
||||
" event_push_actions AS ep"
|
||||
" WHERE"
|
||||
" ep.room_id = rl.room_id"
|
||||
" AND ep.stream_ordering > rl.stream_ordering"
|
||||
" AND ep.user_id = ?"
|
||||
" AND ep.stream_ordering > ?"
|
||||
" AND ep.stream_ordering <= ?"
|
||||
" AND ep.notif = 1"
|
||||
" ORDER BY ep.stream_ordering ASC LIMIT ?"
|
||||
|
||||
receipt_types_clause, args = make_in_list_sql_clause(
|
||||
self.database_engine,
|
||||
"receipt_type",
|
||||
(
|
||||
ReceiptTypes.READ,
|
||||
ReceiptTypes.READ_PRIVATE,
|
||||
ReceiptTypes.UNSTABLE_READ_PRIVATE,
|
||||
),
|
||||
)
|
||||
|
||||
sql = f"""
|
||||
SELECT ep.event_id, ep.room_id, ep.stream_ordering, ep.actions,
|
||||
ep.highlight
|
||||
FROM (
|
||||
SELECT room_id,
|
||||
MAX(stream_ordering) as stream_ordering
|
||||
FROM events
|
||||
INNER JOIN receipts_linearized USING (room_id, event_id)
|
||||
WHERE {receipt_types_clause} AND user_id = ?
|
||||
GROUP BY room_id
|
||||
) AS rl,
|
||||
event_push_actions AS ep
|
||||
WHERE
|
||||
ep.room_id = rl.room_id
|
||||
AND ep.stream_ordering > rl.stream_ordering
|
||||
AND ep.user_id = ?
|
||||
AND ep.stream_ordering > ?
|
||||
AND ep.stream_ordering <= ?
|
||||
AND ep.notif = 1
|
||||
ORDER BY ep.stream_ordering ASC LIMIT ?
|
||||
"""
|
||||
args.extend(
|
||||
(user_id, user_id, min_stream_ordering, max_stream_ordering, limit)
|
||||
)
|
||||
args = [user_id, user_id, min_stream_ordering, max_stream_ordering, limit]
|
||||
txn.execute(sql, args)
|
||||
return cast(List[Tuple[str, str, int, str, bool]], txn.fetchall())
|
||||
|
||||
|
@ -418,24 +508,36 @@ class EventPushActionsWorkerStore(ReceiptsWorkerStore, StreamWorkerStore, SQLBas
|
|||
def get_no_receipt(
|
||||
txn: LoggingTransaction,
|
||||
) -> List[Tuple[str, str, int, str, bool]]:
|
||||
sql = (
|
||||
"SELECT ep.event_id, ep.room_id, ep.stream_ordering, ep.actions,"
|
||||
" ep.highlight "
|
||||
" FROM event_push_actions AS ep"
|
||||
" INNER JOIN events AS e USING (room_id, event_id)"
|
||||
" WHERE"
|
||||
" ep.room_id NOT IN ("
|
||||
" SELECT room_id FROM receipts_linearized"
|
||||
" WHERE receipt_type = 'm.read' AND user_id = ?"
|
||||
" GROUP BY room_id"
|
||||
" )"
|
||||
" AND ep.user_id = ?"
|
||||
" AND ep.stream_ordering > ?"
|
||||
" AND ep.stream_ordering <= ?"
|
||||
" AND ep.notif = 1"
|
||||
" ORDER BY ep.stream_ordering ASC LIMIT ?"
|
||||
receipt_types_clause, args = make_in_list_sql_clause(
|
||||
self.database_engine,
|
||||
"receipt_type",
|
||||
(
|
||||
ReceiptTypes.READ,
|
||||
ReceiptTypes.READ_PRIVATE,
|
||||
ReceiptTypes.UNSTABLE_READ_PRIVATE,
|
||||
),
|
||||
)
|
||||
|
||||
sql = f"""
|
||||
SELECT ep.event_id, ep.room_id, ep.stream_ordering, ep.actions,
|
||||
ep.highlight
|
||||
FROM event_push_actions AS ep
|
||||
INNER JOIN events AS e USING (room_id, event_id)
|
||||
WHERE
|
||||
ep.room_id NOT IN (
|
||||
SELECT room_id FROM receipts_linearized
|
||||
WHERE {receipt_types_clause} AND user_id = ?
|
||||
GROUP BY room_id
|
||||
)
|
||||
AND ep.user_id = ?
|
||||
AND ep.stream_ordering > ?
|
||||
AND ep.stream_ordering <= ?
|
||||
AND ep.notif = 1
|
||||
ORDER BY ep.stream_ordering ASC LIMIT ?
|
||||
"""
|
||||
args.extend(
|
||||
(user_id, user_id, min_stream_ordering, max_stream_ordering, limit)
|
||||
)
|
||||
args = [user_id, user_id, min_stream_ordering, max_stream_ordering, limit]
|
||||
txn.execute(sql, args)
|
||||
return cast(List[Tuple[str, str, int, str, bool]], txn.fetchall())
|
||||
|
||||
|
@ -485,34 +587,47 @@ class EventPushActionsWorkerStore(ReceiptsWorkerStore, StreamWorkerStore, SQLBas
|
|||
The list will be ordered by descending received_ts.
|
||||
The list will have between 0~limit entries.
|
||||
"""
|
||||
|
||||
# find rooms that have a read receipt in them and return the most recent
|
||||
# push actions
|
||||
def get_after_receipt(
|
||||
txn: LoggingTransaction,
|
||||
) -> List[Tuple[str, str, int, str, bool, int]]:
|
||||
sql = (
|
||||
"SELECT ep.event_id, ep.room_id, ep.stream_ordering, ep.actions,"
|
||||
" ep.highlight, e.received_ts"
|
||||
" FROM ("
|
||||
" SELECT room_id,"
|
||||
" MAX(stream_ordering) as stream_ordering"
|
||||
" FROM events"
|
||||
" INNER JOIN receipts_linearized USING (room_id, event_id)"
|
||||
" WHERE receipt_type = 'm.read' AND user_id = ?"
|
||||
" GROUP BY room_id"
|
||||
") AS rl,"
|
||||
" event_push_actions AS ep"
|
||||
" INNER JOIN events AS e USING (room_id, event_id)"
|
||||
" WHERE"
|
||||
" ep.room_id = rl.room_id"
|
||||
" AND ep.stream_ordering > rl.stream_ordering"
|
||||
" AND ep.user_id = ?"
|
||||
" AND ep.stream_ordering > ?"
|
||||
" AND ep.stream_ordering <= ?"
|
||||
" AND ep.notif = 1"
|
||||
" ORDER BY ep.stream_ordering DESC LIMIT ?"
|
||||
receipt_types_clause, args = make_in_list_sql_clause(
|
||||
self.database_engine,
|
||||
"receipt_type",
|
||||
(
|
||||
ReceiptTypes.READ,
|
||||
ReceiptTypes.READ_PRIVATE,
|
||||
ReceiptTypes.UNSTABLE_READ_PRIVATE,
|
||||
),
|
||||
)
|
||||
|
||||
sql = f"""
|
||||
SELECT ep.event_id, ep.room_id, ep.stream_ordering, ep.actions,
|
||||
ep.highlight, e.received_ts
|
||||
FROM (
|
||||
SELECT room_id,
|
||||
MAX(stream_ordering) as stream_ordering
|
||||
FROM events
|
||||
INNER JOIN receipts_linearized USING (room_id, event_id)
|
||||
WHERE {receipt_types_clause} AND user_id = ?
|
||||
GROUP BY room_id
|
||||
) AS rl,
|
||||
event_push_actions AS ep
|
||||
INNER JOIN events AS e USING (room_id, event_id)
|
||||
WHERE
|
||||
ep.room_id = rl.room_id
|
||||
AND ep.stream_ordering > rl.stream_ordering
|
||||
AND ep.user_id = ?
|
||||
AND ep.stream_ordering > ?
|
||||
AND ep.stream_ordering <= ?
|
||||
AND ep.notif = 1
|
||||
ORDER BY ep.stream_ordering DESC LIMIT ?
|
||||
"""
|
||||
args.extend(
|
||||
(user_id, user_id, min_stream_ordering, max_stream_ordering, limit)
|
||||
)
|
||||
args = [user_id, user_id, min_stream_ordering, max_stream_ordering, limit]
|
||||
txn.execute(sql, args)
|
||||
return cast(List[Tuple[str, str, int, str, bool, int]], txn.fetchall())
|
||||
|
||||
|
@ -526,24 +641,36 @@ class EventPushActionsWorkerStore(ReceiptsWorkerStore, StreamWorkerStore, SQLBas
|
|||
def get_no_receipt(
|
||||
txn: LoggingTransaction,
|
||||
) -> List[Tuple[str, str, int, str, bool, int]]:
|
||||
sql = (
|
||||
"SELECT ep.event_id, ep.room_id, ep.stream_ordering, ep.actions,"
|
||||
" ep.highlight, e.received_ts"
|
||||
" FROM event_push_actions AS ep"
|
||||
" INNER JOIN events AS e USING (room_id, event_id)"
|
||||
" WHERE"
|
||||
" ep.room_id NOT IN ("
|
||||
" SELECT room_id FROM receipts_linearized"
|
||||
" WHERE receipt_type = 'm.read' AND user_id = ?"
|
||||
" GROUP BY room_id"
|
||||
" )"
|
||||
" AND ep.user_id = ?"
|
||||
" AND ep.stream_ordering > ?"
|
||||
" AND ep.stream_ordering <= ?"
|
||||
" AND ep.notif = 1"
|
||||
" ORDER BY ep.stream_ordering DESC LIMIT ?"
|
||||
receipt_types_clause, args = make_in_list_sql_clause(
|
||||
self.database_engine,
|
||||
"receipt_type",
|
||||
(
|
||||
ReceiptTypes.READ,
|
||||
ReceiptTypes.READ_PRIVATE,
|
||||
ReceiptTypes.UNSTABLE_READ_PRIVATE,
|
||||
),
|
||||
)
|
||||
|
||||
sql = f"""
|
||||
SELECT ep.event_id, ep.room_id, ep.stream_ordering, ep.actions,
|
||||
ep.highlight, e.received_ts
|
||||
FROM event_push_actions AS ep
|
||||
INNER JOIN events AS e USING (room_id, event_id)
|
||||
WHERE
|
||||
ep.room_id NOT IN (
|
||||
SELECT room_id FROM receipts_linearized
|
||||
WHERE {receipt_types_clause} AND user_id = ?
|
||||
GROUP BY room_id
|
||||
)
|
||||
AND ep.user_id = ?
|
||||
AND ep.stream_ordering > ?
|
||||
AND ep.stream_ordering <= ?
|
||||
AND ep.notif = 1
|
||||
ORDER BY ep.stream_ordering DESC LIMIT ?
|
||||
"""
|
||||
args.extend(
|
||||
(user_id, user_id, min_stream_ordering, max_stream_ordering, limit)
|
||||
)
|
||||
args = [user_id, user_id, min_stream_ordering, max_stream_ordering, limit]
|
||||
txn.execute(sql, args)
|
||||
return cast(List[Tuple[str, str, int, str, bool, int]], txn.fetchall())
|
||||
|
||||
|
@ -769,12 +896,12 @@ class EventPushActionsWorkerStore(ReceiptsWorkerStore, StreamWorkerStore, SQLBas
|
|||
# [10, <none>, 20], we should treat this as being equivalent to
|
||||
# [10, 10, 20].
|
||||
#
|
||||
sql = (
|
||||
"SELECT received_ts FROM events"
|
||||
" WHERE stream_ordering <= ?"
|
||||
" ORDER BY stream_ordering DESC"
|
||||
" LIMIT 1"
|
||||
)
|
||||
sql = """
|
||||
SELECT received_ts FROM events
|
||||
WHERE stream_ordering <= ?
|
||||
ORDER BY stream_ordering DESC
|
||||
LIMIT 1
|
||||
"""
|
||||
|
||||
while range_end - range_start > 0:
|
||||
middle = (range_end + range_start) // 2
|
||||
|
@ -802,14 +929,14 @@ class EventPushActionsWorkerStore(ReceiptsWorkerStore, StreamWorkerStore, SQLBas
|
|||
self, stream_ordering: int
|
||||
) -> Optional[int]:
|
||||
def f(txn: LoggingTransaction) -> Optional[Tuple[int]]:
|
||||
sql = (
|
||||
"SELECT e.received_ts"
|
||||
" FROM event_push_actions AS ep"
|
||||
" JOIN events e ON ep.room_id = e.room_id AND ep.event_id = e.event_id"
|
||||
" WHERE ep.stream_ordering > ? AND notif = 1"
|
||||
" ORDER BY ep.stream_ordering ASC"
|
||||
" LIMIT 1"
|
||||
)
|
||||
sql = """
|
||||
SELECT e.received_ts
|
||||
FROM event_push_actions AS ep
|
||||
JOIN events e ON ep.room_id = e.room_id AND ep.event_id = e.event_id
|
||||
WHERE ep.stream_ordering > ? AND notif = 1
|
||||
ORDER BY ep.stream_ordering ASC
|
||||
LIMIT 1
|
||||
"""
|
||||
txn.execute(sql, (stream_ordering,))
|
||||
return cast(Optional[Tuple[int]], txn.fetchone())
|
||||
|
||||
|
@ -858,10 +985,13 @@ class EventPushActionsWorkerStore(ReceiptsWorkerStore, StreamWorkerStore, SQLBas
|
|||
Any push actions which predate the user's most recent read receipt are
|
||||
now redundant, so we can remove them from `event_push_actions` and
|
||||
update `event_push_summary`.
|
||||
|
||||
Returns true if all new receipts have been processed.
|
||||
"""
|
||||
|
||||
limit = 100
|
||||
|
||||
# The (inclusive) receipt stream ID that was previously processed..
|
||||
min_receipts_stream_id = self.db_pool.simple_select_one_onecol_txn(
|
||||
txn,
|
||||
table="event_push_summary_last_receipt_stream_id",
|
||||
|
@ -871,6 +1001,14 @@ class EventPushActionsWorkerStore(ReceiptsWorkerStore, StreamWorkerStore, SQLBas
|
|||
|
||||
max_receipts_stream_id = self._receipts_id_gen.get_current_token()
|
||||
|
||||
# The (inclusive) event stream ordering that was previously summarised.
|
||||
old_rotate_stream_ordering = self.db_pool.simple_select_one_onecol_txn(
|
||||
txn,
|
||||
table="event_push_summary_stream_ordering",
|
||||
keyvalues={},
|
||||
retcol="stream_ordering",
|
||||
)
|
||||
|
||||
sql = """
|
||||
SELECT r.stream_id, r.room_id, r.user_id, e.stream_ordering
|
||||
FROM receipts_linearized AS r
|
||||
|
@ -895,13 +1033,6 @@ class EventPushActionsWorkerStore(ReceiptsWorkerStore, StreamWorkerStore, SQLBas
|
|||
)
|
||||
rows = txn.fetchall()
|
||||
|
||||
old_rotate_stream_ordering = self.db_pool.simple_select_one_onecol_txn(
|
||||
txn,
|
||||
table="event_push_summary_stream_ordering",
|
||||
keyvalues={},
|
||||
retcol="stream_ordering",
|
||||
)
|
||||
|
||||
# For each new read receipt we delete push actions from before it and
|
||||
# recalculate the summary.
|
||||
for _, room_id, user_id, stream_ordering in rows:
|
||||
|
@ -920,10 +1051,13 @@ class EventPushActionsWorkerStore(ReceiptsWorkerStore, StreamWorkerStore, SQLBas
|
|||
(room_id, user_id, stream_ordering),
|
||||
)
|
||||
|
||||
# Fetch the notification counts between the stream ordering of the
|
||||
# latest receipt and what was previously summarised.
|
||||
notif_count, unread_count = self._get_notif_unread_count_for_user_room(
|
||||
txn, room_id, user_id, stream_ordering, old_rotate_stream_ordering
|
||||
)
|
||||
|
||||
# Replace the previous summary with the new counts.
|
||||
self.db_pool.simple_upsert_txn(
|
||||
txn,
|
||||
table="event_push_summary",
|
||||
|
@ -956,10 +1090,12 @@ class EventPushActionsWorkerStore(ReceiptsWorkerStore, StreamWorkerStore, SQLBas
|
|||
return len(rows) < limit
|
||||
|
||||
def _rotate_notifs_txn(self, txn: LoggingTransaction) -> bool:
|
||||
"""Archives older notifications into event_push_summary. Returns whether
|
||||
the archiving process has caught up or not.
|
||||
"""Archives older notifications (from event_push_actions) into event_push_summary.
|
||||
|
||||
Returns whether the archiving process has caught up or not.
|
||||
"""
|
||||
|
||||
# The (inclusive) event stream ordering that was previously summarised.
|
||||
old_rotate_stream_ordering = self.db_pool.simple_select_one_onecol_txn(
|
||||
txn,
|
||||
table="event_push_summary_stream_ordering",
|
||||
|
@ -974,7 +1110,7 @@ class EventPushActionsWorkerStore(ReceiptsWorkerStore, StreamWorkerStore, SQLBas
|
|||
SELECT stream_ordering FROM event_push_actions
|
||||
WHERE stream_ordering > ?
|
||||
ORDER BY stream_ordering ASC LIMIT 1 OFFSET ?
|
||||
""",
|
||||
""",
|
||||
(old_rotate_stream_ordering, self._rotate_count),
|
||||
)
|
||||
stream_row = txn.fetchone()
|
||||
|
@ -993,19 +1129,31 @@ class EventPushActionsWorkerStore(ReceiptsWorkerStore, StreamWorkerStore, SQLBas
|
|||
|
||||
logger.info("Rotating notifications up to: %s", rotate_to_stream_ordering)
|
||||
|
||||
self._rotate_notifs_before_txn(txn, rotate_to_stream_ordering)
|
||||
self._rotate_notifs_before_txn(
|
||||
txn, old_rotate_stream_ordering, rotate_to_stream_ordering
|
||||
)
|
||||
|
||||
return caught_up
|
||||
|
||||
def _rotate_notifs_before_txn(
|
||||
self, txn: LoggingTransaction, rotate_to_stream_ordering: int
|
||||
self,
|
||||
txn: LoggingTransaction,
|
||||
old_rotate_stream_ordering: int,
|
||||
rotate_to_stream_ordering: int,
|
||||
) -> None:
|
||||
old_rotate_stream_ordering = self.db_pool.simple_select_one_onecol_txn(
|
||||
txn,
|
||||
table="event_push_summary_stream_ordering",
|
||||
keyvalues={},
|
||||
retcol="stream_ordering",
|
||||
)
|
||||
"""Archives older notifications (from event_push_actions) into event_push_summary.
|
||||
|
||||
Any event_push_actions between old_rotate_stream_ordering (exclusive) and
|
||||
rotate_to_stream_ordering (inclusive) will be added to the event_push_summary
|
||||
table.
|
||||
|
||||
Args:
|
||||
txn: The database transaction.
|
||||
old_rotate_stream_ordering: The previous maximum event stream ordering.
|
||||
rotate_to_stream_ordering: The new maximum event stream ordering to summarise.
|
||||
|
||||
Returns whether the archiving process has caught up or not.
|
||||
"""
|
||||
|
||||
# Calculate the new counts that should be upserted into event_push_summary
|
||||
sql = """
|
||||
|
@ -1093,9 +1241,9 @@ class EventPushActionsWorkerStore(ReceiptsWorkerStore, StreamWorkerStore, SQLBas
|
|||
async def _remove_old_push_actions_that_have_rotated(
|
||||
self,
|
||||
) -> None:
|
||||
"""Clear out old push actions that have been summarized."""
|
||||
"""Clear out old push actions that have been summarised."""
|
||||
|
||||
# We want to clear out anything that older than a day that *has* already
|
||||
# We want to clear out anything that is older than a day that *has* already
|
||||
# been rotated.
|
||||
rotated_upto_stream_ordering = await self.db_pool.simple_select_one_onecol(
|
||||
table="event_push_summary_stream_ordering",
|
||||
|
@ -1119,7 +1267,7 @@ class EventPushActionsWorkerStore(ReceiptsWorkerStore, StreamWorkerStore, SQLBas
|
|||
SELECT stream_ordering FROM event_push_actions
|
||||
WHERE stream_ordering <= ? AND highlight = 0
|
||||
ORDER BY stream_ordering ASC LIMIT 1 OFFSET ?
|
||||
""",
|
||||
""",
|
||||
(
|
||||
max_stream_ordering_to_delete,
|
||||
batch_size,
|
||||
|
@ -1215,16 +1363,18 @@ class EventPushActionsStore(EventPushActionsWorkerStore):
|
|||
|
||||
# NB. This assumes event_ids are globally unique since
|
||||
# it makes the query easier to index
|
||||
sql = (
|
||||
"SELECT epa.event_id, epa.room_id,"
|
||||
" epa.stream_ordering, epa.topological_ordering,"
|
||||
" epa.actions, epa.highlight, epa.profile_tag, e.received_ts"
|
||||
" FROM event_push_actions epa, events e"
|
||||
" WHERE epa.event_id = e.event_id"
|
||||
" AND epa.user_id = ? %s"
|
||||
" AND epa.notif = 1"
|
||||
" ORDER BY epa.stream_ordering DESC"
|
||||
" LIMIT ?" % (before_clause,)
|
||||
sql = """
|
||||
SELECT epa.event_id, epa.room_id,
|
||||
epa.stream_ordering, epa.topological_ordering,
|
||||
epa.actions, epa.highlight, epa.profile_tag, e.received_ts
|
||||
FROM event_push_actions epa, events e
|
||||
WHERE epa.event_id = e.event_id
|
||||
AND epa.user_id = ? %s
|
||||
AND epa.notif = 1
|
||||
ORDER BY epa.stream_ordering DESC
|
||||
LIMIT ?
|
||||
""" % (
|
||||
before_clause,
|
||||
)
|
||||
txn.execute(sql, args)
|
||||
return cast(
|
||||
|
|
|
@ -1490,7 +1490,7 @@ class PersistEventsStore:
|
|||
event.sender,
|
||||
"url" in event.content and isinstance(event.content["url"], str),
|
||||
event.get_state_key(),
|
||||
context.rejected or None,
|
||||
context.rejected,
|
||||
)
|
||||
for event, context in events_and_contexts
|
||||
),
|
||||
|
|
|
@ -600,7 +600,11 @@ class EventsWorkerStore(SQLBaseStore):
|
|||
Returns:
|
||||
map from event id to result
|
||||
"""
|
||||
event_entry_map = await self._get_events_from_cache(
|
||||
# Shortcut: check if we have any events in the *in memory* cache - this function
|
||||
# may be called repeatedly for the same event so at this point we cannot reach
|
||||
# out to any external cache for performance reasons. The external cache is
|
||||
# checked later on in the `get_missing_events_from_cache_or_db` function below.
|
||||
event_entry_map = self._get_events_from_local_cache(
|
||||
event_ids,
|
||||
)
|
||||
|
||||
|
@ -632,7 +636,9 @@ class EventsWorkerStore(SQLBaseStore):
|
|||
|
||||
if missing_events_ids:
|
||||
|
||||
async def get_missing_events_from_db() -> Dict[str, EventCacheEntry]:
|
||||
async def get_missing_events_from_cache_or_db() -> Dict[
|
||||
str, EventCacheEntry
|
||||
]:
|
||||
"""Fetches the events in `missing_event_ids` from the database.
|
||||
|
||||
Also creates entries in `self._current_event_fetches` to allow
|
||||
|
@ -657,10 +663,18 @@ class EventsWorkerStore(SQLBaseStore):
|
|||
# the events have been redacted, and if so pulling the redaction event
|
||||
# out of the database to check it.
|
||||
#
|
||||
missing_events = {}
|
||||
try:
|
||||
missing_events = await self._get_events_from_db(
|
||||
# Try to fetch from any external cache. We already checked the
|
||||
# in-memory cache above.
|
||||
missing_events = await self._get_events_from_external_cache(
|
||||
missing_events_ids,
|
||||
)
|
||||
# Now actually fetch any remaining events from the DB
|
||||
db_missing_events = await self._get_events_from_db(
|
||||
missing_events_ids - missing_events.keys(),
|
||||
)
|
||||
missing_events.update(db_missing_events)
|
||||
except Exception as e:
|
||||
with PreserveLoggingContext():
|
||||
fetching_deferred.errback(e)
|
||||
|
@ -679,7 +693,7 @@ class EventsWorkerStore(SQLBaseStore):
|
|||
# cancellations, since multiple `_get_events_from_cache_or_db` calls can
|
||||
# reuse the same fetch.
|
||||
missing_events: Dict[str, EventCacheEntry] = await delay_cancellation(
|
||||
get_missing_events_from_db()
|
||||
get_missing_events_from_cache_or_db()
|
||||
)
|
||||
event_entry_map.update(missing_events)
|
||||
|
||||
|
@ -754,7 +768,54 @@ class EventsWorkerStore(SQLBaseStore):
|
|||
async def _get_events_from_cache(
|
||||
self, events: Iterable[str], update_metrics: bool = True
|
||||
) -> Dict[str, EventCacheEntry]:
|
||||
"""Fetch events from the caches.
|
||||
"""Fetch events from the caches, both in memory and any external.
|
||||
|
||||
May return rejected events.
|
||||
|
||||
Args:
|
||||
events: list of event_ids to fetch
|
||||
update_metrics: Whether to update the cache hit ratio metrics
|
||||
"""
|
||||
event_map = self._get_events_from_local_cache(
|
||||
events, update_metrics=update_metrics
|
||||
)
|
||||
|
||||
missing_event_ids = (e for e in events if e not in event_map)
|
||||
event_map.update(
|
||||
await self._get_events_from_external_cache(
|
||||
events=missing_event_ids,
|
||||
update_metrics=update_metrics,
|
||||
)
|
||||
)
|
||||
|
||||
return event_map
|
||||
|
||||
async def _get_events_from_external_cache(
|
||||
self, events: Iterable[str], update_metrics: bool = True
|
||||
) -> Dict[str, EventCacheEntry]:
|
||||
"""Fetch events from any configured external cache.
|
||||
|
||||
May return rejected events.
|
||||
|
||||
Args:
|
||||
events: list of event_ids to fetch
|
||||
update_metrics: Whether to update the cache hit ratio metrics
|
||||
"""
|
||||
event_map = {}
|
||||
|
||||
for event_id in events:
|
||||
ret = await self._get_event_cache.get_external(
|
||||
(event_id,), None, update_metrics=update_metrics
|
||||
)
|
||||
if ret:
|
||||
event_map[event_id] = ret
|
||||
|
||||
return event_map
|
||||
|
||||
def _get_events_from_local_cache(
|
||||
self, events: Iterable[str], update_metrics: bool = True
|
||||
) -> Dict[str, EventCacheEntry]:
|
||||
"""Fetch events from the local, in memory, caches.
|
||||
|
||||
May return rejected events.
|
||||
|
||||
|
@ -766,7 +827,7 @@ class EventsWorkerStore(SQLBaseStore):
|
|||
|
||||
for event_id in events:
|
||||
# First check if it's in the event cache
|
||||
ret = await self._get_event_cache.get(
|
||||
ret = self._get_event_cache.get_local(
|
||||
(event_id,), None, update_metrics=update_metrics
|
||||
)
|
||||
if ret:
|
||||
|
@ -788,7 +849,7 @@ class EventsWorkerStore(SQLBaseStore):
|
|||
|
||||
# We add the entry back into the cache as we want to keep
|
||||
# recently queried events in the cache.
|
||||
await self._get_event_cache.set((event_id,), cache_entry)
|
||||
self._get_event_cache.set_local((event_id,), cache_entry)
|
||||
|
||||
return event_map
|
||||
|
||||
|
|
|
@ -896,7 +896,7 @@ class RoomMemberWorkerStore(EventsWorkerStore):
|
|||
# We don't update the event cache hit ratio as it completely throws off
|
||||
# the hit ratio counts. After all, we don't populate the cache if we
|
||||
# miss it here
|
||||
event_map = await self._get_events_from_cache(
|
||||
event_map = self._get_events_from_local_cache(
|
||||
member_event_ids, update_metrics=False
|
||||
)
|
||||
|
||||
|
|
|
@ -834,9 +834,26 @@ class AsyncLruCache(Generic[KT, VT]):
|
|||
) -> Optional[VT]:
|
||||
return self._lru_cache.get(key, update_metrics=update_metrics)
|
||||
|
||||
async def get_external(
|
||||
self,
|
||||
key: KT,
|
||||
default: Optional[T] = None,
|
||||
update_metrics: bool = True,
|
||||
) -> Optional[VT]:
|
||||
# This method should fetch from any configured external cache, in this case noop.
|
||||
return None
|
||||
|
||||
def get_local(
|
||||
self, key: KT, default: Optional[T] = None, update_metrics: bool = True
|
||||
) -> Optional[VT]:
|
||||
return self._lru_cache.get(key, update_metrics=update_metrics)
|
||||
|
||||
async def set(self, key: KT, value: VT) -> None:
|
||||
self._lru_cache.set(key, value)
|
||||
|
||||
def set_local(self, key: KT, value: VT) -> None:
|
||||
self._lru_cache.set(key, value)
|
||||
|
||||
async def invalidate(self, key: KT) -> None:
|
||||
# This method should invalidate any external cache and then invalidate the LruCache.
|
||||
return self._lru_cache.invalidate(key)
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from http import HTTPStatus
|
||||
from unittest.mock import Mock
|
||||
|
||||
from synapse.api.errors import Codes, SynapseError
|
||||
|
@ -51,7 +50,7 @@ class RoomComplexityTests(unittest.FederatingHomeserverTestCase):
|
|||
channel = self.make_signed_federation_request(
|
||||
"GET", "/_matrix/federation/unstable/rooms/%s/complexity" % (room_1,)
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code)
|
||||
self.assertEqual(200, channel.code)
|
||||
complexity = channel.json_body["v1"]
|
||||
self.assertTrue(complexity > 0, complexity)
|
||||
|
||||
|
@ -63,7 +62,7 @@ class RoomComplexityTests(unittest.FederatingHomeserverTestCase):
|
|||
channel = self.make_signed_federation_request(
|
||||
"GET", "/_matrix/federation/unstable/rooms/%s/complexity" % (room_1,)
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code)
|
||||
self.assertEqual(200, channel.code)
|
||||
complexity = channel.json_body["v1"]
|
||||
self.assertEqual(complexity, 1.23)
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
from collections import OrderedDict
|
||||
from http import HTTPStatus
|
||||
from typing import Dict, List
|
||||
|
||||
from synapse.api.constants import EventTypes, JoinRules, Membership
|
||||
|
@ -256,7 +255,7 @@ class FederationKnockingTestCase(
|
|||
RoomVersions.V7.identifier,
|
||||
),
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, channel.result)
|
||||
self.assertEqual(200, channel.code, channel.result)
|
||||
|
||||
# Note: We don't expect the knock membership event to be sent over federation as
|
||||
# part of the stripped room state, as the knocking homeserver already has that
|
||||
|
@ -294,7 +293,7 @@ class FederationKnockingTestCase(
|
|||
% (room_id, signed_knock_event.event_id),
|
||||
signed_knock_event_json,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, channel.result)
|
||||
self.assertEqual(200, channel.code, channel.result)
|
||||
|
||||
# Check that we got the stripped room state in return
|
||||
room_state_events = channel.json_body["knock_state_events"]
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
# 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 http import HTTPStatus
|
||||
from typing import Any, Dict
|
||||
|
||||
from twisted.test.proto_helpers import MemoryReactor
|
||||
|
@ -58,7 +57,7 @@ class DeactivateAccountTestCase(HomeserverTestCase):
|
|||
access_token=self.token,
|
||||
)
|
||||
|
||||
self.assertEqual(req.code, HTTPStatus.OK, req)
|
||||
self.assertEqual(req.code, 200, req)
|
||||
|
||||
def test_global_account_data_deleted_upon_deactivation(self) -> None:
|
||||
"""
|
||||
|
|
|
@ -314,4 +314,4 @@ class ServerAclValidationTestCase(unittest.HomeserverTestCase):
|
|||
channel = self.make_request(
|
||||
"POST", path, content={}, access_token=self.access_token
|
||||
)
|
||||
self.assertEqual(int(channel.result["code"]), 403)
|
||||
self.assertEqual(channel.code, 403)
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
from copy import deepcopy
|
||||
from typing import List
|
||||
|
||||
from parameterized import parameterized
|
||||
|
||||
from synapse.api.constants import EduTypes, ReceiptTypes
|
||||
from synapse.types import JsonDict
|
||||
|
||||
|
@ -25,13 +27,16 @@ class ReceiptsTestCase(unittest.HomeserverTestCase):
|
|||
def prepare(self, reactor, clock, hs):
|
||||
self.event_source = hs.get_event_sources().sources.receipt
|
||||
|
||||
def test_filters_out_private_receipt(self):
|
||||
@parameterized.expand(
|
||||
[ReceiptTypes.READ_PRIVATE, ReceiptTypes.UNSTABLE_READ_PRIVATE]
|
||||
)
|
||||
def test_filters_out_private_receipt(self, receipt_type: str) -> None:
|
||||
self._test_filters_private(
|
||||
[
|
||||
{
|
||||
"content": {
|
||||
"$1435641916114394fHBLK:matrix.org": {
|
||||
ReceiptTypes.READ_PRIVATE: {
|
||||
receipt_type: {
|
||||
"@rikj:jki.re": {
|
||||
"ts": 1436451550453,
|
||||
}
|
||||
|
@ -45,13 +50,18 @@ class ReceiptsTestCase(unittest.HomeserverTestCase):
|
|||
[],
|
||||
)
|
||||
|
||||
def test_filters_out_private_receipt_and_ignores_rest(self):
|
||||
@parameterized.expand(
|
||||
[ReceiptTypes.READ_PRIVATE, ReceiptTypes.UNSTABLE_READ_PRIVATE]
|
||||
)
|
||||
def test_filters_out_private_receipt_and_ignores_rest(
|
||||
self, receipt_type: str
|
||||
) -> None:
|
||||
self._test_filters_private(
|
||||
[
|
||||
{
|
||||
"content": {
|
||||
"$1dgdgrd5641916114394fHBLK:matrix.org": {
|
||||
ReceiptTypes.READ_PRIVATE: {
|
||||
receipt_type: {
|
||||
"@rikj:jki.re": {
|
||||
"ts": 1436451550453,
|
||||
},
|
||||
|
@ -84,13 +94,18 @@ class ReceiptsTestCase(unittest.HomeserverTestCase):
|
|||
],
|
||||
)
|
||||
|
||||
def test_filters_out_event_with_only_private_receipts_and_ignores_the_rest(self):
|
||||
@parameterized.expand(
|
||||
[ReceiptTypes.READ_PRIVATE, ReceiptTypes.UNSTABLE_READ_PRIVATE]
|
||||
)
|
||||
def test_filters_out_event_with_only_private_receipts_and_ignores_the_rest(
|
||||
self, receipt_type: str
|
||||
) -> None:
|
||||
self._test_filters_private(
|
||||
[
|
||||
{
|
||||
"content": {
|
||||
"$14356419edgd14394fHBLK:matrix.org": {
|
||||
ReceiptTypes.READ_PRIVATE: {
|
||||
receipt_type: {
|
||||
"@rikj:jki.re": {
|
||||
"ts": 1436451550453,
|
||||
},
|
||||
|
@ -125,7 +140,7 @@ class ReceiptsTestCase(unittest.HomeserverTestCase):
|
|||
],
|
||||
)
|
||||
|
||||
def test_handles_empty_event(self):
|
||||
def test_handles_empty_event(self) -> None:
|
||||
self._test_filters_private(
|
||||
[
|
||||
{
|
||||
|
@ -160,13 +175,18 @@ class ReceiptsTestCase(unittest.HomeserverTestCase):
|
|||
],
|
||||
)
|
||||
|
||||
def test_filters_out_receipt_event_with_only_private_receipt_and_ignores_rest(self):
|
||||
@parameterized.expand(
|
||||
[ReceiptTypes.READ_PRIVATE, ReceiptTypes.UNSTABLE_READ_PRIVATE]
|
||||
)
|
||||
def test_filters_out_receipt_event_with_only_private_receipt_and_ignores_rest(
|
||||
self, receipt_type: str
|
||||
) -> None:
|
||||
self._test_filters_private(
|
||||
[
|
||||
{
|
||||
"content": {
|
||||
"$14356419edgd14394fHBLK:matrix.org": {
|
||||
ReceiptTypes.READ_PRIVATE: {
|
||||
receipt_type: {
|
||||
"@rikj:jki.re": {
|
||||
"ts": 1436451550453,
|
||||
},
|
||||
|
@ -207,7 +227,7 @@ class ReceiptsTestCase(unittest.HomeserverTestCase):
|
|||
],
|
||||
)
|
||||
|
||||
def test_handles_string_data(self):
|
||||
def test_handles_string_data(self) -> None:
|
||||
"""
|
||||
Tests that an invalid shape for read-receipts is handled.
|
||||
Context: https://github.com/matrix-org/synapse/issues/10603
|
||||
|
@ -242,13 +262,16 @@ class ReceiptsTestCase(unittest.HomeserverTestCase):
|
|||
],
|
||||
)
|
||||
|
||||
def test_leaves_our_private_and_their_public(self):
|
||||
@parameterized.expand(
|
||||
[ReceiptTypes.READ_PRIVATE, ReceiptTypes.UNSTABLE_READ_PRIVATE]
|
||||
)
|
||||
def test_leaves_our_private_and_their_public(self, receipt_type: str) -> None:
|
||||
self._test_filters_private(
|
||||
[
|
||||
{
|
||||
"content": {
|
||||
"$1dgdgrd5641916114394fHBLK:matrix.org": {
|
||||
ReceiptTypes.READ_PRIVATE: {
|
||||
receipt_type: {
|
||||
"@me:server.org": {
|
||||
"ts": 1436451550453,
|
||||
},
|
||||
|
@ -273,7 +296,7 @@ class ReceiptsTestCase(unittest.HomeserverTestCase):
|
|||
{
|
||||
"content": {
|
||||
"$1dgdgrd5641916114394fHBLK:matrix.org": {
|
||||
ReceiptTypes.READ_PRIVATE: {
|
||||
receipt_type: {
|
||||
"@me:server.org": {
|
||||
"ts": 1436451550453,
|
||||
},
|
||||
|
@ -296,13 +319,16 @@ class ReceiptsTestCase(unittest.HomeserverTestCase):
|
|||
],
|
||||
)
|
||||
|
||||
def test_we_do_not_mutate(self):
|
||||
@parameterized.expand(
|
||||
[ReceiptTypes.READ_PRIVATE, ReceiptTypes.UNSTABLE_READ_PRIVATE]
|
||||
)
|
||||
def test_we_do_not_mutate(self, receipt_type: str) -> None:
|
||||
"""Ensure the input values are not modified."""
|
||||
events = [
|
||||
{
|
||||
"content": {
|
||||
"$1435641916114394fHBLK:matrix.org": {
|
||||
ReceiptTypes.READ_PRIVATE: {
|
||||
receipt_type: {
|
||||
"@rikj:jki.re": {
|
||||
"ts": 1436451550453,
|
||||
}
|
||||
|
@ -320,7 +346,7 @@ class ReceiptsTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
def _test_filters_private(
|
||||
self, events: List[JsonDict], expected_output: List[JsonDict]
|
||||
):
|
||||
) -> None:
|
||||
"""Tests that the _filter_out_private returns the expected output"""
|
||||
filtered_events = self.event_source.filter_out_private_receipts(
|
||||
events, "@me:server.org"
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
from http import HTTPStatus
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from twisted.test.proto_helpers import MemoryReactor
|
||||
|
@ -260,7 +259,7 @@ class TestReplicatedJoinsLimitedByPerRoomRateLimiter(RedisMultiWorkerStreamTestC
|
|||
f"/_matrix/client/v3/rooms/{self.room_id}/join",
|
||||
access_token=self.bob_token,
|
||||
)
|
||||
self.assertEqual(channel.code, HTTPStatus.OK, channel.json_body)
|
||||
self.assertEqual(channel.code, 200, channel.json_body)
|
||||
|
||||
# wait for join to arrive over replication
|
||||
self.replicate()
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
import inspect
|
||||
import itertools
|
||||
import logging
|
||||
from http import HTTPStatus
|
||||
from typing import (
|
||||
Any,
|
||||
Callable,
|
||||
|
@ -78,7 +77,7 @@ def test_disconnect(
|
|||
if expect_cancellation:
|
||||
expected_code = HTTP_STATUS_REQUEST_CANCELLED
|
||||
else:
|
||||
expected_code = HTTPStatus.OK
|
||||
expected_code = 200
|
||||
|
||||
request = channel.request
|
||||
if channel.is_finished():
|
||||
|
|
|
@ -16,7 +16,7 @@ from twisted.internet import defer
|
|||
from twisted.test.proto_helpers import MemoryReactorClock
|
||||
|
||||
from synapse.logging.context import make_deferred_yieldable, run_in_background
|
||||
from synapse.logging.tracing import start_active_span
|
||||
from synapse.logging.tracing import start_active_span, trace_with_opname, tag_args
|
||||
from synapse.util import Clock
|
||||
|
||||
from tests.unittest import TestCase
|
||||
|
@ -180,3 +180,75 @@ class TracingTestCase(TestCase):
|
|||
[span.name for span in self._exporter.get_finished_spans()],
|
||||
["task1", "task2", "root_span"],
|
||||
)
|
||||
|
||||
def test_trace_decorator_sync(self) -> None:
|
||||
"""
|
||||
Test whether we can use `@trace_with_opname` (`@trace`) and `@tag_args`
|
||||
with sync functions
|
||||
"""
|
||||
|
||||
@trace_with_opname("fixture_sync_func", tracer=self._tracer)
|
||||
@tag_args
|
||||
def fixture_sync_func() -> str:
|
||||
return "foo"
|
||||
|
||||
result = fixture_sync_func()
|
||||
self.assertEqual(result, "foo")
|
||||
|
||||
# the span should have been reported
|
||||
self.assertEqual(
|
||||
[span.name for span in self._exporter.get_finished_spans()],
|
||||
["fixture_sync_func"],
|
||||
)
|
||||
|
||||
def test_trace_decorator_deferred(self) -> None:
|
||||
"""
|
||||
Test whether we can use `@trace_with_opname` (`@trace`) and `@tag_args`
|
||||
with functions that return deferreds
|
||||
"""
|
||||
reactor = MemoryReactorClock()
|
||||
|
||||
@trace_with_opname("fixture_deferred_func", tracer=self._tracer)
|
||||
@tag_args
|
||||
def fixture_deferred_func() -> "defer.Deferred[str]":
|
||||
d1: defer.Deferred[str] = defer.Deferred()
|
||||
d1.callback("foo")
|
||||
return d1
|
||||
|
||||
result_d1 = fixture_deferred_func()
|
||||
|
||||
# let the tasks complete
|
||||
reactor.pump((2,) * 8)
|
||||
|
||||
self.assertEqual(self.successResultOf(result_d1), "foo")
|
||||
|
||||
# the span should have been reported
|
||||
self.assertEqual(
|
||||
[span.name for span in self._exporter.get_finished_spans()],
|
||||
["fixture_deferred_func"],
|
||||
)
|
||||
|
||||
def test_trace_decorator_async(self) -> None:
|
||||
"""
|
||||
Test whether we can use `@trace_with_opname` (`@trace`) and `@tag_args`
|
||||
with async functions
|
||||
"""
|
||||
reactor = MemoryReactorClock()
|
||||
|
||||
@trace_with_opname("fixture_async_func", tracer=self._tracer)
|
||||
@tag_args
|
||||
async def fixture_async_func() -> str:
|
||||
return "foo"
|
||||
|
||||
d1 = defer.ensureDeferred(fixture_async_func())
|
||||
|
||||
# let the tasks complete
|
||||
reactor.pump((2,) * 8)
|
||||
|
||||
self.assertEqual(self.successResultOf(d1), "foo")
|
||||
|
||||
# the span should have been reported
|
||||
self.assertEqual(
|
||||
[span.name for span in self._exporter.get_finished_spans()],
|
||||
["fixture_async_func"],
|
||||
)
|
||||
|
|
|
@ -16,6 +16,7 @@ from unittest.mock import Mock
|
|||
from twisted.internet import defer
|
||||
|
||||
from synapse.api.constants import EduTypes, EventTypes
|
||||
from synapse.api.errors import NotFoundError
|
||||
from synapse.events import EventBase
|
||||
from synapse.federation.units import Transaction
|
||||
from synapse.handlers.presence import UserPresenceState
|
||||
|
@ -532,6 +533,34 @@ class ModuleApiTestCase(HomeserverTestCase):
|
|||
self.assertEqual(res["displayname"], "simone")
|
||||
self.assertIsNone(res["avatar_url"])
|
||||
|
||||
def test_update_room_membership_remote_join(self):
|
||||
"""Test that the module API can join a remote room."""
|
||||
# Necessary to fake a remote join.
|
||||
fake_stream_id = 1
|
||||
mocked_remote_join = simple_async_mock(
|
||||
return_value=("fake-event-id", fake_stream_id)
|
||||
)
|
||||
self.hs.get_room_member_handler()._remote_join = mocked_remote_join
|
||||
fake_remote_host = f"{self.module_api.server_name}-remote"
|
||||
|
||||
# Given that the join is to be faked, we expect the relevant join event not to
|
||||
# be persisted and the module API method to raise that.
|
||||
self.get_failure(
|
||||
defer.ensureDeferred(
|
||||
self.module_api.update_room_membership(
|
||||
sender=f"@user:{self.module_api.server_name}",
|
||||
target=f"@user:{self.module_api.server_name}",
|
||||
room_id=f"!nonexistent:{fake_remote_host}",
|
||||
new_membership="join",
|
||||
remote_room_hosts=[fake_remote_host],
|
||||
)
|
||||
),
|
||||
NotFoundError,
|
||||
)
|
||||
|
||||
# Check that a remote join was attempted.
|
||||
self.assertEqual(mocked_remote_join.call_count, 1)
|
||||
|
||||
def test_get_room_state(self):
|
||||
"""Tests that a module can retrieve the state of a room through the module API."""
|
||||
user_id = self.register_user("peter", "hackme")
|
||||
|
@ -654,6 +683,57 @@ class ModuleApiTestCase(HomeserverTestCase):
|
|||
|
||||
self.assertEqual(room_id, reference_room_id)
|
||||
|
||||
def test_create_room(self) -> None:
|
||||
"""Test that modules can create a room."""
|
||||
# First test user validation (i.e. user is local).
|
||||
self.get_failure(
|
||||
self.module_api.create_room(
|
||||
user_id=f"@user:{self.module_api.server_name}abc",
|
||||
config={},
|
||||
ratelimit=False,
|
||||
),
|
||||
RuntimeError,
|
||||
)
|
||||
|
||||
# Now do the happy path.
|
||||
user_id = self.register_user("user", "password")
|
||||
access_token = self.login(user_id, "password")
|
||||
|
||||
room_id, room_alias = self.get_success(
|
||||
self.module_api.create_room(
|
||||
user_id=user_id, config={"room_alias_name": "foo-bar"}, ratelimit=False
|
||||
)
|
||||
)
|
||||
|
||||
# Check room creator.
|
||||
channel = self.make_request(
|
||||
"GET",
|
||||
f"/_matrix/client/v3/rooms/{room_id}/state/m.room.create",
|
||||
access_token=access_token,
|
||||
)
|
||||
self.assertEqual(channel.code, 200, channel.result)
|
||||
self.assertEqual(channel.json_body["creator"], user_id)
|
||||
|
||||
# Check room alias.
|
||||
self.assertEquals(room_alias, f"#foo-bar:{self.module_api.server_name}")
|
||||
|
||||
# Let's try a room with no alias.
|
||||
room_id, room_alias = self.get_success(
|
||||
self.module_api.create_room(user_id=user_id, config={}, ratelimit=False)
|
||||
)
|
||||
|
||||
# Check room creator.
|
||||
channel = self.make_request(
|
||||
"GET",
|
||||
f"/_matrix/client/v3/rooms/{room_id}/state/m.room.create",
|
||||
access_token=access_token,
|
||||
)
|
||||
self.assertEqual(channel.code, 200, channel.result)
|
||||
self.assertEqual(channel.json_body["creator"], user_id)
|
||||
|
||||
# Check room alias.
|
||||
self.assertIsNone(room_alias)
|
||||
|
||||
|
||||
class ModuleApiWorkerTestCase(BaseMultiWorkerStreamTestCase):
|
||||
"""For testing ModuleApi functionality in a multi-worker setup"""
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
# limitations under the License.
|
||||
|
||||
import urllib.parse
|
||||
from http import HTTPStatus
|
||||
|
||||
from parameterized import parameterized
|
||||
|
||||
|
@ -42,7 +41,7 @@ class VersionTestCase(unittest.HomeserverTestCase):
|
|||
def test_version_string(self) -> None:
|
||||
channel = self.make_request("GET", self.url, shorthand=False)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(
|
||||
{"server_version", "python_version"}, set(channel.json_body.keys())
|
||||
)
|
||||
|
@ -79,10 +78,10 @@ class QuarantineMediaTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
# Should be quarantined
|
||||
self.assertEqual(
|
||||
HTTPStatus.NOT_FOUND,
|
||||
404,
|
||||
channel.code,
|
||||
msg=(
|
||||
"Expected to receive a HTTPStatus.NOT_FOUND on accessing quarantined media: %s"
|
||||
"Expected to receive a 404 on accessing quarantined media: %s"
|
||||
% server_and_media_id
|
||||
),
|
||||
)
|
||||
|
@ -107,7 +106,7 @@ class QuarantineMediaTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
# Expect a forbidden error
|
||||
self.assertEqual(
|
||||
HTTPStatus.FORBIDDEN,
|
||||
403,
|
||||
channel.code,
|
||||
msg="Expected forbidden on quarantining media as a non-admin",
|
||||
)
|
||||
|
@ -139,7 +138,7 @@ class QuarantineMediaTestCase(unittest.HomeserverTestCase):
|
|||
)
|
||||
|
||||
# Should be successful
|
||||
self.assertEqual(HTTPStatus.OK, channel.code)
|
||||
self.assertEqual(200, channel.code)
|
||||
|
||||
# Quarantine the media
|
||||
url = "/_synapse/admin/v1/media/quarantine/%s/%s" % (
|
||||
|
@ -152,7 +151,7 @@ class QuarantineMediaTestCase(unittest.HomeserverTestCase):
|
|||
access_token=admin_user_tok,
|
||||
)
|
||||
self.pump(1.0)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
# Attempt to access the media
|
||||
self._ensure_quarantined(admin_user_tok, server_name_and_media_id)
|
||||
|
@ -209,7 +208,7 @@ class QuarantineMediaTestCase(unittest.HomeserverTestCase):
|
|||
access_token=admin_user_tok,
|
||||
)
|
||||
self.pump(1.0)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(
|
||||
channel.json_body, {"num_quarantined": 2}, "Expected 2 quarantined items"
|
||||
)
|
||||
|
@ -251,7 +250,7 @@ class QuarantineMediaTestCase(unittest.HomeserverTestCase):
|
|||
access_token=admin_user_tok,
|
||||
)
|
||||
self.pump(1.0)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(
|
||||
channel.json_body, {"num_quarantined": 2}, "Expected 2 quarantined items"
|
||||
)
|
||||
|
@ -285,7 +284,7 @@ class QuarantineMediaTestCase(unittest.HomeserverTestCase):
|
|||
url = "/_synapse/admin/v1/media/protect/%s" % (urllib.parse.quote(media_id_2),)
|
||||
channel = self.make_request("POST", url, access_token=admin_user_tok)
|
||||
self.pump(1.0)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
# Quarantine all media by this user
|
||||
url = "/_synapse/admin/v1/user/%s/media/quarantine" % urllib.parse.quote(
|
||||
|
@ -297,7 +296,7 @@ class QuarantineMediaTestCase(unittest.HomeserverTestCase):
|
|||
access_token=admin_user_tok,
|
||||
)
|
||||
self.pump(1.0)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(
|
||||
channel.json_body, {"num_quarantined": 1}, "Expected 1 quarantined item"
|
||||
)
|
||||
|
@ -318,10 +317,10 @@ class QuarantineMediaTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
# Shouldn't be quarantined
|
||||
self.assertEqual(
|
||||
HTTPStatus.OK,
|
||||
200,
|
||||
channel.code,
|
||||
msg=(
|
||||
"Expected to receive a HTTPStatus.OK on accessing not-quarantined media: %s"
|
||||
"Expected to receive a 200 on accessing not-quarantined media: %s"
|
||||
% server_and_media_id_2
|
||||
),
|
||||
)
|
||||
|
@ -350,7 +349,7 @@ class PurgeHistoryTestCase(unittest.HomeserverTestCase):
|
|||
def test_purge_history(self) -> None:
|
||||
"""
|
||||
Simple test of purge history API.
|
||||
Test only that is is possible to call, get status HTTPStatus.OK and purge_id.
|
||||
Test only that is is possible to call, get status 200 and purge_id.
|
||||
"""
|
||||
|
||||
channel = self.make_request(
|
||||
|
@ -360,7 +359,7 @@ class PurgeHistoryTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertIn("purge_id", channel.json_body)
|
||||
purge_id = channel.json_body["purge_id"]
|
||||
|
||||
|
@ -371,5 +370,5 @@ class PurgeHistoryTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual("complete", channel.json_body["status"])
|
||||
|
|
|
@ -51,7 +51,7 @@ class BackgroundUpdatesTestCase(unittest.HomeserverTestCase):
|
|||
)
|
||||
def test_requester_is_no_admin(self, method: str, url: str) -> None:
|
||||
"""
|
||||
If the user is not a server admin, an error HTTPStatus.FORBIDDEN is returned.
|
||||
If the user is not a server admin, an error 403 is returned.
|
||||
"""
|
||||
|
||||
self.register_user("user", "pass", admin=False)
|
||||
|
@ -64,7 +64,7 @@ class BackgroundUpdatesTestCase(unittest.HomeserverTestCase):
|
|||
access_token=other_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.FORBIDDEN, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(403, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
||||
|
||||
def test_invalid_parameter(self) -> None:
|
||||
|
@ -125,7 +125,7 @@ class BackgroundUpdatesTestCase(unittest.HomeserverTestCase):
|
|||
"/_synapse/admin/v1/background_updates/status",
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
# Background updates should be enabled, but none should be running.
|
||||
self.assertDictEqual(
|
||||
|
@ -147,7 +147,7 @@ class BackgroundUpdatesTestCase(unittest.HomeserverTestCase):
|
|||
"/_synapse/admin/v1/background_updates/status",
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
# Background updates should be enabled, and one should be running.
|
||||
self.assertDictEqual(
|
||||
|
@ -181,7 +181,7 @@ class BackgroundUpdatesTestCase(unittest.HomeserverTestCase):
|
|||
"/_synapse/admin/v1/background_updates/enabled",
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertDictEqual(channel.json_body, {"enabled": True})
|
||||
|
||||
# Disable the BG updates
|
||||
|
@ -191,7 +191,7 @@ class BackgroundUpdatesTestCase(unittest.HomeserverTestCase):
|
|||
content={"enabled": False},
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertDictEqual(channel.json_body, {"enabled": False})
|
||||
|
||||
# Advance a bit and get the current status, note this will finish the in
|
||||
|
@ -204,7 +204,7 @@ class BackgroundUpdatesTestCase(unittest.HomeserverTestCase):
|
|||
"/_synapse/admin/v1/background_updates/status",
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertDictEqual(
|
||||
channel.json_body,
|
||||
{
|
||||
|
@ -231,7 +231,7 @@ class BackgroundUpdatesTestCase(unittest.HomeserverTestCase):
|
|||
"/_synapse/admin/v1/background_updates/status",
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
# There should be no change from the previous /status response.
|
||||
self.assertDictEqual(
|
||||
|
@ -259,7 +259,7 @@ class BackgroundUpdatesTestCase(unittest.HomeserverTestCase):
|
|||
content={"enabled": True},
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
self.assertDictEqual(channel.json_body, {"enabled": True})
|
||||
|
||||
|
@ -270,7 +270,7 @@ class BackgroundUpdatesTestCase(unittest.HomeserverTestCase):
|
|||
"/_synapse/admin/v1/background_updates/status",
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
# Background updates should be enabled and making progress.
|
||||
self.assertDictEqual(
|
||||
|
@ -325,7 +325,7 @@ class BackgroundUpdatesTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
# test that each background update is waiting now
|
||||
for update in updates:
|
||||
|
|
|
@ -58,7 +58,7 @@ class DeviceRestTestCase(unittest.HomeserverTestCase):
|
|||
channel = self.make_request(method, self.url, b"{}")
|
||||
|
||||
self.assertEqual(
|
||||
HTTPStatus.UNAUTHORIZED,
|
||||
401,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
@ -76,7 +76,7 @@ class DeviceRestTestCase(unittest.HomeserverTestCase):
|
|||
)
|
||||
|
||||
self.assertEqual(
|
||||
HTTPStatus.FORBIDDEN,
|
||||
403,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
@ -85,7 +85,7 @@ class DeviceRestTestCase(unittest.HomeserverTestCase):
|
|||
@parameterized.expand(["GET", "PUT", "DELETE"])
|
||||
def test_user_does_not_exist(self, method: str) -> None:
|
||||
"""
|
||||
Tests that a lookup for a user that does not exist returns a HTTPStatus.NOT_FOUND
|
||||
Tests that a lookup for a user that does not exist returns a 404
|
||||
"""
|
||||
url = (
|
||||
"/_synapse/admin/v2/users/@unknown_person:test/devices/%s"
|
||||
|
@ -98,7 +98,7 @@ class DeviceRestTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.NOT_FOUND, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(404, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
|
||||
|
||||
@parameterized.expand(["GET", "PUT", "DELETE"])
|
||||
|
@ -122,7 +122,7 @@ class DeviceRestTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
def test_unknown_device(self) -> None:
|
||||
"""
|
||||
Tests that a lookup for a device that does not exist returns either HTTPStatus.NOT_FOUND or HTTPStatus.OK.
|
||||
Tests that a lookup for a device that does not exist returns either 404 or 200.
|
||||
"""
|
||||
url = "/_synapse/admin/v2/users/%s/devices/unknown_device" % urllib.parse.quote(
|
||||
self.other_user
|
||||
|
@ -134,7 +134,7 @@ class DeviceRestTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.NOT_FOUND, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(404, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
|
||||
|
||||
channel = self.make_request(
|
||||
|
@ -143,7 +143,7 @@ class DeviceRestTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
channel = self.make_request(
|
||||
"DELETE",
|
||||
|
@ -151,8 +151,8 @@ class DeviceRestTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
# Delete unknown device returns status HTTPStatus.OK
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
# Delete unknown device returns status 200
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
def test_update_device_too_long_display_name(self) -> None:
|
||||
"""
|
||||
|
@ -189,12 +189,12 @@ class DeviceRestTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual("new display", channel.json_body["display_name"])
|
||||
|
||||
def test_update_no_display_name(self) -> None:
|
||||
"""
|
||||
Tests that a update for a device without JSON returns a HTTPStatus.OK
|
||||
Tests that a update for a device without JSON returns a 200
|
||||
"""
|
||||
# Set iniital display name.
|
||||
update = {"display_name": "new display"}
|
||||
|
@ -210,7 +210,7 @@ class DeviceRestTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
# Ensure the display name was not updated.
|
||||
channel = self.make_request(
|
||||
|
@ -219,7 +219,7 @@ class DeviceRestTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual("new display", channel.json_body["display_name"])
|
||||
|
||||
def test_update_display_name(self) -> None:
|
||||
|
@ -234,7 +234,7 @@ class DeviceRestTestCase(unittest.HomeserverTestCase):
|
|||
content={"display_name": "new displayname"},
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
# Check new display_name
|
||||
channel = self.make_request(
|
||||
|
@ -243,7 +243,7 @@ class DeviceRestTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual("new displayname", channel.json_body["display_name"])
|
||||
|
||||
def test_get_device(self) -> None:
|
||||
|
@ -256,7 +256,7 @@ class DeviceRestTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(self.other_user, channel.json_body["user_id"])
|
||||
# Check that all fields are available
|
||||
self.assertIn("user_id", channel.json_body)
|
||||
|
@ -281,7 +281,7 @@ class DeviceRestTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
# Ensure that the number of devices is decreased
|
||||
res = self.get_success(self.handler.get_devices_by_user(self.other_user))
|
||||
|
@ -312,7 +312,7 @@ class DevicesRestTestCase(unittest.HomeserverTestCase):
|
|||
channel = self.make_request("GET", self.url, b"{}")
|
||||
|
||||
self.assertEqual(
|
||||
HTTPStatus.UNAUTHORIZED,
|
||||
401,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
@ -331,7 +331,7 @@ class DevicesRestTestCase(unittest.HomeserverTestCase):
|
|||
)
|
||||
|
||||
self.assertEqual(
|
||||
HTTPStatus.FORBIDDEN,
|
||||
403,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
@ -339,7 +339,7 @@ class DevicesRestTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
def test_user_does_not_exist(self) -> None:
|
||||
"""
|
||||
Tests that a lookup for a user that does not exist returns a HTTPStatus.NOT_FOUND
|
||||
Tests that a lookup for a user that does not exist returns a 404
|
||||
"""
|
||||
url = "/_synapse/admin/v2/users/@unknown_person:test/devices"
|
||||
channel = self.make_request(
|
||||
|
@ -348,7 +348,7 @@ class DevicesRestTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.NOT_FOUND, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(404, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
|
||||
|
||||
def test_user_is_not_local(self) -> None:
|
||||
|
@ -379,7 +379,7 @@ class DevicesRestTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(0, channel.json_body["total"])
|
||||
self.assertEqual(0, len(channel.json_body["devices"]))
|
||||
|
||||
|
@ -399,7 +399,7 @@ class DevicesRestTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(number_devices, channel.json_body["total"])
|
||||
self.assertEqual(number_devices, len(channel.json_body["devices"]))
|
||||
self.assertEqual(self.other_user, channel.json_body["devices"][0]["user_id"])
|
||||
|
@ -438,7 +438,7 @@ class DeleteDevicesRestTestCase(unittest.HomeserverTestCase):
|
|||
channel = self.make_request("POST", self.url, b"{}")
|
||||
|
||||
self.assertEqual(
|
||||
HTTPStatus.UNAUTHORIZED,
|
||||
401,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
@ -457,7 +457,7 @@ class DeleteDevicesRestTestCase(unittest.HomeserverTestCase):
|
|||
)
|
||||
|
||||
self.assertEqual(
|
||||
HTTPStatus.FORBIDDEN,
|
||||
403,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
@ -465,7 +465,7 @@ class DeleteDevicesRestTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
def test_user_does_not_exist(self) -> None:
|
||||
"""
|
||||
Tests that a lookup for a user that does not exist returns a HTTPStatus.NOT_FOUND
|
||||
Tests that a lookup for a user that does not exist returns a 404
|
||||
"""
|
||||
url = "/_synapse/admin/v2/users/@unknown_person:test/delete_devices"
|
||||
channel = self.make_request(
|
||||
|
@ -474,7 +474,7 @@ class DeleteDevicesRestTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.NOT_FOUND, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(404, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
|
||||
|
||||
def test_user_is_not_local(self) -> None:
|
||||
|
@ -494,7 +494,7 @@ class DeleteDevicesRestTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
def test_unknown_devices(self) -> None:
|
||||
"""
|
||||
Tests that a remove of a device that does not exist returns HTTPStatus.OK.
|
||||
Tests that a remove of a device that does not exist returns 200.
|
||||
"""
|
||||
channel = self.make_request(
|
||||
"POST",
|
||||
|
@ -503,8 +503,8 @@ class DeleteDevicesRestTestCase(unittest.HomeserverTestCase):
|
|||
content={"devices": ["unknown_device1", "unknown_device2"]},
|
||||
)
|
||||
|
||||
# Delete unknown devices returns status HTTPStatus.OK
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
# Delete unknown devices returns status 200
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
def test_delete_devices(self) -> None:
|
||||
"""
|
||||
|
@ -533,7 +533,7 @@ class DeleteDevicesRestTestCase(unittest.HomeserverTestCase):
|
|||
content={"devices": device_ids},
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
res = self.get_success(self.handler.get_devices_by_user(self.other_user))
|
||||
self.assertEqual(0, len(res))
|
||||
|
|
|
@ -82,7 +82,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
|||
channel = self.make_request("GET", self.url, b"{}")
|
||||
|
||||
self.assertEqual(
|
||||
HTTPStatus.UNAUTHORIZED,
|
||||
401,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
@ -90,7 +90,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
def test_requester_is_no_admin(self) -> None:
|
||||
"""
|
||||
If the user is not a server admin, an error HTTPStatus.FORBIDDEN is returned.
|
||||
If the user is not a server admin, an error 403 is returned.
|
||||
"""
|
||||
|
||||
channel = self.make_request(
|
||||
|
@ -100,7 +100,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
|||
)
|
||||
|
||||
self.assertEqual(
|
||||
HTTPStatus.FORBIDDEN,
|
||||
403,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
@ -117,7 +117,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], 20)
|
||||
self.assertEqual(len(channel.json_body["event_reports"]), 20)
|
||||
self.assertNotIn("next_token", channel.json_body)
|
||||
|
@ -134,7 +134,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], 20)
|
||||
self.assertEqual(len(channel.json_body["event_reports"]), 5)
|
||||
self.assertEqual(channel.json_body["next_token"], 5)
|
||||
|
@ -151,7 +151,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], 20)
|
||||
self.assertEqual(len(channel.json_body["event_reports"]), 15)
|
||||
self.assertNotIn("next_token", channel.json_body)
|
||||
|
@ -168,7 +168,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], 20)
|
||||
self.assertEqual(channel.json_body["next_token"], 15)
|
||||
self.assertEqual(len(channel.json_body["event_reports"]), 10)
|
||||
|
@ -185,7 +185,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], 10)
|
||||
self.assertEqual(len(channel.json_body["event_reports"]), 10)
|
||||
self.assertNotIn("next_token", channel.json_body)
|
||||
|
@ -205,7 +205,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], 10)
|
||||
self.assertEqual(len(channel.json_body["event_reports"]), 10)
|
||||
self.assertNotIn("next_token", channel.json_body)
|
||||
|
@ -225,7 +225,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], 5)
|
||||
self.assertEqual(len(channel.json_body["event_reports"]), 5)
|
||||
self.assertNotIn("next_token", channel.json_body)
|
||||
|
@ -247,7 +247,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], 20)
|
||||
self.assertEqual(len(channel.json_body["event_reports"]), 20)
|
||||
report = 1
|
||||
|
@ -265,7 +265,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], 20)
|
||||
self.assertEqual(len(channel.json_body["event_reports"]), 20)
|
||||
report = 1
|
||||
|
@ -344,7 +344,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], 20)
|
||||
self.assertEqual(len(channel.json_body["event_reports"]), 20)
|
||||
self.assertNotIn("next_token", channel.json_body)
|
||||
|
@ -357,7 +357,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], 20)
|
||||
self.assertEqual(len(channel.json_body["event_reports"]), 20)
|
||||
self.assertNotIn("next_token", channel.json_body)
|
||||
|
@ -370,7 +370,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], 20)
|
||||
self.assertEqual(len(channel.json_body["event_reports"]), 19)
|
||||
self.assertEqual(channel.json_body["next_token"], 19)
|
||||
|
@ -384,7 +384,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], 20)
|
||||
self.assertEqual(len(channel.json_body["event_reports"]), 1)
|
||||
self.assertNotIn("next_token", channel.json_body)
|
||||
|
@ -400,7 +400,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
|||
{"score": -100, "reason": "this makes me sad"},
|
||||
access_token=user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
def _create_event_and_report_without_parameters(
|
||||
self, room_id: str, user_tok: str
|
||||
|
@ -415,7 +415,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
|||
{},
|
||||
access_token=user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
def _check_fields(self, content: List[JsonDict]) -> None:
|
||||
"""Checks that all attributes are present in an event report"""
|
||||
|
@ -467,7 +467,7 @@ class EventReportDetailTestCase(unittest.HomeserverTestCase):
|
|||
channel = self.make_request("GET", self.url, b"{}")
|
||||
|
||||
self.assertEqual(
|
||||
HTTPStatus.UNAUTHORIZED,
|
||||
401,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
@ -475,7 +475,7 @@ class EventReportDetailTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
def test_requester_is_no_admin(self) -> None:
|
||||
"""
|
||||
If the user is not a server admin, an error HTTPStatus.FORBIDDEN is returned.
|
||||
If the user is not a server admin, an error 403 is returned.
|
||||
"""
|
||||
|
||||
channel = self.make_request(
|
||||
|
@ -485,7 +485,7 @@ class EventReportDetailTestCase(unittest.HomeserverTestCase):
|
|||
)
|
||||
|
||||
self.assertEqual(
|
||||
HTTPStatus.FORBIDDEN,
|
||||
403,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
@ -502,7 +502,7 @@ class EventReportDetailTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self._check_fields(channel.json_body)
|
||||
|
||||
def test_invalid_report_id(self) -> None:
|
||||
|
@ -566,7 +566,7 @@ class EventReportDetailTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
def test_report_id_not_found(self) -> None:
|
||||
"""
|
||||
Testing that a not existing `report_id` returns a HTTPStatus.NOT_FOUND.
|
||||
Testing that a not existing `report_id` returns a 404.
|
||||
"""
|
||||
|
||||
channel = self.make_request(
|
||||
|
@ -576,7 +576,7 @@ class EventReportDetailTestCase(unittest.HomeserverTestCase):
|
|||
)
|
||||
|
||||
self.assertEqual(
|
||||
HTTPStatus.NOT_FOUND,
|
||||
404,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
@ -594,7 +594,7 @@ class EventReportDetailTestCase(unittest.HomeserverTestCase):
|
|||
{"score": -100, "reason": "this makes me sad"},
|
||||
access_token=user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
def _check_fields(self, content: JsonDict) -> None:
|
||||
"""Checks that all attributes are present in a event report"""
|
||||
|
|
|
@ -64,7 +64,7 @@ class FederationTestCase(unittest.HomeserverTestCase):
|
|||
access_token=other_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.FORBIDDEN, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(403, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
||||
|
||||
def test_invalid_parameter(self) -> None:
|
||||
|
@ -117,7 +117,7 @@ class FederationTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.NOT_FOUND, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(404, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
|
||||
|
||||
# invalid destination
|
||||
|
@ -127,7 +127,7 @@ class FederationTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.NOT_FOUND, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(404, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
|
||||
|
||||
def test_limit(self) -> None:
|
||||
|
@ -142,7 +142,7 @@ class FederationTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], number_destinations)
|
||||
self.assertEqual(len(channel.json_body["destinations"]), 5)
|
||||
self.assertEqual(channel.json_body["next_token"], "5")
|
||||
|
@ -160,7 +160,7 @@ class FederationTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], number_destinations)
|
||||
self.assertEqual(len(channel.json_body["destinations"]), 15)
|
||||
self.assertNotIn("next_token", channel.json_body)
|
||||
|
@ -178,7 +178,7 @@ class FederationTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], number_destinations)
|
||||
self.assertEqual(channel.json_body["next_token"], "15")
|
||||
self.assertEqual(len(channel.json_body["destinations"]), 10)
|
||||
|
@ -198,7 +198,7 @@ class FederationTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], number_destinations)
|
||||
self.assertEqual(len(channel.json_body["destinations"]), number_destinations)
|
||||
self.assertNotIn("next_token", channel.json_body)
|
||||
|
@ -211,7 +211,7 @@ class FederationTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], number_destinations)
|
||||
self.assertEqual(len(channel.json_body["destinations"]), number_destinations)
|
||||
self.assertNotIn("next_token", channel.json_body)
|
||||
|
@ -224,7 +224,7 @@ class FederationTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], number_destinations)
|
||||
self.assertEqual(len(channel.json_body["destinations"]), 19)
|
||||
self.assertEqual(channel.json_body["next_token"], "19")
|
||||
|
@ -238,7 +238,7 @@ class FederationTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], number_destinations)
|
||||
self.assertEqual(len(channel.json_body["destinations"]), 1)
|
||||
self.assertNotIn("next_token", channel.json_body)
|
||||
|
@ -255,7 +255,7 @@ class FederationTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(number_destinations, len(channel.json_body["destinations"]))
|
||||
self.assertEqual(number_destinations, channel.json_body["total"])
|
||||
|
||||
|
@ -290,7 +290,7 @@ class FederationTestCase(unittest.HomeserverTestCase):
|
|||
url,
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], len(expected_destination_list))
|
||||
|
||||
returned_order = [
|
||||
|
@ -376,7 +376,7 @@ class FederationTestCase(unittest.HomeserverTestCase):
|
|||
url.encode("ascii"),
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
# Check that destinations were returned
|
||||
self.assertTrue("destinations" in channel.json_body)
|
||||
|
@ -418,7 +418,7 @@ class FederationTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual("sub0.example.com", channel.json_body["destination"])
|
||||
|
||||
# Check that all fields are available
|
||||
|
@ -435,7 +435,7 @@ class FederationTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual("sub0.example.com", channel.json_body["destination"])
|
||||
self.assertEqual(0, channel.json_body["retry_last_ts"])
|
||||
self.assertEqual(0, channel.json_body["retry_interval"])
|
||||
|
@ -452,7 +452,7 @@ class FederationTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
retry_timings = self.get_success(
|
||||
self.store.get_destination_retry_timings("sub0.example.com")
|
||||
|
@ -561,7 +561,7 @@ class DestinationMembershipTestCase(unittest.HomeserverTestCase):
|
|||
access_token=other_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.FORBIDDEN, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(403, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
||||
|
||||
def test_invalid_parameter(self) -> None:
|
||||
|
@ -604,7 +604,7 @@ class DestinationMembershipTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.NOT_FOUND, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(404, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
|
||||
|
||||
def test_limit(self) -> None:
|
||||
|
@ -619,7 +619,7 @@ class DestinationMembershipTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], number_rooms)
|
||||
self.assertEqual(len(channel.json_body["rooms"]), 3)
|
||||
self.assertEqual(channel.json_body["next_token"], "3")
|
||||
|
@ -637,7 +637,7 @@ class DestinationMembershipTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], number_rooms)
|
||||
self.assertEqual(len(channel.json_body["rooms"]), 5)
|
||||
self.assertNotIn("next_token", channel.json_body)
|
||||
|
@ -655,7 +655,7 @@ class DestinationMembershipTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], number_rooms)
|
||||
self.assertEqual(channel.json_body["next_token"], "8")
|
||||
self.assertEqual(len(channel.json_body["rooms"]), 5)
|
||||
|
@ -673,7 +673,7 @@ class DestinationMembershipTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel_asc.code, msg=channel_asc.json_body)
|
||||
self.assertEqual(200, channel_asc.code, msg=channel_asc.json_body)
|
||||
self.assertEqual(channel_asc.json_body["total"], number_rooms)
|
||||
self.assertEqual(number_rooms, len(channel_asc.json_body["rooms"]))
|
||||
self._check_fields(channel_asc.json_body["rooms"])
|
||||
|
@ -685,7 +685,7 @@ class DestinationMembershipTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel_desc.code, msg=channel_desc.json_body)
|
||||
self.assertEqual(200, channel_desc.code, msg=channel_desc.json_body)
|
||||
self.assertEqual(channel_desc.json_body["total"], number_rooms)
|
||||
self.assertEqual(number_rooms, len(channel_desc.json_body["rooms"]))
|
||||
self._check_fields(channel_desc.json_body["rooms"])
|
||||
|
@ -711,7 +711,7 @@ class DestinationMembershipTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], number_rooms)
|
||||
self.assertEqual(len(channel.json_body["rooms"]), number_rooms)
|
||||
self.assertNotIn("next_token", channel.json_body)
|
||||
|
@ -724,7 +724,7 @@ class DestinationMembershipTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], number_rooms)
|
||||
self.assertEqual(len(channel.json_body["rooms"]), number_rooms)
|
||||
self.assertNotIn("next_token", channel.json_body)
|
||||
|
@ -737,7 +737,7 @@ class DestinationMembershipTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], number_rooms)
|
||||
self.assertEqual(len(channel.json_body["rooms"]), 4)
|
||||
self.assertEqual(channel.json_body["next_token"], "4")
|
||||
|
@ -751,7 +751,7 @@ class DestinationMembershipTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], number_rooms)
|
||||
self.assertEqual(len(channel.json_body["rooms"]), 1)
|
||||
self.assertNotIn("next_token", channel.json_body)
|
||||
|
@ -767,7 +767,7 @@ class DestinationMembershipTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], number_rooms)
|
||||
self.assertEqual(number_rooms, len(channel.json_body["rooms"]))
|
||||
self._check_fields(channel.json_body["rooms"])
|
||||
|
|
|
@ -60,7 +60,7 @@ class DeleteMediaByIDTestCase(unittest.HomeserverTestCase):
|
|||
channel = self.make_request("DELETE", url, b"{}")
|
||||
|
||||
self.assertEqual(
|
||||
HTTPStatus.UNAUTHORIZED,
|
||||
401,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
@ -82,7 +82,7 @@ class DeleteMediaByIDTestCase(unittest.HomeserverTestCase):
|
|||
)
|
||||
|
||||
self.assertEqual(
|
||||
HTTPStatus.FORBIDDEN,
|
||||
403,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
@ -90,7 +90,7 @@ class DeleteMediaByIDTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
def test_media_does_not_exist(self) -> None:
|
||||
"""
|
||||
Tests that a lookup for a media that does not exist returns a HTTPStatus.NOT_FOUND
|
||||
Tests that a lookup for a media that does not exist returns a 404
|
||||
"""
|
||||
url = "/_synapse/admin/v1/media/%s/%s" % (self.server_name, "12345")
|
||||
|
||||
|
@ -100,7 +100,7 @@ class DeleteMediaByIDTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.NOT_FOUND, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(404, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
|
||||
|
||||
def test_media_is_not_local(self) -> None:
|
||||
|
@ -131,7 +131,7 @@ class DeleteMediaByIDTestCase(unittest.HomeserverTestCase):
|
|||
upload_resource,
|
||||
SMALL_PNG,
|
||||
tok=self.admin_user_tok,
|
||||
expect_code=HTTPStatus.OK,
|
||||
expect_code=200,
|
||||
)
|
||||
# Extract media ID from the response
|
||||
server_and_media_id = response["content_uri"][6:] # Cut off 'mxc://'
|
||||
|
@ -151,11 +151,10 @@ class DeleteMediaByIDTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
# Should be successful
|
||||
self.assertEqual(
|
||||
HTTPStatus.OK,
|
||||
200,
|
||||
channel.code,
|
||||
msg=(
|
||||
"Expected to receive a HTTPStatus.OK on accessing media: %s"
|
||||
% server_and_media_id
|
||||
"Expected to receive a 200 on accessing media: %s" % server_and_media_id
|
||||
),
|
||||
)
|
||||
|
||||
|
@ -172,7 +171,7 @@ class DeleteMediaByIDTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(1, channel.json_body["total"])
|
||||
self.assertEqual(
|
||||
media_id,
|
||||
|
@ -189,10 +188,10 @@ class DeleteMediaByIDTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(
|
||||
HTTPStatus.NOT_FOUND,
|
||||
404,
|
||||
channel.code,
|
||||
msg=(
|
||||
"Expected to receive a HTTPStatus.NOT_FOUND on accessing deleted media: %s"
|
||||
"Expected to receive a 404 on accessing deleted media: %s"
|
||||
% server_and_media_id
|
||||
),
|
||||
)
|
||||
|
@ -232,7 +231,7 @@ class DeleteMediaByDateSizeTestCase(unittest.HomeserverTestCase):
|
|||
channel = self.make_request("POST", self.url, b"{}")
|
||||
|
||||
self.assertEqual(
|
||||
HTTPStatus.UNAUTHORIZED,
|
||||
401,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
@ -252,7 +251,7 @@ class DeleteMediaByDateSizeTestCase(unittest.HomeserverTestCase):
|
|||
)
|
||||
|
||||
self.assertEqual(
|
||||
HTTPStatus.FORBIDDEN,
|
||||
403,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
@ -388,7 +387,7 @@ class DeleteMediaByDateSizeTestCase(unittest.HomeserverTestCase):
|
|||
self.url + "?before_ts=" + str(now_ms),
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(1, channel.json_body["total"])
|
||||
self.assertEqual(
|
||||
media_id,
|
||||
|
@ -413,7 +412,7 @@ class DeleteMediaByDateSizeTestCase(unittest.HomeserverTestCase):
|
|||
self.url + "?before_ts=" + str(now_ms),
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(0, channel.json_body["total"])
|
||||
|
||||
self._access_media(server_and_media_id)
|
||||
|
@ -425,7 +424,7 @@ class DeleteMediaByDateSizeTestCase(unittest.HomeserverTestCase):
|
|||
self.url + "?before_ts=" + str(now_ms),
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(1, channel.json_body["total"])
|
||||
self.assertEqual(
|
||||
server_and_media_id.split("/")[1],
|
||||
|
@ -449,7 +448,7 @@ class DeleteMediaByDateSizeTestCase(unittest.HomeserverTestCase):
|
|||
self.url + "?before_ts=" + str(now_ms) + "&size_gt=67",
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(0, channel.json_body["total"])
|
||||
|
||||
self._access_media(server_and_media_id)
|
||||
|
@ -460,7 +459,7 @@ class DeleteMediaByDateSizeTestCase(unittest.HomeserverTestCase):
|
|||
self.url + "?before_ts=" + str(now_ms) + "&size_gt=66",
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(1, channel.json_body["total"])
|
||||
self.assertEqual(
|
||||
server_and_media_id.split("/")[1],
|
||||
|
@ -485,7 +484,7 @@ class DeleteMediaByDateSizeTestCase(unittest.HomeserverTestCase):
|
|||
content={"avatar_url": "mxc://%s" % (server_and_media_id,)},
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
now_ms = self.clock.time_msec()
|
||||
channel = self.make_request(
|
||||
|
@ -493,7 +492,7 @@ class DeleteMediaByDateSizeTestCase(unittest.HomeserverTestCase):
|
|||
self.url + "?before_ts=" + str(now_ms) + "&keep_profiles=true",
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(0, channel.json_body["total"])
|
||||
|
||||
self._access_media(server_and_media_id)
|
||||
|
@ -504,7 +503,7 @@ class DeleteMediaByDateSizeTestCase(unittest.HomeserverTestCase):
|
|||
self.url + "?before_ts=" + str(now_ms) + "&keep_profiles=false",
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(1, channel.json_body["total"])
|
||||
self.assertEqual(
|
||||
server_and_media_id.split("/")[1],
|
||||
|
@ -530,7 +529,7 @@ class DeleteMediaByDateSizeTestCase(unittest.HomeserverTestCase):
|
|||
content={"url": "mxc://%s" % (server_and_media_id,)},
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
now_ms = self.clock.time_msec()
|
||||
channel = self.make_request(
|
||||
|
@ -538,7 +537,7 @@ class DeleteMediaByDateSizeTestCase(unittest.HomeserverTestCase):
|
|||
self.url + "?before_ts=" + str(now_ms) + "&keep_profiles=true",
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(0, channel.json_body["total"])
|
||||
|
||||
self._access_media(server_and_media_id)
|
||||
|
@ -549,7 +548,7 @@ class DeleteMediaByDateSizeTestCase(unittest.HomeserverTestCase):
|
|||
self.url + "?before_ts=" + str(now_ms) + "&keep_profiles=false",
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(1, channel.json_body["total"])
|
||||
self.assertEqual(
|
||||
server_and_media_id.split("/")[1],
|
||||
|
@ -569,7 +568,7 @@ class DeleteMediaByDateSizeTestCase(unittest.HomeserverTestCase):
|
|||
upload_resource,
|
||||
SMALL_PNG,
|
||||
tok=self.admin_user_tok,
|
||||
expect_code=HTTPStatus.OK,
|
||||
expect_code=200,
|
||||
)
|
||||
# Extract media ID from the response
|
||||
server_and_media_id = response["content_uri"][6:] # Cut off 'mxc://'
|
||||
|
@ -602,10 +601,10 @@ class DeleteMediaByDateSizeTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
if expect_success:
|
||||
self.assertEqual(
|
||||
HTTPStatus.OK,
|
||||
200,
|
||||
channel.code,
|
||||
msg=(
|
||||
"Expected to receive a HTTPStatus.OK on accessing media: %s"
|
||||
"Expected to receive a 200 on accessing media: %s"
|
||||
% server_and_media_id
|
||||
),
|
||||
)
|
||||
|
@ -613,10 +612,10 @@ class DeleteMediaByDateSizeTestCase(unittest.HomeserverTestCase):
|
|||
self.assertTrue(os.path.exists(local_path))
|
||||
else:
|
||||
self.assertEqual(
|
||||
HTTPStatus.NOT_FOUND,
|
||||
404,
|
||||
channel.code,
|
||||
msg=(
|
||||
"Expected to receive a HTTPStatus.NOT_FOUND on accessing deleted media: %s"
|
||||
"Expected to receive a 404 on accessing deleted media: %s"
|
||||
% (server_and_media_id)
|
||||
),
|
||||
)
|
||||
|
@ -648,7 +647,7 @@ class QuarantineMediaByIDTestCase(unittest.HomeserverTestCase):
|
|||
upload_resource,
|
||||
SMALL_PNG,
|
||||
tok=self.admin_user_tok,
|
||||
expect_code=HTTPStatus.OK,
|
||||
expect_code=200,
|
||||
)
|
||||
# Extract media ID from the response
|
||||
server_and_media_id = response["content_uri"][6:] # Cut off 'mxc://'
|
||||
|
@ -669,7 +668,7 @@ class QuarantineMediaByIDTestCase(unittest.HomeserverTestCase):
|
|||
)
|
||||
|
||||
self.assertEqual(
|
||||
HTTPStatus.UNAUTHORIZED,
|
||||
401,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
@ -690,7 +689,7 @@ class QuarantineMediaByIDTestCase(unittest.HomeserverTestCase):
|
|||
)
|
||||
|
||||
self.assertEqual(
|
||||
HTTPStatus.FORBIDDEN,
|
||||
403,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
@ -712,7 +711,7 @@ class QuarantineMediaByIDTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertFalse(channel.json_body)
|
||||
|
||||
media_info = self.get_success(self.store.get_local_media(self.media_id))
|
||||
|
@ -726,7 +725,7 @@ class QuarantineMediaByIDTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertFalse(channel.json_body)
|
||||
|
||||
media_info = self.get_success(self.store.get_local_media(self.media_id))
|
||||
|
@ -753,7 +752,7 @@ class QuarantineMediaByIDTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertFalse(channel.json_body)
|
||||
|
||||
# verify that is not in quarantine
|
||||
|
@ -785,7 +784,7 @@ class ProtectMediaByIDTestCase(unittest.HomeserverTestCase):
|
|||
upload_resource,
|
||||
SMALL_PNG,
|
||||
tok=self.admin_user_tok,
|
||||
expect_code=HTTPStatus.OK,
|
||||
expect_code=200,
|
||||
)
|
||||
# Extract media ID from the response
|
||||
server_and_media_id = response["content_uri"][6:] # Cut off 'mxc://'
|
||||
|
@ -802,7 +801,7 @@ class ProtectMediaByIDTestCase(unittest.HomeserverTestCase):
|
|||
channel = self.make_request("POST", self.url % (action, self.media_id), b"{}")
|
||||
|
||||
self.assertEqual(
|
||||
HTTPStatus.UNAUTHORIZED,
|
||||
401,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
@ -823,7 +822,7 @@ class ProtectMediaByIDTestCase(unittest.HomeserverTestCase):
|
|||
)
|
||||
|
||||
self.assertEqual(
|
||||
HTTPStatus.FORBIDDEN,
|
||||
403,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
@ -845,7 +844,7 @@ class ProtectMediaByIDTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertFalse(channel.json_body)
|
||||
|
||||
media_info = self.get_success(self.store.get_local_media(self.media_id))
|
||||
|
@ -859,7 +858,7 @@ class ProtectMediaByIDTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertFalse(channel.json_body)
|
||||
|
||||
media_info = self.get_success(self.store.get_local_media(self.media_id))
|
||||
|
@ -895,7 +894,7 @@ class PurgeMediaCacheTestCase(unittest.HomeserverTestCase):
|
|||
channel = self.make_request("POST", self.url, b"{}")
|
||||
|
||||
self.assertEqual(
|
||||
HTTPStatus.UNAUTHORIZED,
|
||||
401,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
@ -915,7 +914,7 @@ class PurgeMediaCacheTestCase(unittest.HomeserverTestCase):
|
|||
)
|
||||
|
||||
self.assertEqual(
|
||||
HTTPStatus.FORBIDDEN,
|
||||
403,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
|
|
@ -75,7 +75,7 @@ class ManageRegistrationTokensTestCase(unittest.HomeserverTestCase):
|
|||
"""Try to create a token without authentication."""
|
||||
channel = self.make_request("POST", self.url + "/new", {})
|
||||
self.assertEqual(
|
||||
HTTPStatus.UNAUTHORIZED,
|
||||
401,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
@ -90,7 +90,7 @@ class ManageRegistrationTokensTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.other_user_tok,
|
||||
)
|
||||
self.assertEqual(
|
||||
HTTPStatus.FORBIDDEN,
|
||||
403,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
@ -105,7 +105,7 @@ class ManageRegistrationTokensTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(len(channel.json_body["token"]), 16)
|
||||
self.assertIsNone(channel.json_body["uses_allowed"])
|
||||
self.assertIsNone(channel.json_body["expiry_time"])
|
||||
|
@ -129,7 +129,7 @@ class ManageRegistrationTokensTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["token"], token)
|
||||
self.assertEqual(channel.json_body["uses_allowed"], 1)
|
||||
self.assertEqual(channel.json_body["expiry_time"], data["expiry_time"])
|
||||
|
@ -150,7 +150,7 @@ class ManageRegistrationTokensTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(len(channel.json_body["token"]), 16)
|
||||
self.assertIsNone(channel.json_body["uses_allowed"])
|
||||
self.assertIsNone(channel.json_body["expiry_time"])
|
||||
|
@ -207,7 +207,7 @@ class ManageRegistrationTokensTestCase(unittest.HomeserverTestCase):
|
|||
data,
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel1.code, msg=channel1.json_body)
|
||||
self.assertEqual(200, channel1.code, msg=channel1.json_body)
|
||||
|
||||
channel2 = self.make_request(
|
||||
"POST",
|
||||
|
@ -251,7 +251,7 @@ class ManageRegistrationTokensTestCase(unittest.HomeserverTestCase):
|
|||
{"uses_allowed": 0},
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["uses_allowed"], 0)
|
||||
|
||||
# Should fail with negative integer
|
||||
|
@ -321,7 +321,7 @@ class ManageRegistrationTokensTestCase(unittest.HomeserverTestCase):
|
|||
{"length": 64},
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(len(channel.json_body["token"]), 64)
|
||||
|
||||
# Should fail with 0
|
||||
|
@ -390,7 +390,7 @@ class ManageRegistrationTokensTestCase(unittest.HomeserverTestCase):
|
|||
{},
|
||||
)
|
||||
self.assertEqual(
|
||||
HTTPStatus.UNAUTHORIZED,
|
||||
401,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
@ -405,7 +405,7 @@ class ManageRegistrationTokensTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.other_user_tok,
|
||||
)
|
||||
self.assertEqual(
|
||||
HTTPStatus.FORBIDDEN,
|
||||
403,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
@ -421,7 +421,7 @@ class ManageRegistrationTokensTestCase(unittest.HomeserverTestCase):
|
|||
)
|
||||
|
||||
self.assertEqual(
|
||||
HTTPStatus.NOT_FOUND,
|
||||
404,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
@ -439,7 +439,7 @@ class ManageRegistrationTokensTestCase(unittest.HomeserverTestCase):
|
|||
{"uses_allowed": 1},
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["uses_allowed"], 1)
|
||||
self.assertIsNone(channel.json_body["expiry_time"])
|
||||
|
||||
|
@ -450,7 +450,7 @@ class ManageRegistrationTokensTestCase(unittest.HomeserverTestCase):
|
|||
{"uses_allowed": 0},
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["uses_allowed"], 0)
|
||||
self.assertIsNone(channel.json_body["expiry_time"])
|
||||
|
||||
|
@ -461,7 +461,7 @@ class ManageRegistrationTokensTestCase(unittest.HomeserverTestCase):
|
|||
{"uses_allowed": None},
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertIsNone(channel.json_body["uses_allowed"])
|
||||
self.assertIsNone(channel.json_body["expiry_time"])
|
||||
|
||||
|
@ -506,7 +506,7 @@ class ManageRegistrationTokensTestCase(unittest.HomeserverTestCase):
|
|||
{"expiry_time": new_expiry_time},
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["expiry_time"], new_expiry_time)
|
||||
self.assertIsNone(channel.json_body["uses_allowed"])
|
||||
|
||||
|
@ -517,7 +517,7 @@ class ManageRegistrationTokensTestCase(unittest.HomeserverTestCase):
|
|||
{"expiry_time": None},
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertIsNone(channel.json_body["expiry_time"])
|
||||
self.assertIsNone(channel.json_body["uses_allowed"])
|
||||
|
||||
|
@ -568,7 +568,7 @@ class ManageRegistrationTokensTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["uses_allowed"], 1)
|
||||
self.assertEqual(channel.json_body["expiry_time"], new_expiry_time)
|
||||
|
||||
|
@ -606,7 +606,7 @@ class ManageRegistrationTokensTestCase(unittest.HomeserverTestCase):
|
|||
{},
|
||||
)
|
||||
self.assertEqual(
|
||||
HTTPStatus.UNAUTHORIZED,
|
||||
401,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
@ -621,7 +621,7 @@ class ManageRegistrationTokensTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.other_user_tok,
|
||||
)
|
||||
self.assertEqual(
|
||||
HTTPStatus.FORBIDDEN,
|
||||
403,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
@ -637,7 +637,7 @@ class ManageRegistrationTokensTestCase(unittest.HomeserverTestCase):
|
|||
)
|
||||
|
||||
self.assertEqual(
|
||||
HTTPStatus.NOT_FOUND,
|
||||
404,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
@ -655,7 +655,7 @@ class ManageRegistrationTokensTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
# GETTING ONE
|
||||
|
||||
|
@ -667,7 +667,7 @@ class ManageRegistrationTokensTestCase(unittest.HomeserverTestCase):
|
|||
{},
|
||||
)
|
||||
self.assertEqual(
|
||||
HTTPStatus.UNAUTHORIZED,
|
||||
401,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
@ -682,7 +682,7 @@ class ManageRegistrationTokensTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.other_user_tok,
|
||||
)
|
||||
self.assertEqual(
|
||||
HTTPStatus.FORBIDDEN,
|
||||
403,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
@ -698,7 +698,7 @@ class ManageRegistrationTokensTestCase(unittest.HomeserverTestCase):
|
|||
)
|
||||
|
||||
self.assertEqual(
|
||||
HTTPStatus.NOT_FOUND,
|
||||
404,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
@ -716,7 +716,7 @@ class ManageRegistrationTokensTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["token"], token)
|
||||
self.assertIsNone(channel.json_body["uses_allowed"])
|
||||
self.assertIsNone(channel.json_body["expiry_time"])
|
||||
|
@ -729,7 +729,7 @@ class ManageRegistrationTokensTestCase(unittest.HomeserverTestCase):
|
|||
"""Try to list tokens without authentication."""
|
||||
channel = self.make_request("GET", self.url, {})
|
||||
self.assertEqual(
|
||||
HTTPStatus.UNAUTHORIZED,
|
||||
401,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
@ -744,7 +744,7 @@ class ManageRegistrationTokensTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.other_user_tok,
|
||||
)
|
||||
self.assertEqual(
|
||||
HTTPStatus.FORBIDDEN,
|
||||
403,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
@ -762,7 +762,7 @@ class ManageRegistrationTokensTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(len(channel.json_body["registration_tokens"]), 1)
|
||||
token_info = channel.json_body["registration_tokens"][0]
|
||||
self.assertEqual(token_info["token"], token)
|
||||
|
@ -816,7 +816,7 @@ class ManageRegistrationTokensTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(len(channel.json_body["registration_tokens"]), 2)
|
||||
token_info_1 = channel.json_body["registration_tokens"][0]
|
||||
token_info_2 = channel.json_body["registration_tokens"][1]
|
||||
|
|
|
@ -68,7 +68,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
def test_requester_is_no_admin(self) -> None:
|
||||
"""
|
||||
If the user is not a server admin, an error HTTPStatus.FORBIDDEN is returned.
|
||||
If the user is not a server admin, an error 403 is returned.
|
||||
"""
|
||||
|
||||
channel = self.make_request(
|
||||
|
@ -78,7 +78,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.other_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.FORBIDDEN, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(403, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
||||
|
||||
def test_room_does_not_exist(self) -> None:
|
||||
|
@ -94,7 +94,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
def test_room_is_not_valid(self) -> None:
|
||||
"""
|
||||
|
@ -127,7 +127,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertIn("new_room_id", channel.json_body)
|
||||
self.assertIn("kicked_users", channel.json_body)
|
||||
self.assertIn("failed_to_kick_users", channel.json_body)
|
||||
|
@ -202,7 +202,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(None, channel.json_body["new_room_id"])
|
||||
self.assertEqual(self.other_user, channel.json_body["kicked_users"][0])
|
||||
self.assertIn("failed_to_kick_users", channel.json_body)
|
||||
|
@ -233,7 +233,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(None, channel.json_body["new_room_id"])
|
||||
self.assertEqual(self.other_user, channel.json_body["kicked_users"][0])
|
||||
self.assertIn("failed_to_kick_users", channel.json_body)
|
||||
|
@ -265,7 +265,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(None, channel.json_body["new_room_id"])
|
||||
self.assertEqual(self.other_user, channel.json_body["kicked_users"][0])
|
||||
self.assertIn("failed_to_kick_users", channel.json_body)
|
||||
|
@ -296,7 +296,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
|||
)
|
||||
|
||||
# The room is now blocked.
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self._is_blocked(room_id)
|
||||
|
||||
def test_shutdown_room_consent(self) -> None:
|
||||
|
@ -319,7 +319,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
|||
self.room_id,
|
||||
body="foo",
|
||||
tok=self.other_user_tok,
|
||||
expect_code=HTTPStatus.FORBIDDEN,
|
||||
expect_code=403,
|
||||
)
|
||||
|
||||
# Test that room is not purged
|
||||
|
@ -337,7 +337,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(self.other_user, channel.json_body["kicked_users"][0])
|
||||
self.assertIn("new_room_id", channel.json_body)
|
||||
self.assertIn("failed_to_kick_users", channel.json_body)
|
||||
|
@ -366,7 +366,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
|||
{"history_visibility": "world_readable"},
|
||||
access_token=self.other_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
# Test that room is not purged
|
||||
with self.assertRaises(AssertionError):
|
||||
|
@ -383,7 +383,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(self.other_user, channel.json_body["kicked_users"][0])
|
||||
self.assertIn("new_room_id", channel.json_body)
|
||||
self.assertIn("failed_to_kick_users", channel.json_body)
|
||||
|
@ -398,7 +398,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
|||
self._has_no_members(self.room_id)
|
||||
|
||||
# Assert we can no longer peek into the room
|
||||
self._assert_peek(self.room_id, expect_code=HTTPStatus.FORBIDDEN)
|
||||
self._assert_peek(self.room_id, expect_code=403)
|
||||
|
||||
def _is_blocked(self, room_id: str, expect: bool = True) -> None:
|
||||
"""Assert that the room is blocked or not"""
|
||||
|
@ -494,7 +494,7 @@ class DeleteRoomV2TestCase(unittest.HomeserverTestCase):
|
|||
)
|
||||
def test_requester_is_no_admin(self, method: str, url: str) -> None:
|
||||
"""
|
||||
If the user is not a server admin, an error HTTPStatus.FORBIDDEN is returned.
|
||||
If the user is not a server admin, an error 403 is returned.
|
||||
"""
|
||||
|
||||
channel = self.make_request(
|
||||
|
@ -504,7 +504,7 @@ class DeleteRoomV2TestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.other_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.FORBIDDEN, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(403, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
||||
|
||||
def test_room_does_not_exist(self) -> None:
|
||||
|
@ -522,7 +522,7 @@ class DeleteRoomV2TestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertIn("delete_id", channel.json_body)
|
||||
delete_id = channel.json_body["delete_id"]
|
||||
|
||||
|
@ -533,7 +533,7 @@ class DeleteRoomV2TestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(1, len(channel.json_body["results"]))
|
||||
self.assertEqual("complete", channel.json_body["results"][0]["status"])
|
||||
self.assertEqual(delete_id, channel.json_body["results"][0]["delete_id"])
|
||||
|
@ -574,7 +574,7 @@ class DeleteRoomV2TestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertIn("delete_id", channel.json_body)
|
||||
delete_id = channel.json_body["delete_id"]
|
||||
|
||||
|
@ -639,7 +639,7 @@ class DeleteRoomV2TestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertIn("delete_id", channel.json_body)
|
||||
delete_id1 = channel.json_body["delete_id"]
|
||||
|
||||
|
@ -654,7 +654,7 @@ class DeleteRoomV2TestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertIn("delete_id", channel.json_body)
|
||||
delete_id2 = channel.json_body["delete_id"]
|
||||
|
||||
|
@ -665,7 +665,7 @@ class DeleteRoomV2TestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(2, len(channel.json_body["results"]))
|
||||
self.assertEqual("complete", channel.json_body["results"][0]["status"])
|
||||
self.assertEqual("complete", channel.json_body["results"][1]["status"])
|
||||
|
@ -682,7 +682,7 @@ class DeleteRoomV2TestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(1, len(channel.json_body["results"]))
|
||||
self.assertEqual("complete", channel.json_body["results"][0]["status"])
|
||||
self.assertEqual(delete_id2, channel.json_body["results"][0]["delete_id"])
|
||||
|
@ -696,7 +696,7 @@ class DeleteRoomV2TestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.NOT_FOUND, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(404, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
|
||||
|
||||
def test_delete_same_room_twice(self) -> None:
|
||||
|
@ -733,7 +733,7 @@ class DeleteRoomV2TestCase(unittest.HomeserverTestCase):
|
|||
|
||||
# get result of first call
|
||||
first_channel.await_result()
|
||||
self.assertEqual(HTTPStatus.OK, first_channel.code, msg=first_channel.json_body)
|
||||
self.assertEqual(200, first_channel.code, msg=first_channel.json_body)
|
||||
self.assertIn("delete_id", first_channel.json_body)
|
||||
|
||||
# check status after finish the task
|
||||
|
@ -764,7 +764,7 @@ class DeleteRoomV2TestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertIn("delete_id", channel.json_body)
|
||||
delete_id = channel.json_body["delete_id"]
|
||||
|
||||
|
@ -795,7 +795,7 @@ class DeleteRoomV2TestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertIn("delete_id", channel.json_body)
|
||||
delete_id = channel.json_body["delete_id"]
|
||||
|
||||
|
@ -827,7 +827,7 @@ class DeleteRoomV2TestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertIn("delete_id", channel.json_body)
|
||||
delete_id = channel.json_body["delete_id"]
|
||||
|
||||
|
@ -858,7 +858,7 @@ class DeleteRoomV2TestCase(unittest.HomeserverTestCase):
|
|||
self.room_id,
|
||||
body="foo",
|
||||
tok=self.other_user_tok,
|
||||
expect_code=HTTPStatus.FORBIDDEN,
|
||||
expect_code=403,
|
||||
)
|
||||
|
||||
# Test that room is not purged
|
||||
|
@ -876,7 +876,7 @@ class DeleteRoomV2TestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertIn("delete_id", channel.json_body)
|
||||
delete_id = channel.json_body["delete_id"]
|
||||
|
||||
|
@ -887,7 +887,7 @@ class DeleteRoomV2TestCase(unittest.HomeserverTestCase):
|
|||
self.url_status_by_room_id,
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(1, len(channel.json_body["results"]))
|
||||
|
||||
# Test that member has moved to new room
|
||||
|
@ -914,7 +914,7 @@ class DeleteRoomV2TestCase(unittest.HomeserverTestCase):
|
|||
content={"history_visibility": "world_readable"},
|
||||
access_token=self.other_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
# Test that room is not purged
|
||||
with self.assertRaises(AssertionError):
|
||||
|
@ -931,7 +931,7 @@ class DeleteRoomV2TestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertIn("delete_id", channel.json_body)
|
||||
delete_id = channel.json_body["delete_id"]
|
||||
|
||||
|
@ -942,7 +942,7 @@ class DeleteRoomV2TestCase(unittest.HomeserverTestCase):
|
|||
self.url_status_by_room_id,
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(1, len(channel.json_body["results"]))
|
||||
|
||||
# Test that member has moved to new room
|
||||
|
@ -955,7 +955,7 @@ class DeleteRoomV2TestCase(unittest.HomeserverTestCase):
|
|||
self._has_no_members(self.room_id)
|
||||
|
||||
# Assert we can no longer peek into the room
|
||||
self._assert_peek(self.room_id, expect_code=HTTPStatus.FORBIDDEN)
|
||||
self._assert_peek(self.room_id, expect_code=403)
|
||||
|
||||
def _is_blocked(self, room_id: str, expect: bool = True) -> None:
|
||||
"""Assert that the room is blocked or not"""
|
||||
|
@ -1026,9 +1026,7 @@ class DeleteRoomV2TestCase(unittest.HomeserverTestCase):
|
|||
self.url_status_by_room_id,
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(
|
||||
HTTPStatus.OK, channel_room_id.code, msg=channel_room_id.json_body
|
||||
)
|
||||
self.assertEqual(200, channel_room_id.code, msg=channel_room_id.json_body)
|
||||
self.assertEqual(1, len(channel_room_id.json_body["results"]))
|
||||
self.assertEqual(
|
||||
delete_id, channel_room_id.json_body["results"][0]["delete_id"]
|
||||
|
@ -1041,7 +1039,7 @@ class DeleteRoomV2TestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(
|
||||
HTTPStatus.OK,
|
||||
200,
|
||||
channel_delete_id.code,
|
||||
msg=channel_delete_id.json_body,
|
||||
)
|
||||
|
@ -1100,7 +1098,7 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
|||
)
|
||||
|
||||
# Check request completed successfully
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
# Check that response json body contains a "rooms" key
|
||||
self.assertTrue(
|
||||
|
@ -1186,7 +1184,7 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
|||
url.encode("ascii"),
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
self.assertTrue("rooms" in channel.json_body)
|
||||
for r in channel.json_body["rooms"]:
|
||||
|
@ -1226,7 +1224,7 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
|||
url.encode("ascii"),
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
def test_correct_room_attributes(self) -> None:
|
||||
"""Test the correct attributes for a room are returned"""
|
||||
|
@ -1253,7 +1251,7 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
|||
{"room_id": room_id},
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
# Set this new alias as the canonical alias for this room
|
||||
self.helper.send_state(
|
||||
|
@ -1285,7 +1283,7 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
|||
url.encode("ascii"),
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
# Check that rooms were returned
|
||||
self.assertTrue("rooms" in channel.json_body)
|
||||
|
@ -1341,7 +1339,7 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
|||
url.encode("ascii"),
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
# Check that rooms were returned
|
||||
self.assertTrue("rooms" in channel.json_body)
|
||||
|
@ -1487,7 +1485,7 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
|||
def _search_test(
|
||||
expected_room_id: Optional[str],
|
||||
search_term: str,
|
||||
expected_http_code: int = HTTPStatus.OK,
|
||||
expected_http_code: int = 200,
|
||||
) -> None:
|
||||
"""Search for a room and check that the returned room's id is a match
|
||||
|
||||
|
@ -1505,7 +1503,7 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
|||
)
|
||||
self.assertEqual(expected_http_code, channel.code, msg=channel.json_body)
|
||||
|
||||
if expected_http_code != HTTPStatus.OK:
|
||||
if expected_http_code != 200:
|
||||
return
|
||||
|
||||
# Check that rooms were returned
|
||||
|
@ -1585,7 +1583,7 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
|||
url.encode("ascii"),
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(room_id, channel.json_body["rooms"][0].get("room_id"))
|
||||
self.assertEqual("ж", channel.json_body["rooms"][0].get("name"))
|
||||
|
||||
|
@ -1618,7 +1616,7 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
|||
url.encode("ascii"),
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
self.assertIn("room_id", channel.json_body)
|
||||
self.assertIn("name", channel.json_body)
|
||||
|
@ -1650,7 +1648,7 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
|||
url.encode("ascii"),
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(1, channel.json_body["joined_local_devices"])
|
||||
|
||||
# Have another user join the room
|
||||
|
@ -1664,7 +1662,7 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
|||
url.encode("ascii"),
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(2, channel.json_body["joined_local_devices"])
|
||||
|
||||
# leave room
|
||||
|
@ -1676,7 +1674,7 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
|||
url.encode("ascii"),
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(0, channel.json_body["joined_local_devices"])
|
||||
|
||||
def test_room_members(self) -> None:
|
||||
|
@ -1707,7 +1705,7 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
|||
url.encode("ascii"),
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
self.assertCountEqual(
|
||||
["@admin:test", "@foo:test", "@bar:test"], channel.json_body["members"]
|
||||
|
@ -1720,7 +1718,7 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
|||
url.encode("ascii"),
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
self.assertCountEqual(
|
||||
["@admin:test", "@bar:test", "@foobar:test"], channel.json_body["members"]
|
||||
|
@ -1738,7 +1736,7 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
|||
url.encode("ascii"),
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertIn("state", channel.json_body)
|
||||
# testing that the state events match is painful and not done here. We assume that
|
||||
# the create_room already does the right thing, so no need to verify that we got
|
||||
|
@ -1755,7 +1753,7 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
|||
{"room_id": room_id},
|
||||
access_token=admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
# Set this new alias as the canonical alias for this room
|
||||
self.helper.send_state(
|
||||
|
@ -1784,7 +1782,7 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
|||
# delete the rooms and get joined roomed membership
|
||||
url = f"/_matrix/client/r0/rooms/{room_id}/joined_members"
|
||||
channel = self.make_request("GET", url.encode("ascii"), access_token=user_tok)
|
||||
self.assertEqual(HTTPStatus.FORBIDDEN, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(403, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
||||
|
||||
|
||||
|
@ -1813,7 +1811,7 @@ class JoinAliasRoomTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
def test_requester_is_no_admin(self) -> None:
|
||||
"""
|
||||
If the user is not a server admin, an error HTTPStatus.FORBIDDEN is returned.
|
||||
If the user is not a server admin, an error 403 is returned.
|
||||
"""
|
||||
|
||||
channel = self.make_request(
|
||||
|
@ -1823,7 +1821,7 @@ class JoinAliasRoomTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.second_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.FORBIDDEN, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(403, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
||||
|
||||
def test_invalid_parameter(self) -> None:
|
||||
|
@ -1843,7 +1841,7 @@ class JoinAliasRoomTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
def test_local_user_does_not_exist(self) -> None:
|
||||
"""
|
||||
Tests that a lookup for a user that does not exist returns a HTTPStatus.NOT_FOUND
|
||||
Tests that a lookup for a user that does not exist returns a 404
|
||||
"""
|
||||
|
||||
channel = self.make_request(
|
||||
|
@ -1853,7 +1851,7 @@ class JoinAliasRoomTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.NOT_FOUND, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(404, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
|
||||
|
||||
def test_remote_user(self) -> None:
|
||||
|
@ -1876,7 +1874,7 @@ class JoinAliasRoomTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
def test_room_does_not_exist(self) -> None:
|
||||
"""
|
||||
Check that unknown rooms/server return error HTTPStatus.NOT_FOUND.
|
||||
Check that unknown rooms/server return error 404.
|
||||
"""
|
||||
url = "/_synapse/admin/v1/join/!unknown:test"
|
||||
|
||||
|
@ -1887,7 +1885,7 @@ class JoinAliasRoomTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.NOT_FOUND, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(404, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(
|
||||
"Can't join remote room because no servers that are in the room have been provided.",
|
||||
channel.json_body["error"],
|
||||
|
@ -1924,7 +1922,7 @@ class JoinAliasRoomTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(self.public_room_id, channel.json_body["room_id"])
|
||||
|
||||
# Validate if user is a member of the room
|
||||
|
@ -1934,7 +1932,7 @@ class JoinAliasRoomTestCase(unittest.HomeserverTestCase):
|
|||
"/_matrix/client/r0/joined_rooms",
|
||||
access_token=self.second_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(self.public_room_id, channel.json_body["joined_rooms"][0])
|
||||
|
||||
def test_join_private_room_if_not_member(self) -> None:
|
||||
|
@ -1954,7 +1952,7 @@ class JoinAliasRoomTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.FORBIDDEN, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(403, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
||||
|
||||
def test_join_private_room_if_member(self) -> None:
|
||||
|
@ -1982,7 +1980,7 @@ class JoinAliasRoomTestCase(unittest.HomeserverTestCase):
|
|||
"/_matrix/client/r0/joined_rooms",
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(private_room_id, channel.json_body["joined_rooms"][0])
|
||||
|
||||
# Join user to room.
|
||||
|
@ -1995,7 +1993,7 @@ class JoinAliasRoomTestCase(unittest.HomeserverTestCase):
|
|||
content={"user_id": self.second_user_id},
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(private_room_id, channel.json_body["room_id"])
|
||||
|
||||
# Validate if user is a member of the room
|
||||
|
@ -2005,7 +2003,7 @@ class JoinAliasRoomTestCase(unittest.HomeserverTestCase):
|
|||
"/_matrix/client/r0/joined_rooms",
|
||||
access_token=self.second_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(private_room_id, channel.json_body["joined_rooms"][0])
|
||||
|
||||
def test_join_private_room_if_owner(self) -> None:
|
||||
|
@ -2025,7 +2023,7 @@ class JoinAliasRoomTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(private_room_id, channel.json_body["room_id"])
|
||||
|
||||
# Validate if user is a member of the room
|
||||
|
@ -2035,7 +2033,7 @@ class JoinAliasRoomTestCase(unittest.HomeserverTestCase):
|
|||
"/_matrix/client/r0/joined_rooms",
|
||||
access_token=self.second_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(private_room_id, channel.json_body["joined_rooms"][0])
|
||||
|
||||
def test_context_as_non_admin(self) -> None:
|
||||
|
@ -2069,7 +2067,7 @@ class JoinAliasRoomTestCase(unittest.HomeserverTestCase):
|
|||
% (room_id, events[midway]["event_id"]),
|
||||
access_token=tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.FORBIDDEN, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(403, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
||||
|
||||
def test_context_as_admin(self) -> None:
|
||||
|
@ -2099,7 +2097,7 @@ class JoinAliasRoomTestCase(unittest.HomeserverTestCase):
|
|||
% (room_id, events[midway]["event_id"]),
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(
|
||||
channel.json_body["event"]["event_id"], events[midway]["event_id"]
|
||||
)
|
||||
|
@ -2158,7 +2156,7 @@ class MakeRoomAdminTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
# Now we test that we can join the room and ban a user.
|
||||
self.helper.join(room_id, self.admin_user, tok=self.admin_user_tok)
|
||||
|
@ -2185,7 +2183,7 @@ class MakeRoomAdminTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
# Now we test that we can join the room (we should have received an
|
||||
# invite) and can ban a user.
|
||||
|
@ -2211,7 +2209,7 @@ class MakeRoomAdminTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
# Now we test that we can join the room and ban a user.
|
||||
self.helper.join(room_id, self.second_user_id, tok=self.second_tok)
|
||||
|
@ -2279,7 +2277,7 @@ class BlockRoomTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
@parameterized.expand([("PUT",), ("GET",)])
|
||||
def test_requester_is_no_admin(self, method: str) -> None:
|
||||
"""If the user is not a server admin, an error HTTPStatus.FORBIDDEN is returned."""
|
||||
"""If the user is not a server admin, an error 403 is returned."""
|
||||
|
||||
channel = self.make_request(
|
||||
method,
|
||||
|
@ -2288,7 +2286,7 @@ class BlockRoomTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.other_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.FORBIDDEN, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(403, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
||||
|
||||
@parameterized.expand([("PUT",), ("GET",)])
|
||||
|
@ -2354,7 +2352,7 @@ class BlockRoomTestCase(unittest.HomeserverTestCase):
|
|||
content={"block": True},
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertTrue(channel.json_body["block"])
|
||||
self._is_blocked(room_id, expect=True)
|
||||
|
||||
|
@ -2378,7 +2376,7 @@ class BlockRoomTestCase(unittest.HomeserverTestCase):
|
|||
content={"block": True},
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertTrue(channel.json_body["block"])
|
||||
self._is_blocked(self.room_id, expect=True)
|
||||
|
||||
|
@ -2394,7 +2392,7 @@ class BlockRoomTestCase(unittest.HomeserverTestCase):
|
|||
content={"block": False},
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertFalse(channel.json_body["block"])
|
||||
self._is_blocked(room_id, expect=False)
|
||||
|
||||
|
@ -2418,7 +2416,7 @@ class BlockRoomTestCase(unittest.HomeserverTestCase):
|
|||
content={"block": False},
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertFalse(channel.json_body["block"])
|
||||
self._is_blocked(self.room_id, expect=False)
|
||||
|
||||
|
@ -2433,7 +2431,7 @@ class BlockRoomTestCase(unittest.HomeserverTestCase):
|
|||
self.url % room_id,
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertTrue(channel.json_body["block"])
|
||||
self.assertEqual(self.other_user, channel.json_body["user_id"])
|
||||
|
||||
|
@ -2457,7 +2455,7 @@ class BlockRoomTestCase(unittest.HomeserverTestCase):
|
|||
self.url % room_id,
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertFalse(channel.json_body["block"])
|
||||
self.assertNotIn("user_id", channel.json_body)
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ class ServerNoticeTestCase(unittest.HomeserverTestCase):
|
|||
channel = self.make_request("POST", self.url)
|
||||
|
||||
self.assertEqual(
|
||||
HTTPStatus.UNAUTHORIZED,
|
||||
401,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
@ -72,7 +72,7 @@ class ServerNoticeTestCase(unittest.HomeserverTestCase):
|
|||
)
|
||||
|
||||
self.assertEqual(
|
||||
HTTPStatus.FORBIDDEN,
|
||||
403,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
@ -80,7 +80,7 @@ class ServerNoticeTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
@override_config({"server_notices": {"system_mxid_localpart": "notices"}})
|
||||
def test_user_does_not_exist(self) -> None:
|
||||
"""Tests that a lookup for a user that does not exist returns a HTTPStatus.NOT_FOUND"""
|
||||
"""Tests that a lookup for a user that does not exist returns a 404"""
|
||||
channel = self.make_request(
|
||||
"POST",
|
||||
self.url,
|
||||
|
@ -88,7 +88,7 @@ class ServerNoticeTestCase(unittest.HomeserverTestCase):
|
|||
content={"user_id": "@unknown_person:test", "content": ""},
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.NOT_FOUND, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(404, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
|
||||
|
||||
@override_config({"server_notices": {"system_mxid_localpart": "notices"}})
|
||||
|
@ -197,7 +197,7 @@ class ServerNoticeTestCase(unittest.HomeserverTestCase):
|
|||
"content": {"msgtype": "m.text", "body": "test msg one"},
|
||||
},
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
# user has one invite
|
||||
invited_rooms = self._check_invite_and_join_status(self.other_user, 1, 0)
|
||||
|
@ -226,7 +226,7 @@ class ServerNoticeTestCase(unittest.HomeserverTestCase):
|
|||
"content": {"msgtype": "m.text", "body": "test msg two"},
|
||||
},
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
# user has no new invites or memberships
|
||||
self._check_invite_and_join_status(self.other_user, 0, 1)
|
||||
|
@ -260,7 +260,7 @@ class ServerNoticeTestCase(unittest.HomeserverTestCase):
|
|||
"content": {"msgtype": "m.text", "body": "test msg one"},
|
||||
},
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
# user has one invite
|
||||
invited_rooms = self._check_invite_and_join_status(self.other_user, 1, 0)
|
||||
|
@ -301,7 +301,7 @@ class ServerNoticeTestCase(unittest.HomeserverTestCase):
|
|||
"content": {"msgtype": "m.text", "body": "test msg two"},
|
||||
},
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
# user has one invite
|
||||
invited_rooms = self._check_invite_and_join_status(self.other_user, 1, 0)
|
||||
|
@ -341,7 +341,7 @@ class ServerNoticeTestCase(unittest.HomeserverTestCase):
|
|||
"content": {"msgtype": "m.text", "body": "test msg one"},
|
||||
},
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
# user has one invite
|
||||
invited_rooms = self._check_invite_and_join_status(self.other_user, 1, 0)
|
||||
|
@ -388,7 +388,7 @@ class ServerNoticeTestCase(unittest.HomeserverTestCase):
|
|||
"content": {"msgtype": "m.text", "body": "test msg two"},
|
||||
},
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
# user has one invite
|
||||
invited_rooms = self._check_invite_and_join_status(self.other_user, 1, 0)
|
||||
|
@ -538,7 +538,7 @@ class ServerNoticeTestCase(unittest.HomeserverTestCase):
|
|||
channel = self.make_request(
|
||||
"GET", "/_matrix/client/r0/sync", access_token=token
|
||||
)
|
||||
self.assertEqual(channel.code, HTTPStatus.OK)
|
||||
self.assertEqual(channel.code, 200)
|
||||
|
||||
# Get the messages
|
||||
room = channel.json_body["rooms"]["join"][room_id]
|
||||
|
|
|
@ -52,7 +52,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
|||
channel = self.make_request("GET", self.url, b"{}")
|
||||
|
||||
self.assertEqual(
|
||||
HTTPStatus.UNAUTHORIZED,
|
||||
401,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
@ -60,7 +60,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
def test_requester_is_no_admin(self) -> None:
|
||||
"""
|
||||
If the user is not a server admin, an error HTTPStatus.FORBIDDEN is returned.
|
||||
If the user is not a server admin, an error 403 is returned.
|
||||
"""
|
||||
channel = self.make_request(
|
||||
"GET",
|
||||
|
@ -70,7 +70,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
|||
)
|
||||
|
||||
self.assertEqual(
|
||||
HTTPStatus.FORBIDDEN,
|
||||
403,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
|
@ -204,7 +204,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], 10)
|
||||
self.assertEqual(len(channel.json_body["users"]), 5)
|
||||
self.assertEqual(channel.json_body["next_token"], 5)
|
||||
|
@ -222,7 +222,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], 20)
|
||||
self.assertEqual(len(channel.json_body["users"]), 15)
|
||||
self.assertNotIn("next_token", channel.json_body)
|
||||
|
@ -240,7 +240,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], 20)
|
||||
self.assertEqual(channel.json_body["next_token"], 15)
|
||||
self.assertEqual(len(channel.json_body["users"]), 10)
|
||||
|
@ -262,7 +262,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], number_users)
|
||||
self.assertEqual(len(channel.json_body["users"]), number_users)
|
||||
self.assertNotIn("next_token", channel.json_body)
|
||||
|
@ -275,7 +275,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], number_users)
|
||||
self.assertEqual(len(channel.json_body["users"]), number_users)
|
||||
self.assertNotIn("next_token", channel.json_body)
|
||||
|
@ -288,7 +288,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], number_users)
|
||||
self.assertEqual(len(channel.json_body["users"]), 19)
|
||||
self.assertEqual(channel.json_body["next_token"], 19)
|
||||
|
@ -301,7 +301,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], number_users)
|
||||
self.assertEqual(len(channel.json_body["users"]), 1)
|
||||
self.assertNotIn("next_token", channel.json_body)
|
||||
|
@ -318,7 +318,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(0, channel.json_body["total"])
|
||||
self.assertEqual(0, len(channel.json_body["users"]))
|
||||
|
||||
|
@ -415,7 +415,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
|||
self.url,
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["users"][0]["media_count"], 3)
|
||||
|
||||
# filter media starting at `ts1` after creating first media
|
||||
|
@ -425,7 +425,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
|||
self.url + "?from_ts=%s" % (ts1,),
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], 0)
|
||||
|
||||
self._create_media(self.other_user_tok, 3)
|
||||
|
@ -440,7 +440,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
|||
self.url + "?from_ts=%s&until_ts=%s" % (ts1, ts2),
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["users"][0]["media_count"], 3)
|
||||
|
||||
# filter media until `ts2` and earlier
|
||||
|
@ -449,7 +449,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
|||
self.url + "?until_ts=%s" % (ts2,),
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["users"][0]["media_count"], 6)
|
||||
|
||||
def test_search_term(self) -> None:
|
||||
|
@ -461,7 +461,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
|||
self.url,
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], 20)
|
||||
|
||||
# filter user 1 and 10-19 by `user_id`
|
||||
|
@ -470,7 +470,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
|||
self.url + "?search_term=foo_user_1",
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], 11)
|
||||
|
||||
# filter on this user in `displayname`
|
||||
|
@ -479,7 +479,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
|||
self.url + "?search_term=bar_user_10",
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["users"][0]["displayname"], "bar_user_10")
|
||||
self.assertEqual(channel.json_body["total"], 1)
|
||||
|
||||
|
@ -489,7 +489,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
|||
self.url + "?search_term=foobar",
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], 0)
|
||||
|
||||
def _create_users_with_media(self, number_users: int, media_per_user: int) -> None:
|
||||
|
@ -515,7 +515,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
|||
for _ in range(number_media):
|
||||
# Upload some media into the room
|
||||
self.helper.upload_media(
|
||||
upload_resource, SMALL_PNG, tok=user_token, expect_code=HTTPStatus.OK
|
||||
upload_resource, SMALL_PNG, tok=user_token, expect_code=200
|
||||
)
|
||||
|
||||
def _check_fields(self, content: List[JsonDict]) -> None:
|
||||
|
@ -549,7 +549,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
|||
url.encode("ascii"),
|
||||
access_token=self.admin_user_tok,
|
||||
)
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(channel.json_body["total"], len(expected_user_list))
|
||||
|
||||
returned_order = [row["user_id"] for row in channel.json_body["users"]]
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -50,18 +50,18 @@ class UsernameAvailableTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
def test_username_available(self) -> None:
|
||||
"""
|
||||
The endpoint should return a HTTPStatus.OK response if the username does not exist
|
||||
The endpoint should return a 200 response if the username does not exist
|
||||
"""
|
||||
|
||||
url = "%s?username=%s" % (self.url, "allowed")
|
||||
channel = self.make_request("GET", url, access_token=self.admin_user_tok)
|
||||
|
||||
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
self.assertTrue(channel.json_body["available"])
|
||||
|
||||
def test_username_unavailable(self) -> None:
|
||||
"""
|
||||
The endpoint should return a HTTPStatus.OK response if the username does not exist
|
||||
The endpoint should return a 200 response if the username does not exist
|
||||
"""
|
||||
|
||||
url = "%s?username=%s" % (self.url, "disallowed")
|
||||
|
|
|
@ -43,7 +43,7 @@ class FilterTestCase(unittest.HomeserverTestCase):
|
|||
self.EXAMPLE_FILTER_JSON,
|
||||
)
|
||||
|
||||
self.assertEqual(channel.result["code"], b"200")
|
||||
self.assertEqual(channel.code, 200)
|
||||
self.assertEqual(channel.json_body, {"filter_id": "0"})
|
||||
filter = self.get_success(
|
||||
self.store.get_user_filter(user_localpart="apple", filter_id=0)
|
||||
|
@ -58,7 +58,7 @@ class FilterTestCase(unittest.HomeserverTestCase):
|
|||
self.EXAMPLE_FILTER_JSON,
|
||||
)
|
||||
|
||||
self.assertEqual(channel.result["code"], b"403")
|
||||
self.assertEqual(channel.code, 403)
|
||||
self.assertEqual(channel.json_body["errcode"], Codes.FORBIDDEN)
|
||||
|
||||
def test_add_filter_non_local_user(self) -> None:
|
||||
|
@ -71,7 +71,7 @@ class FilterTestCase(unittest.HomeserverTestCase):
|
|||
)
|
||||
|
||||
self.hs.is_mine = _is_mine
|
||||
self.assertEqual(channel.result["code"], b"403")
|
||||
self.assertEqual(channel.code, 403)
|
||||
self.assertEqual(channel.json_body["errcode"], Codes.FORBIDDEN)
|
||||
|
||||
def test_get_filter(self) -> None:
|
||||
|
@ -85,7 +85,7 @@ class FilterTestCase(unittest.HomeserverTestCase):
|
|||
"GET", "/_matrix/client/r0/user/%s/filter/%s" % (self.user_id, filter_id)
|
||||
)
|
||||
|
||||
self.assertEqual(channel.result["code"], b"200")
|
||||
self.assertEqual(channel.code, 200)
|
||||
self.assertEqual(channel.json_body, self.EXAMPLE_FILTER)
|
||||
|
||||
def test_get_filter_non_existant(self) -> None:
|
||||
|
@ -93,7 +93,7 @@ class FilterTestCase(unittest.HomeserverTestCase):
|
|||
"GET", "/_matrix/client/r0/user/%s/filter/12382148321" % (self.user_id)
|
||||
)
|
||||
|
||||
self.assertEqual(channel.result["code"], b"404")
|
||||
self.assertEqual(channel.code, 404)
|
||||
self.assertEqual(channel.json_body["errcode"], Codes.NOT_FOUND)
|
||||
|
||||
# Currently invalid params do not have an appropriate errcode
|
||||
|
@ -103,7 +103,7 @@ class FilterTestCase(unittest.HomeserverTestCase):
|
|||
"GET", "/_matrix/client/r0/user/%s/filter/foobar" % (self.user_id)
|
||||
)
|
||||
|
||||
self.assertEqual(channel.result["code"], b"400")
|
||||
self.assertEqual(channel.code, 400)
|
||||
|
||||
# No ID also returns an invalid_id error
|
||||
def test_get_filter_no_id(self) -> None:
|
||||
|
@ -111,4 +111,4 @@ class FilterTestCase(unittest.HomeserverTestCase):
|
|||
"GET", "/_matrix/client/r0/user/%s/filter/" % (self.user_id)
|
||||
)
|
||||
|
||||
self.assertEqual(channel.result["code"], b"400")
|
||||
self.assertEqual(channel.code, 400)
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
# limitations under the License.
|
||||
import time
|
||||
import urllib.parse
|
||||
from http import HTTPStatus
|
||||
from typing import Any, Dict, List, Optional
|
||||
from unittest.mock import Mock
|
||||
from urllib.parse import urlencode
|
||||
|
@ -134,10 +133,10 @@ class LoginRestServletTestCase(unittest.HomeserverTestCase):
|
|||
channel = self.make_request(b"POST", LOGIN_URL, params)
|
||||
|
||||
if i == 5:
|
||||
self.assertEqual(channel.result["code"], b"429", channel.result)
|
||||
self.assertEqual(channel.code, 429, msg=channel.result)
|
||||
retry_after_ms = int(channel.json_body["retry_after_ms"])
|
||||
else:
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
|
||||
# Since we're ratelimiting at 1 request/min, retry_after_ms should be lower
|
||||
# than 1min.
|
||||
|
@ -152,7 +151,7 @@ class LoginRestServletTestCase(unittest.HomeserverTestCase):
|
|||
}
|
||||
channel = self.make_request(b"POST", LOGIN_URL, params)
|
||||
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
|
||||
@override_config(
|
||||
{
|
||||
|
@ -179,10 +178,10 @@ class LoginRestServletTestCase(unittest.HomeserverTestCase):
|
|||
channel = self.make_request(b"POST", LOGIN_URL, params)
|
||||
|
||||
if i == 5:
|
||||
self.assertEqual(channel.result["code"], b"429", channel.result)
|
||||
self.assertEqual(channel.code, 429, msg=channel.result)
|
||||
retry_after_ms = int(channel.json_body["retry_after_ms"])
|
||||
else:
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
|
||||
# Since we're ratelimiting at 1 request/min, retry_after_ms should be lower
|
||||
# than 1min.
|
||||
|
@ -197,7 +196,7 @@ class LoginRestServletTestCase(unittest.HomeserverTestCase):
|
|||
}
|
||||
channel = self.make_request(b"POST", LOGIN_URL, params)
|
||||
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
|
||||
@override_config(
|
||||
{
|
||||
|
@ -224,10 +223,10 @@ class LoginRestServletTestCase(unittest.HomeserverTestCase):
|
|||
channel = self.make_request(b"POST", LOGIN_URL, params)
|
||||
|
||||
if i == 5:
|
||||
self.assertEqual(channel.result["code"], b"429", channel.result)
|
||||
self.assertEqual(channel.code, 429, msg=channel.result)
|
||||
retry_after_ms = int(channel.json_body["retry_after_ms"])
|
||||
else:
|
||||
self.assertEqual(channel.result["code"], b"403", channel.result)
|
||||
self.assertEqual(channel.code, 403, msg=channel.result)
|
||||
|
||||
# Since we're ratelimiting at 1 request/min, retry_after_ms should be lower
|
||||
# than 1min.
|
||||
|
@ -242,7 +241,7 @@ class LoginRestServletTestCase(unittest.HomeserverTestCase):
|
|||
}
|
||||
channel = self.make_request(b"POST", LOGIN_URL, params)
|
||||
|
||||
self.assertEqual(channel.result["code"], b"403", channel.result)
|
||||
self.assertEqual(channel.code, 403, msg=channel.result)
|
||||
|
||||
@override_config({"session_lifetime": "24h"})
|
||||
def test_soft_logout(self) -> None:
|
||||
|
@ -250,7 +249,7 @@ class LoginRestServletTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
# we shouldn't be able to make requests without an access token
|
||||
channel = self.make_request(b"GET", TEST_URL)
|
||||
self.assertEqual(channel.result["code"], b"401", channel.result)
|
||||
self.assertEqual(channel.code, 401, msg=channel.result)
|
||||
self.assertEqual(channel.json_body["errcode"], "M_MISSING_TOKEN")
|
||||
|
||||
# log in as normal
|
||||
|
@ -261,20 +260,20 @@ class LoginRestServletTestCase(unittest.HomeserverTestCase):
|
|||
}
|
||||
channel = self.make_request(b"POST", LOGIN_URL, params)
|
||||
|
||||
self.assertEqual(channel.code, HTTPStatus.OK, channel.result)
|
||||
self.assertEqual(channel.code, 200, channel.result)
|
||||
access_token = channel.json_body["access_token"]
|
||||
device_id = channel.json_body["device_id"]
|
||||
|
||||
# we should now be able to make requests with the access token
|
||||
channel = self.make_request(b"GET", TEST_URL, access_token=access_token)
|
||||
self.assertEqual(channel.code, HTTPStatus.OK, channel.result)
|
||||
self.assertEqual(channel.code, 200, channel.result)
|
||||
|
||||
# time passes
|
||||
self.reactor.advance(24 * 3600)
|
||||
|
||||
# ... and we should be soft-logouted
|
||||
channel = self.make_request(b"GET", TEST_URL, access_token=access_token)
|
||||
self.assertEqual(channel.code, HTTPStatus.UNAUTHORIZED, channel.result)
|
||||
self.assertEqual(channel.code, 401, channel.result)
|
||||
self.assertEqual(channel.json_body["errcode"], "M_UNKNOWN_TOKEN")
|
||||
self.assertEqual(channel.json_body["soft_logout"], True)
|
||||
|
||||
|
@ -288,7 +287,7 @@ class LoginRestServletTestCase(unittest.HomeserverTestCase):
|
|||
# more requests with the expired token should still return a soft-logout
|
||||
self.reactor.advance(3600)
|
||||
channel = self.make_request(b"GET", TEST_URL, access_token=access_token)
|
||||
self.assertEqual(channel.code, HTTPStatus.UNAUTHORIZED, channel.result)
|
||||
self.assertEqual(channel.code, 401, channel.result)
|
||||
self.assertEqual(channel.json_body["errcode"], "M_UNKNOWN_TOKEN")
|
||||
self.assertEqual(channel.json_body["soft_logout"], True)
|
||||
|
||||
|
@ -296,7 +295,7 @@ class LoginRestServletTestCase(unittest.HomeserverTestCase):
|
|||
self._delete_device(access_token_2, "kermit", "monkey", device_id)
|
||||
|
||||
channel = self.make_request(b"GET", TEST_URL, access_token=access_token)
|
||||
self.assertEqual(channel.code, HTTPStatus.UNAUTHORIZED, channel.result)
|
||||
self.assertEqual(channel.code, 401, channel.result)
|
||||
self.assertEqual(channel.json_body["errcode"], "M_UNKNOWN_TOKEN")
|
||||
self.assertEqual(channel.json_body["soft_logout"], False)
|
||||
|
||||
|
@ -307,7 +306,7 @@ class LoginRestServletTestCase(unittest.HomeserverTestCase):
|
|||
channel = self.make_request(
|
||||
b"DELETE", "devices/" + device_id, access_token=access_token
|
||||
)
|
||||
self.assertEqual(channel.code, HTTPStatus.UNAUTHORIZED, channel.result)
|
||||
self.assertEqual(channel.code, 401, channel.result)
|
||||
# check it's a UI-Auth fail
|
||||
self.assertEqual(
|
||||
set(channel.json_body.keys()),
|
||||
|
@ -330,7 +329,7 @@ class LoginRestServletTestCase(unittest.HomeserverTestCase):
|
|||
access_token=access_token,
|
||||
content={"auth": auth},
|
||||
)
|
||||
self.assertEqual(channel.code, HTTPStatus.OK, channel.result)
|
||||
self.assertEqual(channel.code, 200, channel.result)
|
||||
|
||||
@override_config({"session_lifetime": "24h"})
|
||||
def test_session_can_hard_logout_after_being_soft_logged_out(self) -> None:
|
||||
|
@ -341,20 +340,20 @@ class LoginRestServletTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
# we should now be able to make requests with the access token
|
||||
channel = self.make_request(b"GET", TEST_URL, access_token=access_token)
|
||||
self.assertEqual(channel.code, HTTPStatus.OK, channel.result)
|
||||
self.assertEqual(channel.code, 200, channel.result)
|
||||
|
||||
# time passes
|
||||
self.reactor.advance(24 * 3600)
|
||||
|
||||
# ... and we should be soft-logouted
|
||||
channel = self.make_request(b"GET", TEST_URL, access_token=access_token)
|
||||
self.assertEqual(channel.code, HTTPStatus.UNAUTHORIZED, channel.result)
|
||||
self.assertEqual(channel.code, 401, channel.result)
|
||||
self.assertEqual(channel.json_body["errcode"], "M_UNKNOWN_TOKEN")
|
||||
self.assertEqual(channel.json_body["soft_logout"], True)
|
||||
|
||||
# Now try to hard logout this session
|
||||
channel = self.make_request(b"POST", "/logout", access_token=access_token)
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
|
||||
@override_config({"session_lifetime": "24h"})
|
||||
def test_session_can_hard_logout_all_sessions_after_being_soft_logged_out(
|
||||
|
@ -367,20 +366,20 @@ class LoginRestServletTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
# we should now be able to make requests with the access token
|
||||
channel = self.make_request(b"GET", TEST_URL, access_token=access_token)
|
||||
self.assertEqual(channel.code, HTTPStatus.OK, channel.result)
|
||||
self.assertEqual(channel.code, 200, channel.result)
|
||||
|
||||
# time passes
|
||||
self.reactor.advance(24 * 3600)
|
||||
|
||||
# ... and we should be soft-logouted
|
||||
channel = self.make_request(b"GET", TEST_URL, access_token=access_token)
|
||||
self.assertEqual(channel.code, HTTPStatus.UNAUTHORIZED, channel.result)
|
||||
self.assertEqual(channel.code, 401, channel.result)
|
||||
self.assertEqual(channel.json_body["errcode"], "M_UNKNOWN_TOKEN")
|
||||
self.assertEqual(channel.json_body["soft_logout"], True)
|
||||
|
||||
# Now try to hard log out all of the user's sessions
|
||||
channel = self.make_request(b"POST", "/logout/all", access_token=access_token)
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
|
||||
def test_login_with_overly_long_device_id_fails(self) -> None:
|
||||
self.register_user("mickey", "cheese")
|
||||
|
@ -466,7 +465,7 @@ class MultiSSOTestCase(unittest.HomeserverTestCase):
|
|||
def test_get_login_flows(self) -> None:
|
||||
"""GET /login should return password and SSO flows"""
|
||||
channel = self.make_request("GET", "/_matrix/client/r0/login")
|
||||
self.assertEqual(channel.code, HTTPStatus.OK, channel.result)
|
||||
self.assertEqual(channel.code, 200, channel.result)
|
||||
|
||||
expected_flow_types = [
|
||||
"m.login.cas",
|
||||
|
@ -494,14 +493,14 @@ class MultiSSOTestCase(unittest.HomeserverTestCase):
|
|||
"""/login/sso/redirect should redirect to an identity picker"""
|
||||
# first hit the redirect url, which should redirect to our idp picker
|
||||
channel = self._make_sso_redirect_request(None)
|
||||
self.assertEqual(channel.code, HTTPStatus.FOUND, channel.result)
|
||||
self.assertEqual(channel.code, 302, channel.result)
|
||||
location_headers = channel.headers.getRawHeaders("Location")
|
||||
assert location_headers
|
||||
uri = location_headers[0]
|
||||
|
||||
# hitting that picker should give us some HTML
|
||||
channel = self.make_request("GET", uri)
|
||||
self.assertEqual(channel.code, HTTPStatus.OK, channel.result)
|
||||
self.assertEqual(channel.code, 200, channel.result)
|
||||
|
||||
# parse the form to check it has fields assumed elsewhere in this class
|
||||
html = channel.result["body"].decode("utf-8")
|
||||
|
@ -530,7 +529,7 @@ class MultiSSOTestCase(unittest.HomeserverTestCase):
|
|||
+ "&idp=cas",
|
||||
shorthand=False,
|
||||
)
|
||||
self.assertEqual(channel.code, HTTPStatus.FOUND, channel.result)
|
||||
self.assertEqual(channel.code, 302, channel.result)
|
||||
location_headers = channel.headers.getRawHeaders("Location")
|
||||
assert location_headers
|
||||
cas_uri = location_headers[0]
|
||||
|
@ -555,7 +554,7 @@ class MultiSSOTestCase(unittest.HomeserverTestCase):
|
|||
+ urllib.parse.quote_plus(TEST_CLIENT_REDIRECT_URL)
|
||||
+ "&idp=saml",
|
||||
)
|
||||
self.assertEqual(channel.code, HTTPStatus.FOUND, channel.result)
|
||||
self.assertEqual(channel.code, 302, channel.result)
|
||||
location_headers = channel.headers.getRawHeaders("Location")
|
||||
assert location_headers
|
||||
saml_uri = location_headers[0]
|
||||
|
@ -579,7 +578,7 @@ class MultiSSOTestCase(unittest.HomeserverTestCase):
|
|||
+ urllib.parse.quote_plus(TEST_CLIENT_REDIRECT_URL)
|
||||
+ "&idp=oidc",
|
||||
)
|
||||
self.assertEqual(channel.code, HTTPStatus.FOUND, channel.result)
|
||||
self.assertEqual(channel.code, 302, channel.result)
|
||||
location_headers = channel.headers.getRawHeaders("Location")
|
||||
assert location_headers
|
||||
oidc_uri = location_headers[0]
|
||||
|
@ -606,7 +605,7 @@ class MultiSSOTestCase(unittest.HomeserverTestCase):
|
|||
channel = self.helper.complete_oidc_auth(oidc_uri, cookies, {"sub": "user1"})
|
||||
|
||||
# that should serve a confirmation page
|
||||
self.assertEqual(channel.code, HTTPStatus.OK, channel.result)
|
||||
self.assertEqual(channel.code, 200, channel.result)
|
||||
content_type_headers = channel.headers.getRawHeaders("Content-Type")
|
||||
assert content_type_headers
|
||||
self.assertTrue(content_type_headers[-1].startswith("text/html"))
|
||||
|
@ -634,7 +633,7 @@ class MultiSSOTestCase(unittest.HomeserverTestCase):
|
|||
"/login",
|
||||
content={"type": "m.login.token", "token": login_token},
|
||||
)
|
||||
self.assertEqual(chan.code, HTTPStatus.OK, chan.result)
|
||||
self.assertEqual(chan.code, 200, chan.result)
|
||||
self.assertEqual(chan.json_body["user_id"], "@user1:test")
|
||||
|
||||
def test_multi_sso_redirect_to_unknown(self) -> None:
|
||||
|
@ -643,18 +642,18 @@ class MultiSSOTestCase(unittest.HomeserverTestCase):
|
|||
"GET",
|
||||
"/_synapse/client/pick_idp?redirectUrl=http://x&idp=xyz",
|
||||
)
|
||||
self.assertEqual(channel.code, HTTPStatus.BAD_REQUEST, channel.result)
|
||||
self.assertEqual(channel.code, 400, channel.result)
|
||||
|
||||
def test_client_idp_redirect_to_unknown(self) -> None:
|
||||
"""If the client tries to pick an unknown IdP, return a 404"""
|
||||
channel = self._make_sso_redirect_request("xxx")
|
||||
self.assertEqual(channel.code, HTTPStatus.NOT_FOUND, channel.result)
|
||||
self.assertEqual(channel.code, 404, channel.result)
|
||||
self.assertEqual(channel.json_body["errcode"], "M_NOT_FOUND")
|
||||
|
||||
def test_client_idp_redirect_to_oidc(self) -> None:
|
||||
"""If the client pick a known IdP, redirect to it"""
|
||||
channel = self._make_sso_redirect_request("oidc")
|
||||
self.assertEqual(channel.code, HTTPStatus.FOUND, channel.result)
|
||||
self.assertEqual(channel.code, 302, channel.result)
|
||||
location_headers = channel.headers.getRawHeaders("Location")
|
||||
assert location_headers
|
||||
oidc_uri = location_headers[0]
|
||||
|
@ -765,7 +764,7 @@ class CASTestCase(unittest.HomeserverTestCase):
|
|||
channel = self.make_request("GET", cas_ticket_url)
|
||||
|
||||
# Test that the response is HTML.
|
||||
self.assertEqual(channel.code, HTTPStatus.OK, channel.result)
|
||||
self.assertEqual(channel.code, 200, channel.result)
|
||||
content_type_header_value = ""
|
||||
for header in channel.result.get("headers", []):
|
||||
if header[0] == b"Content-Type":
|
||||
|
@ -878,17 +877,17 @@ class JWTTestCase(unittest.HomeserverTestCase):
|
|||
def test_login_jwt_valid_registered(self) -> None:
|
||||
self.register_user("kermit", "monkey")
|
||||
channel = self.jwt_login({"sub": "kermit"})
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
self.assertEqual(channel.json_body["user_id"], "@kermit:test")
|
||||
|
||||
def test_login_jwt_valid_unregistered(self) -> None:
|
||||
channel = self.jwt_login({"sub": "frog"})
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
self.assertEqual(channel.json_body["user_id"], "@frog:test")
|
||||
|
||||
def test_login_jwt_invalid_signature(self) -> None:
|
||||
channel = self.jwt_login({"sub": "frog"}, "notsecret")
|
||||
self.assertEqual(channel.result["code"], b"403", channel.result)
|
||||
self.assertEqual(channel.code, 403, msg=channel.result)
|
||||
self.assertEqual(channel.json_body["errcode"], "M_FORBIDDEN")
|
||||
self.assertEqual(
|
||||
channel.json_body["error"],
|
||||
|
@ -897,7 +896,7 @@ class JWTTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
def test_login_jwt_expired(self) -> None:
|
||||
channel = self.jwt_login({"sub": "frog", "exp": 864000})
|
||||
self.assertEqual(channel.result["code"], b"403", channel.result)
|
||||
self.assertEqual(channel.code, 403, msg=channel.result)
|
||||
self.assertEqual(channel.json_body["errcode"], "M_FORBIDDEN")
|
||||
self.assertEqual(
|
||||
channel.json_body["error"],
|
||||
|
@ -907,7 +906,7 @@ class JWTTestCase(unittest.HomeserverTestCase):
|
|||
def test_login_jwt_not_before(self) -> None:
|
||||
now = int(time.time())
|
||||
channel = self.jwt_login({"sub": "frog", "nbf": now + 3600})
|
||||
self.assertEqual(channel.result["code"], b"403", channel.result)
|
||||
self.assertEqual(channel.code, 403, msg=channel.result)
|
||||
self.assertEqual(channel.json_body["errcode"], "M_FORBIDDEN")
|
||||
self.assertEqual(
|
||||
channel.json_body["error"],
|
||||
|
@ -916,7 +915,7 @@ class JWTTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
def test_login_no_sub(self) -> None:
|
||||
channel = self.jwt_login({"username": "root"})
|
||||
self.assertEqual(channel.result["code"], b"403", channel.result)
|
||||
self.assertEqual(channel.code, 403, msg=channel.result)
|
||||
self.assertEqual(channel.json_body["errcode"], "M_FORBIDDEN")
|
||||
self.assertEqual(channel.json_body["error"], "Invalid JWT")
|
||||
|
||||
|
@ -925,12 +924,12 @@ class JWTTestCase(unittest.HomeserverTestCase):
|
|||
"""Test validating the issuer claim."""
|
||||
# A valid issuer.
|
||||
channel = self.jwt_login({"sub": "kermit", "iss": "test-issuer"})
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
self.assertEqual(channel.json_body["user_id"], "@kermit:test")
|
||||
|
||||
# An invalid issuer.
|
||||
channel = self.jwt_login({"sub": "kermit", "iss": "invalid"})
|
||||
self.assertEqual(channel.result["code"], b"403", channel.result)
|
||||
self.assertEqual(channel.code, 403, msg=channel.result)
|
||||
self.assertEqual(channel.json_body["errcode"], "M_FORBIDDEN")
|
||||
self.assertEqual(
|
||||
channel.json_body["error"],
|
||||
|
@ -939,7 +938,7 @@ class JWTTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
# Not providing an issuer.
|
||||
channel = self.jwt_login({"sub": "kermit"})
|
||||
self.assertEqual(channel.result["code"], b"403", channel.result)
|
||||
self.assertEqual(channel.code, 403, msg=channel.result)
|
||||
self.assertEqual(channel.json_body["errcode"], "M_FORBIDDEN")
|
||||
self.assertEqual(
|
||||
channel.json_body["error"],
|
||||
|
@ -949,7 +948,7 @@ class JWTTestCase(unittest.HomeserverTestCase):
|
|||
def test_login_iss_no_config(self) -> None:
|
||||
"""Test providing an issuer claim without requiring it in the configuration."""
|
||||
channel = self.jwt_login({"sub": "kermit", "iss": "invalid"})
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
self.assertEqual(channel.json_body["user_id"], "@kermit:test")
|
||||
|
||||
@override_config({"jwt_config": {**base_config, "audiences": ["test-audience"]}})
|
||||
|
@ -957,12 +956,12 @@ class JWTTestCase(unittest.HomeserverTestCase):
|
|||
"""Test validating the audience claim."""
|
||||
# A valid audience.
|
||||
channel = self.jwt_login({"sub": "kermit", "aud": "test-audience"})
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
self.assertEqual(channel.json_body["user_id"], "@kermit:test")
|
||||
|
||||
# An invalid audience.
|
||||
channel = self.jwt_login({"sub": "kermit", "aud": "invalid"})
|
||||
self.assertEqual(channel.result["code"], b"403", channel.result)
|
||||
self.assertEqual(channel.code, 403, msg=channel.result)
|
||||
self.assertEqual(channel.json_body["errcode"], "M_FORBIDDEN")
|
||||
self.assertEqual(
|
||||
channel.json_body["error"],
|
||||
|
@ -971,7 +970,7 @@ class JWTTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
# Not providing an audience.
|
||||
channel = self.jwt_login({"sub": "kermit"})
|
||||
self.assertEqual(channel.result["code"], b"403", channel.result)
|
||||
self.assertEqual(channel.code, 403, msg=channel.result)
|
||||
self.assertEqual(channel.json_body["errcode"], "M_FORBIDDEN")
|
||||
self.assertEqual(
|
||||
channel.json_body["error"],
|
||||
|
@ -981,7 +980,7 @@ class JWTTestCase(unittest.HomeserverTestCase):
|
|||
def test_login_aud_no_config(self) -> None:
|
||||
"""Test providing an audience without requiring it in the configuration."""
|
||||
channel = self.jwt_login({"sub": "kermit", "aud": "invalid"})
|
||||
self.assertEqual(channel.result["code"], b"403", channel.result)
|
||||
self.assertEqual(channel.code, 403, msg=channel.result)
|
||||
self.assertEqual(channel.json_body["errcode"], "M_FORBIDDEN")
|
||||
self.assertEqual(
|
||||
channel.json_body["error"],
|
||||
|
@ -991,20 +990,20 @@ class JWTTestCase(unittest.HomeserverTestCase):
|
|||
def test_login_default_sub(self) -> None:
|
||||
"""Test reading user ID from the default subject claim."""
|
||||
channel = self.jwt_login({"sub": "kermit"})
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
self.assertEqual(channel.json_body["user_id"], "@kermit:test")
|
||||
|
||||
@override_config({"jwt_config": {**base_config, "subject_claim": "username"}})
|
||||
def test_login_custom_sub(self) -> None:
|
||||
"""Test reading user ID from a custom subject claim."""
|
||||
channel = self.jwt_login({"username": "frog"})
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
self.assertEqual(channel.json_body["user_id"], "@frog:test")
|
||||
|
||||
def test_login_no_token(self) -> None:
|
||||
params = {"type": "org.matrix.login.jwt"}
|
||||
channel = self.make_request(b"POST", LOGIN_URL, params)
|
||||
self.assertEqual(channel.result["code"], b"403", channel.result)
|
||||
self.assertEqual(channel.code, 403, msg=channel.result)
|
||||
self.assertEqual(channel.json_body["errcode"], "M_FORBIDDEN")
|
||||
self.assertEqual(channel.json_body["error"], "Token field for JWT is missing")
|
||||
|
||||
|
@ -1086,12 +1085,12 @@ class JWTPubKeyTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
def test_login_jwt_valid(self) -> None:
|
||||
channel = self.jwt_login({"sub": "kermit"})
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
self.assertEqual(channel.json_body["user_id"], "@kermit:test")
|
||||
|
||||
def test_login_jwt_invalid_signature(self) -> None:
|
||||
channel = self.jwt_login({"sub": "frog"}, self.bad_privatekey)
|
||||
self.assertEqual(channel.result["code"], b"403", channel.result)
|
||||
self.assertEqual(channel.code, 403, msg=channel.result)
|
||||
self.assertEqual(channel.json_body["errcode"], "M_FORBIDDEN")
|
||||
self.assertEqual(
|
||||
channel.json_body["error"],
|
||||
|
@ -1152,7 +1151,7 @@ class AppserviceLoginRestServletTestCase(unittest.HomeserverTestCase):
|
|||
b"POST", LOGIN_URL, params, access_token=self.service.token
|
||||
)
|
||||
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
|
||||
def test_login_appservice_user_bot(self) -> None:
|
||||
"""Test that the appservice bot can use /login"""
|
||||
|
@ -1166,7 +1165,7 @@ class AppserviceLoginRestServletTestCase(unittest.HomeserverTestCase):
|
|||
b"POST", LOGIN_URL, params, access_token=self.service.token
|
||||
)
|
||||
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
|
||||
def test_login_appservice_wrong_user(self) -> None:
|
||||
"""Test that non-as users cannot login with the as token"""
|
||||
|
@ -1180,7 +1179,7 @@ class AppserviceLoginRestServletTestCase(unittest.HomeserverTestCase):
|
|||
b"POST", LOGIN_URL, params, access_token=self.service.token
|
||||
)
|
||||
|
||||
self.assertEqual(channel.result["code"], b"403", channel.result)
|
||||
self.assertEqual(channel.code, 403, msg=channel.result)
|
||||
|
||||
def test_login_appservice_wrong_as(self) -> None:
|
||||
"""Test that as users cannot login with wrong as token"""
|
||||
|
@ -1194,7 +1193,7 @@ class AppserviceLoginRestServletTestCase(unittest.HomeserverTestCase):
|
|||
b"POST", LOGIN_URL, params, access_token=self.another_service.token
|
||||
)
|
||||
|
||||
self.assertEqual(channel.result["code"], b"403", channel.result)
|
||||
self.assertEqual(channel.code, 403, msg=channel.result)
|
||||
|
||||
def test_login_appservice_no_token(self) -> None:
|
||||
"""Test that users must provide a token when using the appservice
|
||||
|
@ -1208,7 +1207,7 @@ class AppserviceLoginRestServletTestCase(unittest.HomeserverTestCase):
|
|||
}
|
||||
channel = self.make_request(b"POST", LOGIN_URL, params)
|
||||
|
||||
self.assertEqual(channel.result["code"], b"401", channel.result)
|
||||
self.assertEqual(channel.code, 401, msg=channel.result)
|
||||
|
||||
|
||||
@skip_unless(HAS_OIDC, "requires OIDC")
|
||||
|
@ -1246,7 +1245,7 @@ class UsernamePickerTestCase(HomeserverTestCase):
|
|||
)
|
||||
|
||||
# that should redirect to the username picker
|
||||
self.assertEqual(channel.code, HTTPStatus.FOUND, channel.result)
|
||||
self.assertEqual(channel.code, 302, channel.result)
|
||||
location_headers = channel.headers.getRawHeaders("Location")
|
||||
assert location_headers
|
||||
picker_url = location_headers[0]
|
||||
|
@ -1290,7 +1289,7 @@ class UsernamePickerTestCase(HomeserverTestCase):
|
|||
("Content-Length", str(len(content))),
|
||||
],
|
||||
)
|
||||
self.assertEqual(chan.code, HTTPStatus.FOUND, chan.result)
|
||||
self.assertEqual(chan.code, 302, chan.result)
|
||||
location_headers = chan.headers.getRawHeaders("Location")
|
||||
assert location_headers
|
||||
|
||||
|
@ -1300,7 +1299,7 @@ class UsernamePickerTestCase(HomeserverTestCase):
|
|||
path=location_headers[0],
|
||||
custom_headers=[("Cookie", "username_mapping_session=" + session_id)],
|
||||
)
|
||||
self.assertEqual(chan.code, HTTPStatus.FOUND, chan.result)
|
||||
self.assertEqual(chan.code, 302, chan.result)
|
||||
location_headers = chan.headers.getRawHeaders("Location")
|
||||
assert location_headers
|
||||
|
||||
|
@ -1325,5 +1324,5 @@ class UsernamePickerTestCase(HomeserverTestCase):
|
|||
"/login",
|
||||
content={"type": "m.login.token", "token": login_token},
|
||||
)
|
||||
self.assertEqual(chan.code, HTTPStatus.OK, chan.result)
|
||||
self.assertEqual(chan.code, 200, chan.result)
|
||||
self.assertEqual(chan.json_body["user_id"], "@bobby:test")
|
||||
|
|
|
@ -76,12 +76,12 @@ class RedactionsTestCase(HomeserverTestCase):
|
|||
path = "/_matrix/client/r0/rooms/%s/redact/%s" % (room_id, event_id)
|
||||
|
||||
channel = self.make_request("POST", path, content={}, access_token=access_token)
|
||||
self.assertEqual(int(channel.result["code"]), expect_code)
|
||||
self.assertEqual(channel.code, expect_code)
|
||||
return channel.json_body
|
||||
|
||||
def _sync_room_timeline(self, access_token: str, room_id: str) -> List[JsonDict]:
|
||||
channel = self.make_request("GET", "sync", access_token=self.mod_access_token)
|
||||
self.assertEqual(channel.result["code"], b"200")
|
||||
self.assertEqual(channel.code, 200)
|
||||
room_sync = channel.json_body["rooms"]["join"][room_id]
|
||||
return room_sync["timeline"]["events"]
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
|
|||
b"POST", self.url + b"?access_token=i_am_an_app_service", request_data
|
||||
)
|
||||
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
det_data = {"user_id": user_id, "home_server": self.hs.hostname}
|
||||
self.assertDictContainsSubset(det_data, channel.json_body)
|
||||
|
||||
|
@ -91,7 +91,7 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
|
|||
b"POST", self.url + b"?access_token=i_am_an_app_service", request_data
|
||||
)
|
||||
|
||||
self.assertEqual(channel.result["code"], b"400", channel.result)
|
||||
self.assertEqual(channel.code, 400, msg=channel.result)
|
||||
|
||||
def test_POST_appservice_registration_invalid(self) -> None:
|
||||
self.appservice = None # no application service exists
|
||||
|
@ -100,20 +100,20 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
|
|||
b"POST", self.url + b"?access_token=i_am_an_app_service", request_data
|
||||
)
|
||||
|
||||
self.assertEqual(channel.result["code"], b"401", channel.result)
|
||||
self.assertEqual(channel.code, 401, msg=channel.result)
|
||||
|
||||
def test_POST_bad_password(self) -> None:
|
||||
request_data = {"username": "kermit", "password": 666}
|
||||
channel = self.make_request(b"POST", self.url, request_data)
|
||||
|
||||
self.assertEqual(channel.result["code"], b"400", channel.result)
|
||||
self.assertEqual(channel.code, 400, msg=channel.result)
|
||||
self.assertEqual(channel.json_body["error"], "Invalid password")
|
||||
|
||||
def test_POST_bad_username(self) -> None:
|
||||
request_data = {"username": 777, "password": "monkey"}
|
||||
channel = self.make_request(b"POST", self.url, request_data)
|
||||
|
||||
self.assertEqual(channel.result["code"], b"400", channel.result)
|
||||
self.assertEqual(channel.code, 400, msg=channel.result)
|
||||
self.assertEqual(channel.json_body["error"], "Invalid username")
|
||||
|
||||
def test_POST_user_valid(self) -> None:
|
||||
|
@ -132,7 +132,7 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
|
|||
"home_server": self.hs.hostname,
|
||||
"device_id": device_id,
|
||||
}
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
self.assertDictContainsSubset(det_data, channel.json_body)
|
||||
|
||||
@override_config({"enable_registration": False})
|
||||
|
@ -142,7 +142,7 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
channel = self.make_request(b"POST", self.url, request_data)
|
||||
|
||||
self.assertEqual(channel.result["code"], b"403", channel.result)
|
||||
self.assertEqual(channel.code, 403, msg=channel.result)
|
||||
self.assertEqual(channel.json_body["error"], "Registration has been disabled")
|
||||
self.assertEqual(channel.json_body["errcode"], "M_FORBIDDEN")
|
||||
|
||||
|
@ -153,7 +153,7 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
|
|||
channel = self.make_request(b"POST", self.url + b"?kind=guest", b"{}")
|
||||
|
||||
det_data = {"home_server": self.hs.hostname, "device_id": "guest_device"}
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
self.assertDictContainsSubset(det_data, channel.json_body)
|
||||
|
||||
def test_POST_disabled_guest_registration(self) -> None:
|
||||
|
@ -161,7 +161,7 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
channel = self.make_request(b"POST", self.url + b"?kind=guest", b"{}")
|
||||
|
||||
self.assertEqual(channel.result["code"], b"403", channel.result)
|
||||
self.assertEqual(channel.code, 403, msg=channel.result)
|
||||
self.assertEqual(channel.json_body["error"], "Guest access is disabled")
|
||||
|
||||
@override_config({"rc_registration": {"per_second": 0.17, "burst_count": 5}})
|
||||
|
@ -171,16 +171,16 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
|
|||
channel = self.make_request(b"POST", url, b"{}")
|
||||
|
||||
if i == 5:
|
||||
self.assertEqual(channel.result["code"], b"429", channel.result)
|
||||
self.assertEqual(channel.code, 429, msg=channel.result)
|
||||
retry_after_ms = int(channel.json_body["retry_after_ms"])
|
||||
else:
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
|
||||
self.reactor.advance(retry_after_ms / 1000.0 + 1.0)
|
||||
|
||||
channel = self.make_request(b"POST", self.url + b"?kind=guest", b"{}")
|
||||
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
|
||||
@override_config({"rc_registration": {"per_second": 0.17, "burst_count": 5}})
|
||||
def test_POST_ratelimiting(self) -> None:
|
||||
|
@ -194,16 +194,16 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
|
|||
channel = self.make_request(b"POST", self.url, request_data)
|
||||
|
||||
if i == 5:
|
||||
self.assertEqual(channel.result["code"], b"429", channel.result)
|
||||
self.assertEqual(channel.code, 429, msg=channel.result)
|
||||
retry_after_ms = int(channel.json_body["retry_after_ms"])
|
||||
else:
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
|
||||
self.reactor.advance(retry_after_ms / 1000.0 + 1.0)
|
||||
|
||||
channel = self.make_request(b"POST", self.url + b"?kind=guest", b"{}")
|
||||
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
|
||||
@override_config({"registration_requires_token": True})
|
||||
def test_POST_registration_requires_token(self) -> None:
|
||||
|
@ -231,7 +231,7 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
# Request without auth to get flows and session
|
||||
channel = self.make_request(b"POST", self.url, params)
|
||||
self.assertEqual(channel.result["code"], b"401", channel.result)
|
||||
self.assertEqual(channel.code, 401, msg=channel.result)
|
||||
flows = channel.json_body["flows"]
|
||||
# Synapse adds a dummy stage to differentiate flows where otherwise one
|
||||
# flow would be a subset of another flow.
|
||||
|
@ -248,7 +248,7 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
|
|||
"session": session,
|
||||
}
|
||||
channel = self.make_request(b"POST", self.url, params)
|
||||
self.assertEqual(channel.result["code"], b"401", channel.result)
|
||||
self.assertEqual(channel.code, 401, msg=channel.result)
|
||||
completed = channel.json_body["completed"]
|
||||
self.assertCountEqual([LoginType.REGISTRATION_TOKEN], completed)
|
||||
|
||||
|
@ -263,7 +263,7 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
|
|||
"home_server": self.hs.hostname,
|
||||
"device_id": device_id,
|
||||
}
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
self.assertDictContainsSubset(det_data, channel.json_body)
|
||||
|
||||
# Check the `completed` counter has been incremented and pending is 0
|
||||
|
@ -293,21 +293,21 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
|
|||
"session": session,
|
||||
}
|
||||
channel = self.make_request(b"POST", self.url, params)
|
||||
self.assertEqual(channel.result["code"], b"401", channel.result)
|
||||
self.assertEqual(channel.code, 401, msg=channel.result)
|
||||
self.assertEqual(channel.json_body["errcode"], Codes.MISSING_PARAM)
|
||||
self.assertEqual(channel.json_body["completed"], [])
|
||||
|
||||
# Test with non-string (invalid)
|
||||
params["auth"]["token"] = 1234
|
||||
channel = self.make_request(b"POST", self.url, params)
|
||||
self.assertEqual(channel.result["code"], b"401", channel.result)
|
||||
self.assertEqual(channel.code, 401, msg=channel.result)
|
||||
self.assertEqual(channel.json_body["errcode"], Codes.INVALID_PARAM)
|
||||
self.assertEqual(channel.json_body["completed"], [])
|
||||
|
||||
# Test with unknown token (invalid)
|
||||
params["auth"]["token"] = "1234"
|
||||
channel = self.make_request(b"POST", self.url, params)
|
||||
self.assertEqual(channel.result["code"], b"401", channel.result)
|
||||
self.assertEqual(channel.code, 401, msg=channel.result)
|
||||
self.assertEqual(channel.json_body["errcode"], Codes.UNAUTHORIZED)
|
||||
self.assertEqual(channel.json_body["completed"], [])
|
||||
|
||||
|
@ -361,7 +361,7 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
|
|||
"session": session2,
|
||||
}
|
||||
channel = self.make_request(b"POST", self.url, params2)
|
||||
self.assertEqual(channel.result["code"], b"401", channel.result)
|
||||
self.assertEqual(channel.code, 401, msg=channel.result)
|
||||
self.assertEqual(channel.json_body["errcode"], Codes.UNAUTHORIZED)
|
||||
self.assertEqual(channel.json_body["completed"], [])
|
||||
|
||||
|
@ -381,7 +381,7 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
# Check auth still fails when using token with session2
|
||||
channel = self.make_request(b"POST", self.url, params2)
|
||||
self.assertEqual(channel.result["code"], b"401", channel.result)
|
||||
self.assertEqual(channel.code, 401, msg=channel.result)
|
||||
self.assertEqual(channel.json_body["errcode"], Codes.UNAUTHORIZED)
|
||||
self.assertEqual(channel.json_body["completed"], [])
|
||||
|
||||
|
@ -415,7 +415,7 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
|
|||
"session": session,
|
||||
}
|
||||
channel = self.make_request(b"POST", self.url, params)
|
||||
self.assertEqual(channel.result["code"], b"401", channel.result)
|
||||
self.assertEqual(channel.code, 401, msg=channel.result)
|
||||
self.assertEqual(channel.json_body["errcode"], Codes.UNAUTHORIZED)
|
||||
self.assertEqual(channel.json_body["completed"], [])
|
||||
|
||||
|
@ -570,7 +570,7 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
def test_advertised_flows(self) -> None:
|
||||
channel = self.make_request(b"POST", self.url, b"{}")
|
||||
self.assertEqual(channel.result["code"], b"401", channel.result)
|
||||
self.assertEqual(channel.code, 401, msg=channel.result)
|
||||
flows = channel.json_body["flows"]
|
||||
|
||||
# with the stock config, we only expect the dummy flow
|
||||
|
@ -593,7 +593,7 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
|
|||
)
|
||||
def test_advertised_flows_captcha_and_terms_and_3pids(self) -> None:
|
||||
channel = self.make_request(b"POST", self.url, b"{}")
|
||||
self.assertEqual(channel.result["code"], b"401", channel.result)
|
||||
self.assertEqual(channel.code, 401, msg=channel.result)
|
||||
flows = channel.json_body["flows"]
|
||||
|
||||
self.assertCountEqual(
|
||||
|
@ -625,7 +625,7 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
|
|||
)
|
||||
def test_advertised_flows_no_msisdn_email_required(self) -> None:
|
||||
channel = self.make_request(b"POST", self.url, b"{}")
|
||||
self.assertEqual(channel.result["code"], b"401", channel.result)
|
||||
self.assertEqual(channel.code, 401, msg=channel.result)
|
||||
flows = channel.json_body["flows"]
|
||||
|
||||
# with the stock config, we expect all four combinations of 3pid
|
||||
|
@ -797,13 +797,13 @@ class AccountValidityTestCase(unittest.HomeserverTestCase):
|
|||
# endpoint.
|
||||
channel = self.make_request(b"GET", "/sync", access_token=tok)
|
||||
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
|
||||
self.reactor.advance(datetime.timedelta(weeks=1).total_seconds())
|
||||
|
||||
channel = self.make_request(b"GET", "/sync", access_token=tok)
|
||||
|
||||
self.assertEqual(channel.result["code"], b"403", channel.result)
|
||||
self.assertEqual(channel.code, 403, msg=channel.result)
|
||||
self.assertEqual(
|
||||
channel.json_body["errcode"], Codes.EXPIRED_ACCOUNT, channel.result
|
||||
)
|
||||
|
@ -823,12 +823,12 @@ class AccountValidityTestCase(unittest.HomeserverTestCase):
|
|||
url = "/_synapse/admin/v1/account_validity/validity"
|
||||
request_data = {"user_id": user_id}
|
||||
channel = self.make_request(b"POST", url, request_data, access_token=admin_tok)
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
|
||||
# The specific endpoint doesn't matter, all we need is an authenticated
|
||||
# endpoint.
|
||||
channel = self.make_request(b"GET", "/sync", access_token=tok)
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
|
||||
def test_manual_expire(self) -> None:
|
||||
user_id = self.register_user("kermit", "monkey")
|
||||
|
@ -844,12 +844,12 @@ class AccountValidityTestCase(unittest.HomeserverTestCase):
|
|||
"enable_renewal_emails": False,
|
||||
}
|
||||
channel = self.make_request(b"POST", url, request_data, access_token=admin_tok)
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
|
||||
# The specific endpoint doesn't matter, all we need is an authenticated
|
||||
# endpoint.
|
||||
channel = self.make_request(b"GET", "/sync", access_token=tok)
|
||||
self.assertEqual(channel.result["code"], b"403", channel.result)
|
||||
self.assertEqual(channel.code, 403, msg=channel.result)
|
||||
self.assertEqual(
|
||||
channel.json_body["errcode"], Codes.EXPIRED_ACCOUNT, channel.result
|
||||
)
|
||||
|
@ -868,18 +868,18 @@ class AccountValidityTestCase(unittest.HomeserverTestCase):
|
|||
"enable_renewal_emails": False,
|
||||
}
|
||||
channel = self.make_request(b"POST", url, request_data, access_token=admin_tok)
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
|
||||
# Try to log the user out
|
||||
channel = self.make_request(b"POST", "/logout", access_token=tok)
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
|
||||
# Log the user in again (allowed for expired accounts)
|
||||
tok = self.login("kermit", "monkey")
|
||||
|
||||
# Try to log out all of the user's sessions
|
||||
channel = self.make_request(b"POST", "/logout/all", access_token=tok)
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
|
||||
|
||||
class AccountValidityRenewalByEmailTestCase(unittest.HomeserverTestCase):
|
||||
|
@ -954,7 +954,7 @@ class AccountValidityRenewalByEmailTestCase(unittest.HomeserverTestCase):
|
|||
renewal_token = self.get_success(self.store.get_renewal_token_for_user(user_id))
|
||||
url = "/_matrix/client/unstable/account_validity/renew?token=%s" % renewal_token
|
||||
channel = self.make_request(b"GET", url)
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
|
||||
# Check that we're getting HTML back.
|
||||
content_type = channel.headers.getRawHeaders(b"Content-Type")
|
||||
|
@ -972,7 +972,7 @@ class AccountValidityRenewalByEmailTestCase(unittest.HomeserverTestCase):
|
|||
# Move 1 day forward. Try to renew with the same token again.
|
||||
url = "/_matrix/client/unstable/account_validity/renew?token=%s" % renewal_token
|
||||
channel = self.make_request(b"GET", url)
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
|
||||
# Check that we're getting HTML back.
|
||||
content_type = channel.headers.getRawHeaders(b"Content-Type")
|
||||
|
@ -992,14 +992,14 @@ class AccountValidityRenewalByEmailTestCase(unittest.HomeserverTestCase):
|
|||
# succeed.
|
||||
self.reactor.advance(datetime.timedelta(days=3).total_seconds())
|
||||
channel = self.make_request(b"GET", "/sync", access_token=tok)
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
|
||||
def test_renewal_invalid_token(self) -> None:
|
||||
# Hit the renewal endpoint with an invalid token and check that it behaves as
|
||||
# expected, i.e. that it responds with 404 Not Found and the correct HTML.
|
||||
url = "/_matrix/client/unstable/account_validity/renew?token=123"
|
||||
channel = self.make_request(b"GET", url)
|
||||
self.assertEqual(channel.result["code"], b"404", channel.result)
|
||||
self.assertEqual(channel.code, 404, msg=channel.result)
|
||||
|
||||
# Check that we're getting HTML back.
|
||||
content_type = channel.headers.getRawHeaders(b"Content-Type")
|
||||
|
@ -1023,7 +1023,7 @@ class AccountValidityRenewalByEmailTestCase(unittest.HomeserverTestCase):
|
|||
"/_matrix/client/unstable/account_validity/send_mail",
|
||||
access_token=tok,
|
||||
)
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
|
||||
self.assertEqual(len(self.email_attempts), 1)
|
||||
|
||||
|
@ -1096,7 +1096,7 @@ class AccountValidityRenewalByEmailTestCase(unittest.HomeserverTestCase):
|
|||
"/_matrix/client/unstable/account_validity/send_mail",
|
||||
access_token=tok,
|
||||
)
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
|
||||
self.assertEqual(len(self.email_attempts), 1)
|
||||
|
||||
|
@ -1176,7 +1176,7 @@ class RegistrationTokenValidityRestServletTestCase(unittest.HomeserverTestCase):
|
|||
b"GET",
|
||||
f"{self.url}?token={token}",
|
||||
)
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
self.assertEqual(channel.json_body["valid"], True)
|
||||
|
||||
def test_GET_token_invalid(self) -> None:
|
||||
|
@ -1185,7 +1185,7 @@ class RegistrationTokenValidityRestServletTestCase(unittest.HomeserverTestCase):
|
|||
b"GET",
|
||||
f"{self.url}?token={token}",
|
||||
)
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
self.assertEqual(channel.json_body["valid"], False)
|
||||
|
||||
@override_config(
|
||||
|
@ -1201,10 +1201,10 @@ class RegistrationTokenValidityRestServletTestCase(unittest.HomeserverTestCase):
|
|||
)
|
||||
|
||||
if i == 5:
|
||||
self.assertEqual(channel.result["code"], b"429", channel.result)
|
||||
self.assertEqual(channel.code, 429, msg=channel.result)
|
||||
retry_after_ms = int(channel.json_body["retry_after_ms"])
|
||||
else:
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
|
||||
self.reactor.advance(retry_after_ms / 1000.0 + 1.0)
|
||||
|
||||
|
@ -1212,4 +1212,4 @@ class RegistrationTokenValidityRestServletTestCase(unittest.HomeserverTestCase):
|
|||
b"GET",
|
||||
f"{self.url}?token={token}",
|
||||
)
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||
|
|
|
@ -77,6 +77,4 @@ class ReportEventTestCase(unittest.HomeserverTestCase):
|
|||
channel = self.make_request(
|
||||
"POST", self.report_path, data, access_token=self.other_user_tok
|
||||
)
|
||||
self.assertEqual(
|
||||
response_status, int(channel.result["code"]), msg=channel.result["body"]
|
||||
)
|
||||
self.assertEqual(response_status, channel.code, msg=channel.result["body"])
|
||||
|
|
|
@ -38,7 +38,6 @@ from tests.federation.transport.test_knocking import (
|
|||
KnockingStrippedStateEventHelperMixin,
|
||||
)
|
||||
from tests.server import TimedOutException
|
||||
from tests.unittest import override_config
|
||||
|
||||
|
||||
class FilterTestCase(unittest.HomeserverTestCase):
|
||||
|
@ -390,6 +389,12 @@ class ReadReceiptsTestCase(unittest.HomeserverTestCase):
|
|||
sync.register_servlets,
|
||||
]
|
||||
|
||||
def make_homeserver(self, reactor: MemoryReactor, clock: Clock) -> HomeServer:
|
||||
config = self.default_config()
|
||||
config["experimental_features"] = {"msc2285_enabled": True}
|
||||
|
||||
return self.setup_test_homeserver(config=config)
|
||||
|
||||
def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None:
|
||||
self.url = "/sync?since=%s"
|
||||
self.next_batch = "s0"
|
||||
|
@ -408,15 +413,17 @@ class ReadReceiptsTestCase(unittest.HomeserverTestCase):
|
|||
# Join the second user
|
||||
self.helper.join(room=self.room_id, user=self.user2, tok=self.tok2)
|
||||
|
||||
@override_config({"experimental_features": {"msc2285_enabled": True}})
|
||||
def test_private_read_receipts(self) -> None:
|
||||
@parameterized.expand(
|
||||
[ReceiptTypes.READ_PRIVATE, ReceiptTypes.UNSTABLE_READ_PRIVATE]
|
||||
)
|
||||
def test_private_read_receipts(self, receipt_type: str) -> None:
|
||||
# Send a message as the first user
|
||||
res = self.helper.send(self.room_id, body="hello", tok=self.tok)
|
||||
|
||||
# Send a private read receipt to tell the server the first user's message was read
|
||||
channel = self.make_request(
|
||||
"POST",
|
||||
f"/rooms/{self.room_id}/receipt/org.matrix.msc2285.read.private/{res['event_id']}",
|
||||
f"/rooms/{self.room_id}/receipt/{receipt_type}/{res['event_id']}",
|
||||
{},
|
||||
access_token=self.tok2,
|
||||
)
|
||||
|
@ -425,8 +432,10 @@ class ReadReceiptsTestCase(unittest.HomeserverTestCase):
|
|||
# Test that the first user can't see the other user's private read receipt
|
||||
self.assertIsNone(self._get_read_receipt())
|
||||
|
||||
@override_config({"experimental_features": {"msc2285_enabled": True}})
|
||||
def test_public_receipt_can_override_private(self) -> None:
|
||||
@parameterized.expand(
|
||||
[ReceiptTypes.READ_PRIVATE, ReceiptTypes.UNSTABLE_READ_PRIVATE]
|
||||
)
|
||||
def test_public_receipt_can_override_private(self, receipt_type: str) -> None:
|
||||
"""
|
||||
Sending a public read receipt to the same event which has a private read
|
||||
receipt should cause that receipt to become public.
|
||||
|
@ -437,7 +446,7 @@ class ReadReceiptsTestCase(unittest.HomeserverTestCase):
|
|||
# Send a private read receipt
|
||||
channel = self.make_request(
|
||||
"POST",
|
||||
f"/rooms/{self.room_id}/receipt/{ReceiptTypes.READ_PRIVATE}/{res['event_id']}",
|
||||
f"/rooms/{self.room_id}/receipt/{receipt_type}/{res['event_id']}",
|
||||
{},
|
||||
access_token=self.tok2,
|
||||
)
|
||||
|
@ -456,8 +465,10 @@ class ReadReceiptsTestCase(unittest.HomeserverTestCase):
|
|||
# Test that we did override the private read receipt
|
||||
self.assertNotEqual(self._get_read_receipt(), None)
|
||||
|
||||
@override_config({"experimental_features": {"msc2285_enabled": True}})
|
||||
def test_private_receipt_cannot_override_public(self) -> None:
|
||||
@parameterized.expand(
|
||||
[ReceiptTypes.READ_PRIVATE, ReceiptTypes.UNSTABLE_READ_PRIVATE]
|
||||
)
|
||||
def test_private_receipt_cannot_override_public(self, receipt_type: str) -> None:
|
||||
"""
|
||||
Sending a private read receipt to the same event which has a public read
|
||||
receipt should cause no change.
|
||||
|
@ -478,7 +489,7 @@ class ReadReceiptsTestCase(unittest.HomeserverTestCase):
|
|||
# Send a private read receipt
|
||||
channel = self.make_request(
|
||||
"POST",
|
||||
f"/rooms/{self.room_id}/receipt/{ReceiptTypes.READ_PRIVATE}/{res['event_id']}",
|
||||
f"/rooms/{self.room_id}/receipt/{receipt_type}/{res['event_id']}",
|
||||
{},
|
||||
access_token=self.tok2,
|
||||
)
|
||||
|
@ -590,7 +601,10 @@ class UnreadMessagesTestCase(unittest.HomeserverTestCase):
|
|||
tok=self.tok,
|
||||
)
|
||||
|
||||
def test_unread_counts(self) -> None:
|
||||
@parameterized.expand(
|
||||
[ReceiptTypes.READ_PRIVATE, ReceiptTypes.UNSTABLE_READ_PRIVATE]
|
||||
)
|
||||
def test_unread_counts(self, receipt_type: str) -> None:
|
||||
"""Tests that /sync returns the right value for the unread count (MSC2654)."""
|
||||
|
||||
# Check that our own messages don't increase the unread count.
|
||||
|
@ -624,7 +638,7 @@ class UnreadMessagesTestCase(unittest.HomeserverTestCase):
|
|||
# Send a read receipt to tell the server we've read the latest event.
|
||||
channel = self.make_request(
|
||||
"POST",
|
||||
f"/rooms/{self.room_id}/receipt/org.matrix.msc2285.read.private/{res['event_id']}",
|
||||
f"/rooms/{self.room_id}/receipt/{receipt_type}/{res['event_id']}",
|
||||
{},
|
||||
access_token=self.tok,
|
||||
)
|
||||
|
@ -700,7 +714,7 @@ class UnreadMessagesTestCase(unittest.HomeserverTestCase):
|
|||
self._check_unread_count(5)
|
||||
res2 = self.helper.send(self.room_id, "hello", tok=self.tok2)
|
||||
|
||||
# Make sure both m.read and org.matrix.msc2285.read.private advance
|
||||
# Make sure both m.read and m.read.private advance
|
||||
channel = self.make_request(
|
||||
"POST",
|
||||
f"/rooms/{self.room_id}/receipt/m.read/{res1['event_id']}",
|
||||
|
@ -712,16 +726,22 @@ class UnreadMessagesTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
channel = self.make_request(
|
||||
"POST",
|
||||
f"/rooms/{self.room_id}/receipt/org.matrix.msc2285.read.private/{res2['event_id']}",
|
||||
f"/rooms/{self.room_id}/receipt/{receipt_type}/{res2['event_id']}",
|
||||
{},
|
||||
access_token=self.tok,
|
||||
)
|
||||
self.assertEqual(channel.code, 200, channel.json_body)
|
||||
self._check_unread_count(0)
|
||||
|
||||
# We test for both receipt types that influence notification counts
|
||||
@parameterized.expand([ReceiptTypes.READ, ReceiptTypes.READ_PRIVATE])
|
||||
def test_read_receipts_only_go_down(self, receipt_type: ReceiptTypes) -> None:
|
||||
# We test for all three receipt types that influence notification counts
|
||||
@parameterized.expand(
|
||||
[
|
||||
ReceiptTypes.READ,
|
||||
ReceiptTypes.READ_PRIVATE,
|
||||
ReceiptTypes.UNSTABLE_READ_PRIVATE,
|
||||
]
|
||||
)
|
||||
def test_read_receipts_only_go_down(self, receipt_type: str) -> None:
|
||||
# Join the new user
|
||||
self.helper.join(room=self.room_id, user=self.user2, tok=self.tok2)
|
||||
|
||||
|
@ -739,11 +759,11 @@ class UnreadMessagesTestCase(unittest.HomeserverTestCase):
|
|||
self.assertEqual(channel.code, 200, channel.json_body)
|
||||
self._check_unread_count(0)
|
||||
|
||||
# Make sure neither m.read nor org.matrix.msc2285.read.private make the
|
||||
# Make sure neither m.read nor m.read.private make the
|
||||
# read receipt go up to an older event
|
||||
channel = self.make_request(
|
||||
"POST",
|
||||
f"/rooms/{self.room_id}/receipt/org.matrix.msc2285.read.private/{res1['event_id']}",
|
||||
f"/rooms/{self.room_id}/receipt/{receipt_type}/{res1['event_id']}",
|
||||
{},
|
||||
access_token=self.tok,
|
||||
)
|
||||
|
@ -948,3 +968,24 @@ class ExcludeRoomTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
self.assertNotIn(self.excluded_room_id, channel.json_body["rooms"]["invite"])
|
||||
self.assertIn(self.included_room_id, channel.json_body["rooms"]["invite"])
|
||||
|
||||
def test_incremental_sync(self) -> None:
|
||||
"""Tests that activity in the room is properly filtered out of incremental
|
||||
syncs.
|
||||
"""
|
||||
channel = self.make_request("GET", "/sync", access_token=self.tok)
|
||||
self.assertEqual(channel.code, 200, channel.result)
|
||||
next_batch = channel.json_body["next_batch"]
|
||||
|
||||
self.helper.send(self.excluded_room_id, tok=self.tok)
|
||||
self.helper.send(self.included_room_id, tok=self.tok)
|
||||
|
||||
channel = self.make_request(
|
||||
"GET",
|
||||
f"/sync?since={next_batch}",
|
||||
access_token=self.tok,
|
||||
)
|
||||
self.assertEqual(channel.code, 200, channel.result)
|
||||
|
||||
self.assertNotIn(self.excluded_room_id, channel.json_body["rooms"]["join"])
|
||||
self.assertIn(self.included_room_id, channel.json_body["rooms"]["join"])
|
||||
|
|
|
@ -155,7 +155,7 @@ class ThirdPartyRulesTestCase(unittest.FederatingHomeserverTestCase):
|
|||
{},
|
||||
access_token=self.tok,
|
||||
)
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, channel.result)
|
||||
|
||||
callback.assert_called_once()
|
||||
|
||||
|
@ -173,7 +173,7 @@ class ThirdPartyRulesTestCase(unittest.FederatingHomeserverTestCase):
|
|||
{},
|
||||
access_token=self.tok,
|
||||
)
|
||||
self.assertEqual(channel.result["code"], b"403", channel.result)
|
||||
self.assertEqual(channel.code, 403, channel.result)
|
||||
|
||||
def test_third_party_rules_workaround_synapse_errors_pass_through(self) -> None:
|
||||
"""
|
||||
|
@ -211,7 +211,7 @@ class ThirdPartyRulesTestCase(unittest.FederatingHomeserverTestCase):
|
|||
access_token=self.tok,
|
||||
)
|
||||
# Check the error code
|
||||
self.assertEqual(channel.result["code"], b"429", channel.result)
|
||||
self.assertEqual(channel.code, 429, channel.result)
|
||||
# Check the JSON body has had the `nasty` key injected
|
||||
self.assertEqual(
|
||||
channel.json_body,
|
||||
|
@ -260,7 +260,7 @@ class ThirdPartyRulesTestCase(unittest.FederatingHomeserverTestCase):
|
|||
{"x": "x"},
|
||||
access_token=self.tok,
|
||||
)
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, channel.result)
|
||||
event_id = channel.json_body["event_id"]
|
||||
|
||||
# ... and check that it got modified
|
||||
|
@ -269,7 +269,7 @@ class ThirdPartyRulesTestCase(unittest.FederatingHomeserverTestCase):
|
|||
"/_matrix/client/r0/rooms/%s/event/%s" % (self.room_id, event_id),
|
||||
access_token=self.tok,
|
||||
)
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, channel.result)
|
||||
ev = channel.json_body
|
||||
self.assertEqual(ev["content"]["x"], "y")
|
||||
|
||||
|
@ -298,7 +298,7 @@ class ThirdPartyRulesTestCase(unittest.FederatingHomeserverTestCase):
|
|||
},
|
||||
access_token=self.tok,
|
||||
)
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, channel.result)
|
||||
orig_event_id = channel.json_body["event_id"]
|
||||
|
||||
channel = self.make_request(
|
||||
|
@ -315,7 +315,7 @@ class ThirdPartyRulesTestCase(unittest.FederatingHomeserverTestCase):
|
|||
},
|
||||
access_token=self.tok,
|
||||
)
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, channel.result)
|
||||
edited_event_id = channel.json_body["event_id"]
|
||||
|
||||
# ... and check that they both got modified
|
||||
|
@ -324,7 +324,7 @@ class ThirdPartyRulesTestCase(unittest.FederatingHomeserverTestCase):
|
|||
"/_matrix/client/r0/rooms/%s/event/%s" % (self.room_id, orig_event_id),
|
||||
access_token=self.tok,
|
||||
)
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, channel.result)
|
||||
ev = channel.json_body
|
||||
self.assertEqual(ev["content"]["body"], "ORIGINAL BODY")
|
||||
|
||||
|
@ -333,7 +333,7 @@ class ThirdPartyRulesTestCase(unittest.FederatingHomeserverTestCase):
|
|||
"/_matrix/client/r0/rooms/%s/event/%s" % (self.room_id, edited_event_id),
|
||||
access_token=self.tok,
|
||||
)
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, channel.result)
|
||||
ev = channel.json_body
|
||||
self.assertEqual(ev["content"]["body"], "EDITED BODY")
|
||||
|
||||
|
@ -379,7 +379,7 @@ class ThirdPartyRulesTestCase(unittest.FederatingHomeserverTestCase):
|
|||
},
|
||||
access_token=self.tok,
|
||||
)
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, channel.result)
|
||||
|
||||
event_id = channel.json_body["event_id"]
|
||||
|
||||
|
@ -388,7 +388,7 @@ class ThirdPartyRulesTestCase(unittest.FederatingHomeserverTestCase):
|
|||
"/_matrix/client/r0/rooms/%s/event/%s" % (self.room_id, event_id),
|
||||
access_token=self.tok,
|
||||
)
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, channel.result)
|
||||
|
||||
self.assertIn("foo", channel.json_body["content"].keys())
|
||||
self.assertEqual(channel.json_body["content"]["foo"], "bar")
|
||||
|
|
|
@ -140,7 +140,7 @@ class RestHelper:
|
|||
custom_headers=custom_headers,
|
||||
)
|
||||
|
||||
assert channel.result["code"] == b"%d" % expect_code, channel.result
|
||||
assert channel.code == expect_code, channel.result
|
||||
self.auth_user_id = temp_id
|
||||
|
||||
if expect_code == HTTPStatus.OK:
|
||||
|
@ -213,11 +213,9 @@ class RestHelper:
|
|||
data,
|
||||
)
|
||||
|
||||
assert (
|
||||
int(channel.result["code"]) == expect_code
|
||||
), "Expected: %d, got: %d, resp: %r" % (
|
||||
assert channel.code == expect_code, "Expected: %d, got: %d, resp: %r" % (
|
||||
expect_code,
|
||||
int(channel.result["code"]),
|
||||
channel.code,
|
||||
channel.result["body"],
|
||||
)
|
||||
|
||||
|
@ -312,11 +310,9 @@ class RestHelper:
|
|||
data,
|
||||
)
|
||||
|
||||
assert (
|
||||
int(channel.result["code"]) == expect_code
|
||||
), "Expected: %d, got: %d, resp: %r" % (
|
||||
assert channel.code == expect_code, "Expected: %d, got: %d, resp: %r" % (
|
||||
expect_code,
|
||||
int(channel.result["code"]),
|
||||
channel.code,
|
||||
channel.result["body"],
|
||||
)
|
||||
|
||||
|
@ -396,11 +392,9 @@ class RestHelper:
|
|||
custom_headers=custom_headers,
|
||||
)
|
||||
|
||||
assert (
|
||||
int(channel.result["code"]) == expect_code
|
||||
), "Expected: %d, got: %d, resp: %r" % (
|
||||
assert channel.code == expect_code, "Expected: %d, got: %d, resp: %r" % (
|
||||
expect_code,
|
||||
int(channel.result["code"]),
|
||||
channel.code,
|
||||
channel.result["body"],
|
||||
)
|
||||
|
||||
|
@ -449,11 +443,9 @@ class RestHelper:
|
|||
|
||||
channel = make_request(self.hs.get_reactor(), self.site, method, path, content)
|
||||
|
||||
assert (
|
||||
int(channel.result["code"]) == expect_code
|
||||
), "Expected: %d, got: %d, resp: %r" % (
|
||||
assert channel.code == expect_code, "Expected: %d, got: %d, resp: %r" % (
|
||||
expect_code,
|
||||
int(channel.result["code"]),
|
||||
channel.code,
|
||||
channel.result["body"],
|
||||
)
|
||||
|
||||
|
@ -545,7 +537,7 @@ class RestHelper:
|
|||
|
||||
assert channel.code == expect_code, "Expected: %d, got: %d, resp: %r" % (
|
||||
expect_code,
|
||||
int(channel.result["code"]),
|
||||
channel.code,
|
||||
channel.result["body"],
|
||||
)
|
||||
|
||||
|
|
|
@ -11,8 +11,6 @@
|
|||
# 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 http import HTTPStatus
|
||||
|
||||
from synapse.rest.health import HealthResource
|
||||
|
||||
from tests import unittest
|
||||
|
@ -26,5 +24,5 @@ class HealthCheckTests(unittest.HomeserverTestCase):
|
|||
def test_health(self) -> None:
|
||||
channel = self.make_request("GET", "/health", shorthand=False)
|
||||
|
||||
self.assertEqual(channel.code, HTTPStatus.OK)
|
||||
self.assertEqual(channel.code, 200)
|
||||
self.assertEqual(channel.result["body"], b"OK")
|
||||
|
|
|
@ -11,8 +11,6 @@
|
|||
# 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 http import HTTPStatus
|
||||
|
||||
from twisted.web.resource import Resource
|
||||
|
||||
from synapse.rest.well_known import well_known_resource
|
||||
|
@ -38,7 +36,7 @@ class WellKnownTests(unittest.HomeserverTestCase):
|
|||
"GET", "/.well-known/matrix/client", shorthand=False
|
||||
)
|
||||
|
||||
self.assertEqual(channel.code, HTTPStatus.OK)
|
||||
self.assertEqual(channel.code, 200)
|
||||
self.assertEqual(
|
||||
channel.json_body,
|
||||
{
|
||||
|
@ -57,7 +55,7 @@ class WellKnownTests(unittest.HomeserverTestCase):
|
|||
"GET", "/.well-known/matrix/client", shorthand=False
|
||||
)
|
||||
|
||||
self.assertEqual(channel.code, HTTPStatus.NOT_FOUND)
|
||||
self.assertEqual(channel.code, 404)
|
||||
|
||||
@unittest.override_config(
|
||||
{
|
||||
|
@ -71,7 +69,7 @@ class WellKnownTests(unittest.HomeserverTestCase):
|
|||
"GET", "/.well-known/matrix/client", shorthand=False
|
||||
)
|
||||
|
||||
self.assertEqual(channel.code, HTTPStatus.OK)
|
||||
self.assertEqual(channel.code, 200)
|
||||
self.assertEqual(
|
||||
channel.json_body,
|
||||
{
|
||||
|
@ -87,7 +85,7 @@ class WellKnownTests(unittest.HomeserverTestCase):
|
|||
"GET", "/.well-known/matrix/server", shorthand=False
|
||||
)
|
||||
|
||||
self.assertEqual(channel.code, HTTPStatus.OK)
|
||||
self.assertEqual(channel.code, 200)
|
||||
self.assertEqual(
|
||||
channel.json_body,
|
||||
{"m.server": "test:443"},
|
||||
|
@ -97,4 +95,4 @@ class WellKnownTests(unittest.HomeserverTestCase):
|
|||
channel = self.make_request(
|
||||
"GET", "/.well-known/matrix/server", shorthand=False
|
||||
)
|
||||
self.assertEqual(channel.code, HTTPStatus.NOT_FOUND)
|
||||
self.assertEqual(channel.code, 404)
|
||||
|
|
|
@ -135,7 +135,22 @@ class EventPushActionsStoreTestCase(HomeserverTestCase):
|
|||
_assert_counts(1, 1, 0)
|
||||
|
||||
# Delete old event push actions, this should not affect the (summarised) count.
|
||||
#
|
||||
# All event push actions are kept for 24 hours, so need to move forward
|
||||
# in time.
|
||||
self.pump(60 * 60 * 24)
|
||||
self.get_success(self.store._remove_old_push_actions_that_have_rotated())
|
||||
# Double check that the event push actions have been cleared (i.e. that
|
||||
# any results *must* come from the summary).
|
||||
result = self.get_success(
|
||||
self.store.db_pool.simple_select_list(
|
||||
table="event_push_actions",
|
||||
keyvalues={"1": 1},
|
||||
retcols=("event_id",),
|
||||
desc="",
|
||||
)
|
||||
)
|
||||
self.assertEqual(result, [])
|
||||
_assert_counts(1, 1, 0)
|
||||
|
||||
_mark_read(last_event_id)
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from parameterized import parameterized
|
||||
|
||||
from synapse.api.constants import ReceiptTypes
|
||||
from synapse.types import UserID, create_requester
|
||||
|
||||
|
@ -23,7 +25,7 @@ OUR_USER_ID = "@our:test"
|
|||
|
||||
|
||||
class ReceiptTestCase(HomeserverTestCase):
|
||||
def prepare(self, reactor, clock, homeserver):
|
||||
def prepare(self, reactor, clock, homeserver) -> None:
|
||||
super().prepare(reactor, clock, homeserver)
|
||||
|
||||
self.store = homeserver.get_datastores().main
|
||||
|
@ -83,10 +85,15 @@ class ReceiptTestCase(HomeserverTestCase):
|
|||
)
|
||||
)
|
||||
|
||||
def test_return_empty_with_no_data(self):
|
||||
def test_return_empty_with_no_data(self) -> None:
|
||||
res = self.get_success(
|
||||
self.store.get_receipts_for_user(
|
||||
OUR_USER_ID, [ReceiptTypes.READ, ReceiptTypes.READ_PRIVATE]
|
||||
OUR_USER_ID,
|
||||
[
|
||||
ReceiptTypes.READ,
|
||||
ReceiptTypes.READ_PRIVATE,
|
||||
ReceiptTypes.UNSTABLE_READ_PRIVATE,
|
||||
],
|
||||
)
|
||||
)
|
||||
self.assertEqual(res, {})
|
||||
|
@ -94,7 +101,11 @@ class ReceiptTestCase(HomeserverTestCase):
|
|||
res = self.get_success(
|
||||
self.store.get_receipts_for_user_with_orderings(
|
||||
OUR_USER_ID,
|
||||
[ReceiptTypes.READ, ReceiptTypes.READ_PRIVATE],
|
||||
[
|
||||
ReceiptTypes.READ,
|
||||
ReceiptTypes.READ_PRIVATE,
|
||||
ReceiptTypes.UNSTABLE_READ_PRIVATE,
|
||||
],
|
||||
)
|
||||
)
|
||||
self.assertEqual(res, {})
|
||||
|
@ -103,12 +114,19 @@ class ReceiptTestCase(HomeserverTestCase):
|
|||
self.store.get_last_receipt_event_id_for_user(
|
||||
OUR_USER_ID,
|
||||
self.room_id1,
|
||||
[ReceiptTypes.READ, ReceiptTypes.READ_PRIVATE],
|
||||
[
|
||||
ReceiptTypes.READ,
|
||||
ReceiptTypes.READ_PRIVATE,
|
||||
ReceiptTypes.UNSTABLE_READ_PRIVATE,
|
||||
],
|
||||
)
|
||||
)
|
||||
self.assertEqual(res, None)
|
||||
|
||||
def test_get_receipts_for_user(self):
|
||||
@parameterized.expand(
|
||||
[ReceiptTypes.READ_PRIVATE, ReceiptTypes.UNSTABLE_READ_PRIVATE]
|
||||
)
|
||||
def test_get_receipts_for_user(self, receipt_type: str) -> None:
|
||||
# Send some events into the first room
|
||||
event1_1_id = self.create_and_send_event(
|
||||
self.room_id1, UserID.from_string(OTHER_USER_ID)
|
||||
|
@ -126,14 +144,14 @@ class ReceiptTestCase(HomeserverTestCase):
|
|||
# Send private read receipt for the second event
|
||||
self.get_success(
|
||||
self.store.insert_receipt(
|
||||
self.room_id1, ReceiptTypes.READ_PRIVATE, OUR_USER_ID, [event1_2_id], {}
|
||||
self.room_id1, receipt_type, OUR_USER_ID, [event1_2_id], {}
|
||||
)
|
||||
)
|
||||
|
||||
# Test we get the latest event when we want both private and public receipts
|
||||
res = self.get_success(
|
||||
self.store.get_receipts_for_user(
|
||||
OUR_USER_ID, [ReceiptTypes.READ, ReceiptTypes.READ_PRIVATE]
|
||||
OUR_USER_ID, [ReceiptTypes.READ, receipt_type]
|
||||
)
|
||||
)
|
||||
self.assertEqual(res, {self.room_id1: event1_2_id})
|
||||
|
@ -146,7 +164,7 @@ class ReceiptTestCase(HomeserverTestCase):
|
|||
|
||||
# Test we get the latest event when we want only the public receipt
|
||||
res = self.get_success(
|
||||
self.store.get_receipts_for_user(OUR_USER_ID, [ReceiptTypes.READ_PRIVATE])
|
||||
self.store.get_receipts_for_user(OUR_USER_ID, [receipt_type])
|
||||
)
|
||||
self.assertEqual(res, {self.room_id1: event1_2_id})
|
||||
|
||||
|
@ -169,17 +187,20 @@ class ReceiptTestCase(HomeserverTestCase):
|
|||
# Test new room is reflected in what the method returns
|
||||
self.get_success(
|
||||
self.store.insert_receipt(
|
||||
self.room_id2, ReceiptTypes.READ_PRIVATE, OUR_USER_ID, [event2_1_id], {}
|
||||
self.room_id2, receipt_type, OUR_USER_ID, [event2_1_id], {}
|
||||
)
|
||||
)
|
||||
res = self.get_success(
|
||||
self.store.get_receipts_for_user(
|
||||
OUR_USER_ID, [ReceiptTypes.READ, ReceiptTypes.READ_PRIVATE]
|
||||
OUR_USER_ID, [ReceiptTypes.READ, receipt_type]
|
||||
)
|
||||
)
|
||||
self.assertEqual(res, {self.room_id1: event1_2_id, self.room_id2: event2_1_id})
|
||||
|
||||
def test_get_last_receipt_event_id_for_user(self):
|
||||
@parameterized.expand(
|
||||
[ReceiptTypes.READ_PRIVATE, ReceiptTypes.UNSTABLE_READ_PRIVATE]
|
||||
)
|
||||
def test_get_last_receipt_event_id_for_user(self, receipt_type: str) -> None:
|
||||
# Send some events into the first room
|
||||
event1_1_id = self.create_and_send_event(
|
||||
self.room_id1, UserID.from_string(OTHER_USER_ID)
|
||||
|
@ -197,7 +218,7 @@ class ReceiptTestCase(HomeserverTestCase):
|
|||
# Send private read receipt for the second event
|
||||
self.get_success(
|
||||
self.store.insert_receipt(
|
||||
self.room_id1, ReceiptTypes.READ_PRIVATE, OUR_USER_ID, [event1_2_id], {}
|
||||
self.room_id1, receipt_type, OUR_USER_ID, [event1_2_id], {}
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -206,7 +227,7 @@ class ReceiptTestCase(HomeserverTestCase):
|
|||
self.store.get_last_receipt_event_id_for_user(
|
||||
OUR_USER_ID,
|
||||
self.room_id1,
|
||||
[ReceiptTypes.READ, ReceiptTypes.READ_PRIVATE],
|
||||
[ReceiptTypes.READ, receipt_type],
|
||||
)
|
||||
)
|
||||
self.assertEqual(res, event1_2_id)
|
||||
|
@ -222,7 +243,7 @@ class ReceiptTestCase(HomeserverTestCase):
|
|||
# Test we get the latest event when we want only the private receipt
|
||||
res = self.get_success(
|
||||
self.store.get_last_receipt_event_id_for_user(
|
||||
OUR_USER_ID, self.room_id1, [ReceiptTypes.READ_PRIVATE]
|
||||
OUR_USER_ID, self.room_id1, [receipt_type]
|
||||
)
|
||||
)
|
||||
self.assertEqual(res, event1_2_id)
|
||||
|
@ -248,14 +269,14 @@ class ReceiptTestCase(HomeserverTestCase):
|
|||
# Test new room is reflected in what the method returns
|
||||
self.get_success(
|
||||
self.store.insert_receipt(
|
||||
self.room_id2, ReceiptTypes.READ_PRIVATE, OUR_USER_ID, [event2_1_id], {}
|
||||
self.room_id2, receipt_type, OUR_USER_ID, [event2_1_id], {}
|
||||
)
|
||||
)
|
||||
res = self.get_success(
|
||||
self.store.get_last_receipt_event_id_for_user(
|
||||
OUR_USER_ID,
|
||||
self.room_id2,
|
||||
[ReceiptTypes.READ, ReceiptTypes.READ_PRIVATE],
|
||||
[ReceiptTypes.READ, receipt_type],
|
||||
)
|
||||
)
|
||||
self.assertEqual(res, event2_1_id)
|
||||
|
|
|
@ -104,7 +104,7 @@ class JsonResourceTests(unittest.TestCase):
|
|||
self.reactor, FakeSite(res, self.reactor), b"GET", b"/_matrix/foo"
|
||||
)
|
||||
|
||||
self.assertEqual(channel.result["code"], b"500")
|
||||
self.assertEqual(channel.code, 500)
|
||||
|
||||
def test_callback_indirect_exception(self) -> None:
|
||||
"""
|
||||
|
@ -130,7 +130,7 @@ class JsonResourceTests(unittest.TestCase):
|
|||
self.reactor, FakeSite(res, self.reactor), b"GET", b"/_matrix/foo"
|
||||
)
|
||||
|
||||
self.assertEqual(channel.result["code"], b"500")
|
||||
self.assertEqual(channel.code, 500)
|
||||
|
||||
def test_callback_synapseerror(self) -> None:
|
||||
"""
|
||||
|
@ -150,7 +150,7 @@ class JsonResourceTests(unittest.TestCase):
|
|||
self.reactor, FakeSite(res, self.reactor), b"GET", b"/_matrix/foo"
|
||||
)
|
||||
|
||||
self.assertEqual(channel.result["code"], b"403")
|
||||
self.assertEqual(channel.code, 403)
|
||||
self.assertEqual(channel.json_body["error"], "Forbidden!!one!")
|
||||
self.assertEqual(channel.json_body["errcode"], "M_FORBIDDEN")
|
||||
|
||||
|
@ -174,7 +174,7 @@ class JsonResourceTests(unittest.TestCase):
|
|||
self.reactor, FakeSite(res, self.reactor), b"GET", b"/_matrix/foobar"
|
||||
)
|
||||
|
||||
self.assertEqual(channel.result["code"], b"400")
|
||||
self.assertEqual(channel.code, 400)
|
||||
self.assertEqual(channel.json_body["error"], "Unrecognized request")
|
||||
self.assertEqual(channel.json_body["errcode"], "M_UNRECOGNIZED")
|
||||
|
||||
|
@ -203,7 +203,7 @@ class JsonResourceTests(unittest.TestCase):
|
|||
self.reactor, FakeSite(res, self.reactor), b"HEAD", b"/_matrix/foo"
|
||||
)
|
||||
|
||||
self.assertEqual(channel.result["code"], b"200")
|
||||
self.assertEqual(channel.code, 200)
|
||||
self.assertNotIn("body", channel.result)
|
||||
|
||||
|
||||
|
@ -242,7 +242,7 @@ class OptionsResourceTests(unittest.TestCase):
|
|||
def test_unknown_options_request(self) -> None:
|
||||
"""An OPTIONS requests to an unknown URL still returns 204 No Content."""
|
||||
channel = self._make_request(b"OPTIONS", b"/foo/")
|
||||
self.assertEqual(channel.result["code"], b"204")
|
||||
self.assertEqual(channel.code, 204)
|
||||
self.assertNotIn("body", channel.result)
|
||||
|
||||
# Ensure the correct CORS headers have been added
|
||||
|
@ -262,7 +262,7 @@ class OptionsResourceTests(unittest.TestCase):
|
|||
def test_known_options_request(self) -> None:
|
||||
"""An OPTIONS requests to an known URL still returns 204 No Content."""
|
||||
channel = self._make_request(b"OPTIONS", b"/res/")
|
||||
self.assertEqual(channel.result["code"], b"204")
|
||||
self.assertEqual(channel.code, 204)
|
||||
self.assertNotIn("body", channel.result)
|
||||
|
||||
# Ensure the correct CORS headers have been added
|
||||
|
@ -282,12 +282,12 @@ class OptionsResourceTests(unittest.TestCase):
|
|||
def test_unknown_request(self) -> None:
|
||||
"""A non-OPTIONS request to an unknown URL should 404."""
|
||||
channel = self._make_request(b"GET", b"/foo/")
|
||||
self.assertEqual(channel.result["code"], b"404")
|
||||
self.assertEqual(channel.code, 404)
|
||||
|
||||
def test_known_request(self) -> None:
|
||||
"""A non-OPTIONS request to an known URL should query the proper resource."""
|
||||
channel = self._make_request(b"GET", b"/res/")
|
||||
self.assertEqual(channel.result["code"], b"200")
|
||||
self.assertEqual(channel.code, 200)
|
||||
self.assertEqual(channel.result["body"], b"/res/")
|
||||
|
||||
|
||||
|
@ -314,7 +314,7 @@ class WrapHtmlRequestHandlerTests(unittest.TestCase):
|
|||
self.reactor, FakeSite(res, self.reactor), b"GET", b"/path"
|
||||
)
|
||||
|
||||
self.assertEqual(channel.result["code"], b"200")
|
||||
self.assertEqual(channel.code, 200)
|
||||
body = channel.result["body"]
|
||||
self.assertEqual(body, b"response")
|
||||
|
||||
|
@ -334,7 +334,7 @@ class WrapHtmlRequestHandlerTests(unittest.TestCase):
|
|||
self.reactor, FakeSite(res, self.reactor), b"GET", b"/path"
|
||||
)
|
||||
|
||||
self.assertEqual(channel.result["code"], b"301")
|
||||
self.assertEqual(channel.code, 301)
|
||||
headers = channel.result["headers"]
|
||||
location_headers = [v for k, v in headers if k == b"Location"]
|
||||
self.assertEqual(location_headers, [b"/look/an/eagle"])
|
||||
|
@ -357,7 +357,7 @@ class WrapHtmlRequestHandlerTests(unittest.TestCase):
|
|||
self.reactor, FakeSite(res, self.reactor), b"GET", b"/path"
|
||||
)
|
||||
|
||||
self.assertEqual(channel.result["code"], b"304")
|
||||
self.assertEqual(channel.code, 304)
|
||||
headers = channel.result["headers"]
|
||||
location_headers = [v for k, v in headers if k == b"Location"]
|
||||
self.assertEqual(location_headers, [b"/no/over/there"])
|
||||
|
@ -378,7 +378,7 @@ class WrapHtmlRequestHandlerTests(unittest.TestCase):
|
|||
self.reactor, FakeSite(res, self.reactor), b"HEAD", b"/path"
|
||||
)
|
||||
|
||||
self.assertEqual(channel.result["code"], b"200")
|
||||
self.assertEqual(channel.code, 200)
|
||||
self.assertNotIn("body", channel.result)
|
||||
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ class TermsTestCase(unittest.HomeserverTestCase):
|
|||
request_data = {"username": "kermit", "password": "monkey"}
|
||||
channel = self.make_request(b"POST", self.url, request_data)
|
||||
|
||||
self.assertEqual(channel.result["code"], b"401", channel.result)
|
||||
self.assertEqual(channel.code, 401, channel.result)
|
||||
|
||||
self.assertTrue(channel.json_body is not None)
|
||||
self.assertIsInstance(channel.json_body["session"], str)
|
||||
|
@ -96,7 +96,7 @@ class TermsTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
# We don't bother checking that the response is correct - we'll leave that to
|
||||
# other tests. We just want to make sure we're on the right path.
|
||||
self.assertEqual(channel.result["code"], b"401", channel.result)
|
||||
self.assertEqual(channel.code, 401, channel.result)
|
||||
|
||||
# Finish the UI auth for terms
|
||||
request_data = {
|
||||
|
@ -112,7 +112,7 @@ class TermsTestCase(unittest.HomeserverTestCase):
|
|||
# We're interested in getting a response that looks like a successful
|
||||
# registration, not so much that the details are exactly what we want.
|
||||
|
||||
self.assertEqual(channel.result["code"], b"200", channel.result)
|
||||
self.assertEqual(channel.code, 200, channel.result)
|
||||
|
||||
self.assertTrue(channel.json_body is not None)
|
||||
self.assertIsInstance(channel.json_body["user_id"], str)
|
||||
|
|
Loading…
Reference in a new issue