mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-04 05:24:55 -04:00
Correctly handle AS registerations and add test
This commit is contained in:
parent
35be260090
commit
4c33796b20
5 changed files with 77 additions and 9 deletions
|
@ -19,6 +19,7 @@ import json
|
|||
|
||||
from synapse.api.constants import LoginType
|
||||
from synapse.api.errors import Codes, HttpResponseException, SynapseError
|
||||
from synapse.appservice import ApplicationService
|
||||
from synapse.rest.client.v2_alpha import register, sync
|
||||
|
||||
from tests import unittest
|
||||
|
@ -75,6 +76,44 @@ class TestMauLimit(unittest.HomeserverTestCase):
|
|||
self.assertEqual(e.code, 403)
|
||||
self.assertEqual(e.errcode, Codes.RESOURCE_LIMIT_EXCEEDED)
|
||||
|
||||
def test_as_ignores_mau(self):
|
||||
"""Test that application services can still create users when the MAU
|
||||
limit has been reached.
|
||||
"""
|
||||
|
||||
# Create and sync so that the MAU counts get updated
|
||||
token1 = self.create_user("kermit1")
|
||||
self.do_sync_for_user(token1)
|
||||
token2 = self.create_user("kermit2")
|
||||
self.do_sync_for_user(token2)
|
||||
|
||||
# check we're testing what we think we are: there should be two active users
|
||||
self.assertEqual(self.get_success(self.store.get_monthly_active_count()), 2)
|
||||
|
||||
# We've created and activated two users, we shouldn't be able to
|
||||
# register new users
|
||||
with self.assertRaises(SynapseError) as cm:
|
||||
self.create_user("kermit3")
|
||||
|
||||
e = cm.exception
|
||||
self.assertEqual(e.code, 403)
|
||||
self.assertEqual(e.errcode, Codes.RESOURCE_LIMIT_EXCEEDED)
|
||||
|
||||
# Cheekily add an application service that we use to register a new user
|
||||
# with.
|
||||
as_token = "foobartoken"
|
||||
self.store.services_cache.append(
|
||||
ApplicationService(
|
||||
token=as_token,
|
||||
hostname=self.hs.hostname,
|
||||
id="SomeASID",
|
||||
sender="@as_sender:test",
|
||||
namespaces={"users": [{"regex": "@as_*", "exclusive": True}]},
|
||||
)
|
||||
)
|
||||
|
||||
self.create_user("as_kermit4", token=as_token)
|
||||
|
||||
def test_allowed_after_a_month_mau(self):
|
||||
# Create and sync so that the MAU counts get updated
|
||||
token1 = self.create_user("kermit1")
|
||||
|
@ -192,7 +231,7 @@ class TestMauLimit(unittest.HomeserverTestCase):
|
|||
self.reactor.advance(100)
|
||||
self.assertEqual(2, self.successResultOf(count))
|
||||
|
||||
def create_user(self, localpart):
|
||||
def create_user(self, localpart, token=None):
|
||||
request_data = json.dumps(
|
||||
{
|
||||
"username": localpart,
|
||||
|
@ -201,7 +240,9 @@ class TestMauLimit(unittest.HomeserverTestCase):
|
|||
}
|
||||
)
|
||||
|
||||
request, channel = self.make_request("POST", "/register", request_data)
|
||||
request, channel = self.make_request(
|
||||
"POST", "/register", request_data, access_token=token
|
||||
)
|
||||
|
||||
if channel.code != 200:
|
||||
raise HttpResponseException(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue