1919#
2020#
2121
22+ import argparse
23+
2224import synapse .app .homeserver
2325from synapse .config import ConfigError
2426from synapse .config .homeserver import HomeServerConfig
@@ -99,6 +101,10 @@ def test_session_lifetime_must_not_be_exceeded_by_smaller_lifetimes(self) -> Non
99101 )
100102
101103 def test_refuse_to_start_if_open_registration_and_no_verification (self ) -> None :
104+ """
105+ Test that our utilities to start the main Synapse homeserver process refuses
106+ to start if we detect open registration.
107+ """
102108 self .generate_config ()
103109 self .add_lines_to_config (
104110 [
@@ -111,7 +117,7 @@ def test_refuse_to_start_if_open_registration_and_no_verification(self) -> None:
111117 )
112118
113119 # Test that allowing open registration without verification raises an error
114- with self .assertRaises (ConfigError ):
120+ with self .assertRaises (SystemExit ):
115121 # Do a normal homeserver creation and setup
116122 homeserver_config = synapse .app .homeserver .load_or_generate_config (
117123 ["-c" , self .config_file ]
@@ -122,3 +128,76 @@ def test_refuse_to_start_if_open_registration_and_no_verification(self) -> None:
122128 # earlier, but in the future, the code could be refactored to raise the
123129 # error in a different place.
124130 synapse .app .homeserver .setup (hs )
131+
132+ def test_load_config_error_if_open_registration_and_no_verification (self ) -> None :
133+ """
134+ Test that `HomeServerConfig.load_config(...)` raises an exception when we detect open
135+ registration.
136+ """
137+ self .generate_config ()
138+ self .add_lines_to_config (
139+ [
140+ " " ,
141+ "enable_registration: true" ,
142+ "registrations_require_3pid: []" ,
143+ "enable_registration_captcha: false" ,
144+ "registration_requires_token: false" ,
145+ ]
146+ )
147+
148+ # Test that allowing open registration without verification raises an error
149+ with self .assertRaises (ConfigError ):
150+ _homeserver_config = HomeServerConfig .load_config (
151+ description = "test" , argv_options = ["-c" , self .config_file ]
152+ )
153+
154+ def test_load_or_generate_config_error_if_open_registration_and_no_verification (
155+ self ,
156+ ) -> None :
157+ """
158+ Test that `HomeServerConfig.load_or_generate_config(...)` raises an exception when we detect open
159+ registration.
160+ """
161+ self .generate_config ()
162+ self .add_lines_to_config (
163+ [
164+ " " ,
165+ "enable_registration: true" ,
166+ "registrations_require_3pid: []" ,
167+ "enable_registration_captcha: false" ,
168+ "registration_requires_token: false" ,
169+ ]
170+ )
171+
172+ # Test that allowing open registration without verification raises an error
173+ with self .assertRaises (ConfigError ):
174+ _homeserver_config = HomeServerConfig .load_or_generate_config (
175+ description = "test" , argv_options = ["-c" , self .config_file ]
176+ )
177+
178+ def test_load_config_with_parser_error_if_open_registration_and_no_verification (
179+ self ,
180+ ) -> None :
181+ """
182+ Test that `HomeServerConfig.load_config_with_parser(...)` raises an exception when we detect open
183+ registration.
184+ """
185+ self .generate_config ()
186+ self .add_lines_to_config (
187+ [
188+ " " ,
189+ "enable_registration: true" ,
190+ "registrations_require_3pid: []" ,
191+ "enable_registration_captcha: false" ,
192+ "registration_requires_token: false" ,
193+ ]
194+ )
195+
196+ # Test that allowing open registration without verification raises an error
197+ with self .assertRaises (ConfigError ):
198+ config_parser = argparse .ArgumentParser (description = "test" )
199+ HomeServerConfig .add_arguments_to_parser (config_parser )
200+
201+ _homeserver_config = HomeServerConfig .load_config_with_parser (
202+ parser = config_parser , argv_options = ["-c" , self .config_file ]
203+ )
0 commit comments