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

Commit f1b4069

Browse files
authored
Merge pull request #6020 from matrix-org/jaywink/allow-support-users-to-register
Ensure support users can be registered even if MAU limit is reached
2 parents 9fc71dc + 6d847d8 commit f1b4069

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,
@@ -709,7 +709,7 @@ def check_in_room_or_world_readable(self, room_id, user_id):
709709
)
710710

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

727730
# Never fail an auth check for the server notices users or support user
@@ -759,6 +762,10 @@ def check_auth_blocking(self, user_id=None, threepid=None):
759762
self.hs.config.mau_limits_reserved_threepids, threepid
760763
):
761764
return
765+
elif user_type == UserTypes.SUPPORT:
766+
# If the user does not exist yet and is of type "support",
767+
# allow registration. Support users are excluded from MAU checks.
768+
return
762769
# Else if there is no room in the MAU bucket, bail
763770
current_mau = yield self.store.get_monthly_active_count()
764771
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)