misc: abort requests if site-options is invalid (#53587) #562
|
@ -207,3 +207,10 @@ def test_myspace_redirect(pub):
|
|||
|
||||
resp = get_app(pub).get('/myspace/', status=302)
|
||||
assert resp.location == 'https://idp/account/'
|
||||
|
||||
|
||||
def test_invalid_site_options(pub):
|
||||
with open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w') as fd:
|
||||
fd.write('xxx')
|
||||
with pytest.raises(Exception):
|
||||
get_app(pub).get('/', status=500)
|
||||
|
|
|
@ -420,11 +420,13 @@ class QommonPublisher(Publisher):
|
|||
site_options_filename = os.path.join(self.app_dir, 'site-options.cfg')
|
||||
if not os.path.exists(site_options_filename):
|
||||
return
|
||||
self.site_options_exception = None
|
||||
try:
|
||||
self.site_options.read(site_options_filename, encoding='utf-8')
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
self.get_app_logger().error('failed to read site options file')
|
||||
return
|
||||
# keep track of exception, to be raised later
|
||||
self.site_options_exception = e
|
||||
|
||||
def has_site_option(self, option, default=False):
|
||||
if self.site_options is None:
|
||||
|
|
|
@ -283,6 +283,8 @@ class RootDirectory(Directory):
|
|||
get_publisher().substitutions.feed(get_request().user)
|
||||
|
||||
def _q_traverse(self, path):
|
||||
if get_publisher().site_options_exception:
|
||||
|
||||
raise Exception('invalid site options') from get_publisher().site_options_exception
|
||||
if path and path[0] == 'manage':
|
||||
return redirect('/backoffice' + get_request().get_path_query().removeprefix('/manage'))
|
||||
|
||||
|
|
Loading…
Reference in New Issue
J'aurais écrit « is not None: » ici mais ça marchera bien ainsi.