2626from synapse .types import JsonDict , UserID
2727
2828from tests import unittest
29- from tests .rest .client .v1 .utils import TEST_OIDC_CONFIG
29+ from tests .handlers .test_oidc import HAS_OIDC
30+ from tests .rest .client .v1 .utils import TEST_OIDC_CONFIG as BASE_OIDC_CONFIG
3031from tests .server import FakeChannel
32+ from tests .test_utils import skip_unless
33+ from tests .unittest import override_config
3134
3235
3336class DummyRecaptchaChecker (UserInteractiveAuthChecker ):
@@ -147,6 +150,12 @@ def test_complete_operation_unknown_session(self):
147150 self .recaptcha (session , 400 , session + "unknown" )
148151
149152
153+ # we enable OIDC as a way of testing SSO flows
154+ TEST_OIDC_CONFIG = {}
155+ TEST_OIDC_CONFIG .update (BASE_OIDC_CONFIG )
156+ TEST_OIDC_CONFIG ["allow_existing_users" ] = True
157+
158+
150159class UIAuthTests (unittest .HomeserverTestCase ):
151160 servlets = [
152161 auth .register_servlets ,
@@ -158,20 +167,14 @@ class UIAuthTests(unittest.HomeserverTestCase):
158167
159168 def default_config (self ):
160169 config = super ().default_config ()
161-
162- # we enable OIDC as a way of testing SSO flows
163- oidc_config = {}
164- oidc_config .update (TEST_OIDC_CONFIG )
165- oidc_config ["allow_existing_users" ] = True
166-
167- config ["oidc_config" ] = oidc_config
168170 config ["public_baseurl" ] = "https://synapse.test"
169171 return config
170172
171173 def create_resource_dict (self ):
172174 resource_dict = super ().create_resource_dict ()
173- # mount the OIDC resource at /_synapse/oidc
174- resource_dict ["/_synapse/oidc" ] = OIDCResource (self .hs )
175+ if HAS_OIDC :
176+ # mount the OIDC resource at /_synapse/oidc
177+ resource_dict ["/_synapse/oidc" ] = OIDCResource (self .hs )
175178 return resource_dict
176179
177180 def prepare (self , reactor , clock , hs ):
@@ -380,6 +383,8 @@ def test_can_reuse_session(self):
380383 # Note that *no auth* information is provided, not even a session iD!
381384 self .delete_device (self .user_tok , self .device_id , 200 )
382385
386+ @skip_unless (HAS_OIDC , "requires OIDC" )
387+ @override_config ({"oidc_config" : TEST_OIDC_CONFIG })
383388 def test_does_not_offer_password_for_sso_user (self ):
384389 login_resp = self .helper .login_via_oidc ("username" )
385390 user_tok = login_resp ["access_token" ]
@@ -393,13 +398,13 @@ def test_does_not_offer_password_for_sso_user(self):
393398 self .assertEqual (flows , [{"stages" : ["m.login.sso" ]}])
394399
395400 def test_does_not_offer_sso_for_password_user (self ):
396- # now call the device deletion API: we should get the option to auth with SSO
397- # and not password.
398401 channel = self .delete_device (self .user_tok , self .device_id , 401 )
399402
400403 flows = channel .json_body ["flows" ]
401404 self .assertEqual (flows , [{"stages" : ["m.login.password" ]}])
402405
406+ @skip_unless (HAS_OIDC , "requires OIDC" )
407+ @override_config ({"oidc_config" : TEST_OIDC_CONFIG })
403408 def test_offers_both_flows_for_upgraded_user (self ):
404409 """A user that had a password and then logged in with SSO should get both flows
405410 """
0 commit comments