misc: abort requests if site-options is invalid (#53587) #562

Merged
fpeters merged 1 commits from wip/53587-error-on-invalid-site-options into main 2023-08-11 00:31:14 +02:00
3 changed files with 13 additions and 2 deletions

View File

@ -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)

View File

@ -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:

View File

@ -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:
Review

J'aurais écrit « is not None: » ici mais ça marchera bien ainsi.

J'aurais écrit « is not None: » ici mais ça marchera bien ainsi.
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'))