This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Block ability to read via sync if mau limit exceeded #3670
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e92fb00
sync auth blocking
neilisfragile a5ef110
Merge branch 'develop' of github.com:matrix-org/synapse into neilj/ma…
neilisfragile 3dce905
Merge branch 'develop' of github.com:matrix-org/synapse into neilj/ma…
neilisfragile 69ce057
block sync if auth checks fail
neilisfragile c6b28fb
Where server is disabled, block ability for locked out users to read …
neilisfragile 09cf130
only block on sync where user is not part of the mau cohort
neilisfragile 04df714
fix imports
neilisfragile c1f9dec
fix errant parenthesis
neilisfragile 885ea9c
rename _user_last_seen_monthly_active
neilisfragile 2545993
make comments clearer
neilisfragile File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Where server is disabled, block ability for locked out users to read new messages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2018 New Vector Ltd | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
from twisted.internet import defer | ||
|
||
from synapse.api.errors import AuthError, Codes | ||
from synapse.api.filtering import DEFAULT_FILTER_COLLECTION | ||
from synapse.handlers.sync import SyncConfig, SyncHandler | ||
from synapse.types import UserID | ||
|
||
import tests.unittest | ||
import tests.utils | ||
from tests.utils import setup_test_homeserver | ||
|
||
|
||
class SyncTestCase(tests.unittest.TestCase): | ||
""" Tests Sync Handler. """ | ||
|
||
@defer.inlineCallbacks | ||
def setUp(self): | ||
self.hs = yield setup_test_homeserver() | ||
self.sync_handler = SyncHandler(self.hs) | ||
self.store = self.hs.get_datastore() | ||
|
||
@defer.inlineCallbacks | ||
def test_wait_for_sync_for_user_auth_blocking(self): | ||
|
||
user_id1 = "@user1:server" | ||
user_id2 = "@user2:server" | ||
sync_config = self._generate_sync_config(user_id1) | ||
|
||
self.hs.config.limit_usage_by_mau = True | ||
self.hs.config.max_mau_value = 1 | ||
|
||
# Check that the happy case does not throw errors | ||
yield self.store.upsert_monthly_active_user(user_id1) | ||
yield self.sync_handler.wait_for_sync_for_user(sync_config) | ||
|
||
# Test that global lock works | ||
self.hs.config.hs_disabled = True | ||
with self.assertRaises(AuthError) as e: | ||
yield self.sync_handler.wait_for_sync_for_user(sync_config) | ||
self.assertEquals(e.exception.errcode, Codes.HS_DISABLED) | ||
|
||
self.hs.config.hs_disabled = False | ||
|
||
sync_config = self._generate_sync_config(user_id2) | ||
|
||
with self.assertRaises(AuthError) as e: | ||
yield self.sync_handler.wait_for_sync_for_user(sync_config) | ||
self.assertEquals(e.exception.errcode, Codes.MAU_LIMIT_EXCEEDED) | ||
|
||
def _generate_sync_config(self, user_id): | ||
return SyncConfig( | ||
user=UserID(user_id.split(":")[0][1:], user_id.split(":")[1]), | ||
filter_collection=DEFAULT_FILTER_COLLECTION, | ||
is_guest=False, | ||
request_key="request_key", | ||
device_id="device_id", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should call this
check_server_limits
or somethingThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I agree, since it will be a change in a lot of places I'll submit a separate PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
err given I have a few outstanding, I'll wait until a few more of them land