mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2024-12-23 07:33:27 -06:00
91706690e0
Dynamic plugin registry returns as a plugin any folder within the plugins directory. Web UI then attempts to load for each plugin 'foo' a JavaScript file named 'foo/foo.js'. The problem is that if 'foo/foo.js' does not exist, Web UI breaks and it is impossible to recover until the empty folder is removed or 'foo/foo.js' (even empty) is created at the server side. Check that 'foo/foo.js' actual exists when including a plugin into the registry. Test the registry generator by creating fake plugins and removing them during the test. Fixes: https://pagure.io/freeipa/issue/8567 Signed-off-by: Alexander Bokovoy <abokovoy@redhat.com> Reviewed-By: Florence Blanc-Renaud <frenaud@redhat.com>
63 lines
1.9 KiB
Python
63 lines
1.9 KiB
Python
# Authors: Petr Vobornik <pvoborni@redhat.com>
|
|
#
|
|
# Copyright (C) 2013 Red Hat
|
|
# see file 'COPYING' for use and warranty information
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
#
|
|
|
|
"""
|
|
Plugin index generation script
|
|
"""
|
|
from __future__ import absolute_import
|
|
|
|
import logging
|
|
import os
|
|
from ipaplatform.paths import paths
|
|
|
|
logger = logging.getLogger(os.path.basename(__file__))
|
|
|
|
|
|
def get_plugin_index():
|
|
|
|
if not os.path.isdir(paths.IPA_JS_PLUGINS_DIR):
|
|
raise Exception("Supplied plugin directory path is not a directory")
|
|
|
|
dirs = os.listdir(paths.IPA_JS_PLUGINS_DIR)
|
|
index = 'define([],function(){return['
|
|
for x in dirs:
|
|
p = os.path.join(paths.IPA_JS_PLUGINS_DIR, x, x + '.js')
|
|
if os.path.exists(p):
|
|
index += "'" + x + "',"
|
|
index += '];});'
|
|
return index.encode('utf-8')
|
|
|
|
def get_failed():
|
|
return (
|
|
b'define([],function(){return[];});/*error occured: serving default */'
|
|
)
|
|
|
|
def application(environ, start_response):
|
|
try:
|
|
index = get_plugin_index()
|
|
status = '200 OK'
|
|
except Exception as e:
|
|
logger.error('plugin index generation failed: %s', e)
|
|
status = '200 OK'
|
|
index = get_failed()
|
|
headers = [('Content-type', 'application/javascript'),
|
|
('Content-Length', str(len(index)))]
|
|
start_response(status, headers)
|
|
return [index]
|