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

Commit

Permalink
Merge pull request #6020 from matrix-org/jaywink/allow-support-users-…
Browse files Browse the repository at this point in the history
…to-register
  • Loading branch information
anoadragon453 committed Feb 25, 2020
2 parents dd61511 + f1b4069 commit 9b9dfc2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.d/6020.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ensure support users can be registered even if MAU limit is reached.
11 changes: 9 additions & 2 deletions synapse/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import synapse.logging.opentracing as opentracing
import synapse.types
from synapse import event_auth
from synapse.api.constants import EventTypes, JoinRules, Membership
from synapse.api.constants import EventTypes, JoinRules, Membership, UserTypes
from synapse.api.errors import (
AuthError,
Codes,
Expand Down Expand Up @@ -714,7 +714,7 @@ def check_in_room_or_world_readable(self, room_id, user_id):
)

@defer.inlineCallbacks
def check_auth_blocking(self, user_id=None, threepid=None):
def check_auth_blocking(self, user_id=None, threepid=None, user_type=None):
"""Checks if the user should be rejected for some external reason,
such as monthly active user limiting or global disable flag
Expand All @@ -727,6 +727,9 @@ def check_auth_blocking(self, user_id=None, threepid=None):
with a MAU blocked server, normally they would be rejected but their
threepid is on the reserved list. user_id and
threepid should never be set at the same time.
user_type(str|None): If present, is used to decide whether to check against
certain blocking reasons like MAU.
"""

# Never fail an auth check for the server notices users or support user
Expand Down Expand Up @@ -764,6 +767,10 @@ def check_auth_blocking(self, user_id=None, threepid=None):
self.hs.config.mau_limits_reserved_threepids, threepid
):
return
elif user_type == UserTypes.SUPPORT:
# If the user does not exist yet and is of type "support",
# allow registration. Support users are excluded from MAU checks.
return
# Else if there is no room in the MAU bucket, bail
current_mau = yield self.store.get_monthly_active_count()
if current_mau >= self.hs.config.max_mau_value:
Expand Down
18 changes: 18 additions & 0 deletions tests/api/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import synapse.handlers.auth
from synapse.api.auth import Auth
from synapse.api.constants import UserTypes
from synapse.api.errors import (
AuthError,
Codes,
Expand Down Expand Up @@ -335,6 +336,23 @@ def test_blocking_mau(self):
)
yield self.auth.check_auth_blocking()

@defer.inlineCallbacks
def test_blocking_mau__depending_on_user_type(self):
self.hs.config.max_mau_value = 50
self.hs.config.limit_usage_by_mau = True

self.store.get_monthly_active_count = Mock(return_value=defer.succeed(100))
# Support users allowed
yield self.auth.check_auth_blocking(user_type=UserTypes.SUPPORT)
self.store.get_monthly_active_count = Mock(return_value=defer.succeed(100))
# Bots not allowed
with self.assertRaises(ResourceLimitError):
yield self.auth.check_auth_blocking(user_type=UserTypes.BOT)
self.store.get_monthly_active_count = Mock(return_value=defer.succeed(100))
# Real users not allowed
with self.assertRaises(ResourceLimitError):
yield self.auth.check_auth_blocking()

@defer.inlineCallbacks
def test_reserved_threepid(self):
self.hs.config.limit_usage_by_mau = True
Expand Down

0 comments on commit 9b9dfc2

Please sign in to comment.