-
Notifications
You must be signed in to change notification settings - Fork 498
Finish up work to allow per-user feature flags #17392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e61b6a1
Add check for per-user feature flag
erikjohnston e104003
Remove unused feature
erikjohnston 8ce087d
Optionally check for auth in /versions
erikjohnston ff16dd5
Use per-user feature flags for MSC3881
erikjohnston 0721903
Newsfile
erikjohnston ae2b9cc
Update docs
erikjohnston 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 hidden or 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 @@ | ||
| Finish up work to allow per-user feature flags. |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -26,7 +26,8 @@ | |
| import synapse.rest.admin | ||
| from synapse.logging.context import make_deferred_yieldable | ||
| from synapse.push import PusherConfig, PusherConfigException | ||
| from synapse.rest.client import login, push_rule, pusher, receipts, room | ||
| from synapse.rest.admin.experimental_features import ExperimentalFeature | ||
| from synapse.rest.client import login, push_rule, pusher, receipts, room, versions | ||
| from synapse.server import HomeServer | ||
| from synapse.types import JsonDict | ||
| from synapse.util import Clock | ||
|
|
@@ -42,6 +43,7 @@ class HTTPPusherTests(HomeserverTestCase): | |
| receipts.register_servlets, | ||
| push_rule.register_servlets, | ||
| pusher.register_servlets, | ||
| versions.register_servlets, | ||
| ] | ||
| user_id = True | ||
| hijack_auth = False | ||
|
|
@@ -969,6 +971,84 @@ def test_device_id(self) -> None: | |
| lookup_result.device_id, | ||
| ) | ||
|
|
||
| def test_device_id_feature_flag(self) -> None: | ||
| """Tests that a pusher created with a given device ID shows that device ID in | ||
| GET /pushers requests when feature is enabled for the user | ||
| """ | ||
| user_id = self.register_user("user", "pass") | ||
| access_token = self.login("user", "pass") | ||
|
|
||
| # We create the pusher with an HTTP request rather than with | ||
| # _make_user_with_pusher so that we can test the device ID is correctly set when | ||
| # creating a pusher via an API call. | ||
| self.make_request( | ||
| method="POST", | ||
| path="/pushers/set", | ||
| content={ | ||
| "kind": "http", | ||
| "app_id": "m.http", | ||
| "app_display_name": "HTTP Push Notifications", | ||
| "device_display_name": "pushy push", | ||
| "pushkey": "[email protected]", | ||
| "lang": "en", | ||
| "data": {"url": "http://example.com/_matrix/push/v1/notify"}, | ||
| }, | ||
| access_token=access_token, | ||
| ) | ||
|
|
||
| # Look up the user info for the access token so we can compare the device ID. | ||
| store = self.hs.get_datastores().main | ||
| lookup_result = self.get_success(store.get_user_by_access_token(access_token)) | ||
| assert lookup_result is not None | ||
|
|
||
| # Check field is not there before we enable the feature flag | ||
| channel = self.make_request("GET", "/pushers", access_token=access_token) | ||
| self.assertEqual(channel.code, 200) | ||
| self.assertEqual(len(channel.json_body["pushers"]), 1) | ||
| self.assertNotIn( | ||
| "org.matrix.msc3881.device_id", channel.json_body["pushers"][0] | ||
| ) | ||
|
|
||
| self.get_success( | ||
| store.set_features_for_user(user_id, {ExperimentalFeature.MSC3881: True}) | ||
| ) | ||
|
|
||
| # Get the user's devices and check it has the correct device ID. | ||
| channel = self.make_request("GET", "/pushers", access_token=access_token) | ||
| self.assertEqual(channel.code, 200) | ||
| self.assertEqual(len(channel.json_body["pushers"]), 1) | ||
| self.assertEqual( | ||
| channel.json_body["pushers"][0]["org.matrix.msc3881.device_id"], | ||
| lookup_result.device_id, | ||
| ) | ||
|
|
||
| def test_msc3881_client_versions_flag(self) -> None: | ||
| """Tests that MSC3881 only appears in /versions if user has it enabled.""" | ||
|
|
||
| user_id = self.register_user("user", "pass") | ||
| access_token = self.login("user", "pass") | ||
|
|
||
| # Check feature is disabled in /versions | ||
| channel = self.make_request( | ||
| "GET", "/_matrix/client/versions", access_token=access_token | ||
| ) | ||
| self.assertEqual(channel.code, 200) | ||
| self.assertFalse(channel.json_body["unstable_features"]["org.matrix.msc3881"]) | ||
|
|
||
| # Enable feature for user | ||
| self.get_success( | ||
| self.hs.get_datastores().main.set_features_for_user( | ||
| user_id, {ExperimentalFeature.MSC3881: True} | ||
| ) | ||
| ) | ||
|
|
||
| # Check feature is now enabled in /versions for user | ||
| channel = self.make_request( | ||
| "GET", "/_matrix/client/versions", access_token=access_token | ||
| ) | ||
| self.assertEqual(channel.code, 200) | ||
| self.assertTrue(channel.json_body["unstable_features"]["org.matrix.msc3881"]) | ||
|
|
||
| @override_config({"push": {"jitter_delay": "10s"}}) | ||
| def test_jitter(self) -> None: | ||
| """Tests that enabling jitter actually delays sending push.""" | ||
|
|
||
Oops, something went wrong.
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.
We could also have a test for the feature being globally enable - yet disabled for a specific user - if we want to preserve that behaviour.