Skip to content

Commit

Permalink
Update MAU limit tests
Browse files Browse the repository at this point in the history
Update because of changes in "Stop Auth methods from polling the config
on every req. (matrix-org#7420)"
  • Loading branch information
dklimpel committed May 12, 2020
1 parent 75975e0 commit b3b347b
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions tests/rest/admin/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,15 +330,16 @@ def test_register_mau_limit_reached(self):
"""
handler = self.hs.get_registration_handler()
store = self.hs.get_datastore()
auth_blocking = self.hs.get_auth()._auth_blocking

# Configure MAU limit
self.hs.config.limit_usage_by_mau = True
self.hs.config.max_mau_value = 2
self.hs.config.mau_trial_days = 0
auth_blocking._limit_usage_by_mau = True
auth_blocking._max_mau_value = 2
auth_blocking._mau_trial_days = 0

# Set monthly active users to the limit
store.get_monthly_active_count = Mock(
return_value=defer.succeed(self.hs.config.max_mau_value)
return_value=defer.succeed(auth_blocking._max_mau_value)
)
# The registration of a new user fails due to the limit
self.get_failure(
Expand Down Expand Up @@ -577,11 +578,12 @@ def test_create_user_mau_limit_reached_active_admin(self):
self.hs.config.registration_shared_secret = None

handler = self.hs.get_registration_handler()
auth_blocking = self.hs.get_auth()._auth_blocking

# Configure MAU limit
self.hs.config.limit_usage_by_mau = True
self.hs.config.max_mau_value = 2
self.hs.config.mau_trial_days = 0
auth_blocking._limit_usage_by_mau = True
auth_blocking._max_mau_value = 2
auth_blocking._mau_trial_days = 0

# Sync to set admin user to active
# before limit of monthly active users is reached
Expand All @@ -597,7 +599,7 @@ def test_create_user_mau_limit_reached_active_admin(self):

# Set monthly active users to the limit
self.store.get_monthly_active_count = Mock(
return_value=defer.succeed(self.hs.config.max_mau_value)
return_value=defer.succeed(auth_blocking._max_mau_value)
)
# The registration of a new user fails due to the limit
self.get_failure(
Expand Down Expand Up @@ -625,20 +627,21 @@ def test_create_user_mau_limit_reached_active_admin(self):
def test_create_user_mau_limit_reached_passiv_admin(self):
"""
Try to create a new regular user if MAU limit is reached.
Admin user was not active before creating user and creation fails.
Admin user was not active before creating user.
"""
self.hs.config.registration_shared_secret = None

handler = self.hs.get_registration_handler()
auth_blocking = self.hs.get_auth()._auth_blocking

# Configure MAU limit
self.hs.config.limit_usage_by_mau = True
self.hs.config.max_mau_value = 2
self.hs.config.mau_trial_days = 0
auth_blocking._limit_usage_by_mau = True
auth_blocking._max_mau_value = 2
auth_blocking._mau_trial_days = 0

# Set monthly active users to the limit
self.store.get_monthly_active_count = Mock(
return_value=defer.succeed(self.hs.config.max_mau_value)
return_value=defer.succeed(auth_blocking._max_mau_value)
)
# The registration of a new user fails due to the limit
self.get_failure(
Expand All @@ -659,7 +662,10 @@ def test_create_user_mau_limit_reached_passiv_admin(self):
)
self.render(request)

self.assertEqual(500, int(channel.result["code"]), msg=channel.result["body"])
# Admin user is not blocked by mau anymore
self.assertEqual(201, int(channel.result["code"]), msg=channel.result["body"])
self.assertEqual("@bob:test", channel.json_body["name"])
self.assertEqual(False, channel.json_body["admin"])

def test_set_password(self):
"""
Expand Down

0 comments on commit b3b347b

Please sign in to comment.