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

Commit 9b9dfc2

Browse files
committed
Merge pull request #6020 from matrix-org/jaywink/allow-support-users-to-register
2 parents dd61511 + f1b4069 commit 9b9dfc2

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

changelog.d/6020.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ensure support users can be registered even if MAU limit is reached.

synapse/api/auth.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import synapse.logging.opentracing as opentracing
2626
import synapse.types
2727
from synapse import event_auth
28-
from synapse.api.constants import EventTypes, JoinRules, Membership
28+
from synapse.api.constants import EventTypes, JoinRules, Membership, UserTypes
2929
from synapse.api.errors import (
3030
AuthError,
3131
Codes,
@@ -714,7 +714,7 @@ def check_in_room_or_world_readable(self, room_id, user_id):
714714
)
715715

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

732735
# Never fail an auth check for the server notices users or support user
@@ -764,6 +767,10 @@ def check_auth_blocking(self, user_id=None, threepid=None):
764767
self.hs.config.mau_limits_reserved_threepids, threepid
765768
):
766769
return
770+
elif user_type == UserTypes.SUPPORT:
771+
# If the user does not exist yet and is of type "support",
772+
# allow registration. Support users are excluded from MAU checks.
773+
return
767774
# Else if there is no room in the MAU bucket, bail
768775
current_mau = yield self.store.get_monthly_active_count()
769776
if current_mau >= self.hs.config.max_mau_value:

tests/api/test_auth.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import synapse.handlers.auth
2323
from synapse.api.auth import Auth
24+
from synapse.api.constants import UserTypes
2425
from synapse.api.errors import (
2526
AuthError,
2627
Codes,
@@ -335,6 +336,23 @@ def test_blocking_mau(self):
335336
)
336337
yield self.auth.check_auth_blocking()
337338

339+
@defer.inlineCallbacks
340+
def test_blocking_mau__depending_on_user_type(self):
341+
self.hs.config.max_mau_value = 50
342+
self.hs.config.limit_usage_by_mau = True
343+
344+
self.store.get_monthly_active_count = Mock(return_value=defer.succeed(100))
345+
# Support users allowed
346+
yield self.auth.check_auth_blocking(user_type=UserTypes.SUPPORT)
347+
self.store.get_monthly_active_count = Mock(return_value=defer.succeed(100))
348+
# Bots not allowed
349+
with self.assertRaises(ResourceLimitError):
350+
yield self.auth.check_auth_blocking(user_type=UserTypes.BOT)
351+
self.store.get_monthly_active_count = Mock(return_value=defer.succeed(100))
352+
# Real users not allowed
353+
with self.assertRaises(ResourceLimitError):
354+
yield self.auth.check_auth_blocking()
355+
338356
@defer.inlineCallbacks
339357
def test_reserved_threepid(self):
340358
self.hs.config.limit_usage_by_mau = True

0 commit comments

Comments
 (0)