26
26
import synapse .rest .admin
27
27
from synapse .logging .context import make_deferred_yieldable
28
28
from synapse .push import PusherConfig , PusherConfigException
29
- from synapse .rest .client import login , push_rule , pusher , receipts , room
29
+ from synapse .rest .admin .experimental_features import ExperimentalFeature
30
+ from synapse .rest .client import login , push_rule , pusher , receipts , room , versions
30
31
from synapse .server import HomeServer
31
32
from synapse .types import JsonDict
32
33
from synapse .util import Clock
@@ -42,6 +43,7 @@ class HTTPPusherTests(HomeserverTestCase):
42
43
receipts .register_servlets ,
43
44
push_rule .register_servlets ,
44
45
pusher .register_servlets ,
46
+ versions .register_servlets ,
45
47
]
46
48
user_id = True
47
49
hijack_auth = False
@@ -969,6 +971,84 @@ def test_device_id(self) -> None:
969
971
lookup_result .device_id ,
970
972
)
971
973
974
+ def test_device_id_feature_flag (self ) -> None :
975
+ """Tests that a pusher created with a given device ID shows that device ID in
976
+ GET /pushers requests when feature is enabled for the user
977
+ """
978
+ user_id = self .register_user ("user" , "pass" )
979
+ access_token = self .login ("user" , "pass" )
980
+
981
+ # We create the pusher with an HTTP request rather than with
982
+ # _make_user_with_pusher so that we can test the device ID is correctly set when
983
+ # creating a pusher via an API call.
984
+ self .make_request (
985
+ method = "POST" ,
986
+ path = "/pushers/set" ,
987
+ content = {
988
+ "kind" : "http" ,
989
+ "app_id" : "m.http" ,
990
+ "app_display_name" : "HTTP Push Notifications" ,
991
+ "device_display_name" : "pushy push" ,
992
+
993
+ "lang" : "en" ,
994
+ "data" : {"url" : "http://example.com/_matrix/push/v1/notify" },
995
+ },
996
+ access_token = access_token ,
997
+ )
998
+
999
+ # Look up the user info for the access token so we can compare the device ID.
1000
+ store = self .hs .get_datastores ().main
1001
+ lookup_result = self .get_success (store .get_user_by_access_token (access_token ))
1002
+ assert lookup_result is not None
1003
+
1004
+ # Check field is not there before we enable the feature flag
1005
+ channel = self .make_request ("GET" , "/pushers" , access_token = access_token )
1006
+ self .assertEqual (channel .code , 200 )
1007
+ self .assertEqual (len (channel .json_body ["pushers" ]), 1 )
1008
+ self .assertNotIn (
1009
+ "org.matrix.msc3881.device_id" , channel .json_body ["pushers" ][0 ]
1010
+ )
1011
+
1012
+ self .get_success (
1013
+ store .set_features_for_user (user_id , {ExperimentalFeature .MSC3881 : True })
1014
+ )
1015
+
1016
+ # Get the user's devices and check it has the correct device ID.
1017
+ channel = self .make_request ("GET" , "/pushers" , access_token = access_token )
1018
+ self .assertEqual (channel .code , 200 )
1019
+ self .assertEqual (len (channel .json_body ["pushers" ]), 1 )
1020
+ self .assertEqual (
1021
+ channel .json_body ["pushers" ][0 ]["org.matrix.msc3881.device_id" ],
1022
+ lookup_result .device_id ,
1023
+ )
1024
+
1025
+ def test_msc3881_client_versions_flag (self ) -> None :
1026
+ """Tests that MSC3881 only appears in /versions if user has it enabled."""
1027
+
1028
+ user_id = self .register_user ("user" , "pass" )
1029
+ access_token = self .login ("user" , "pass" )
1030
+
1031
+ # Check feature is disabled in /versions
1032
+ channel = self .make_request (
1033
+ "GET" , "/_matrix/client/versions" , access_token = access_token
1034
+ )
1035
+ self .assertEqual (channel .code , 200 )
1036
+ self .assertFalse (channel .json_body ["unstable_features" ]["org.matrix.msc3881" ])
1037
+
1038
+ # Enable feature for user
1039
+ self .get_success (
1040
+ self .hs .get_datastores ().main .set_features_for_user (
1041
+ user_id , {ExperimentalFeature .MSC3881 : True }
1042
+ )
1043
+ )
1044
+
1045
+ # Check feature is now enabled in /versions for user
1046
+ channel = self .make_request (
1047
+ "GET" , "/_matrix/client/versions" , access_token = access_token
1048
+ )
1049
+ self .assertEqual (channel .code , 200 )
1050
+ self .assertTrue (channel .json_body ["unstable_features" ]["org.matrix.msc3881" ])
1051
+
972
1052
@override_config ({"push" : {"jitter_delay" : "10s" }})
973
1053
def test_jitter (self ) -> None :
974
1054
"""Tests that enabling jitter actually delays sending push."""
0 commit comments