Skip to content
Snippets Groups Projects
Commit c6c7fba9 authored by felmer's avatar felmer
Browse files

LMS-2612 ignore . files/folders, do not allow ' ', ',', '=' in plugin names

SVN: 24534
parent 87c70208
No related branches found
No related tags found
No related merge requests found
......@@ -52,6 +52,8 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.CorePlugin;
*/
class CorePluginsInjector
{
private static final String UNALLOWED_PLUGIN_NAME_CHARACTERS = " ,=";
static final String CORE_PLUGINS_FOLDER_KEY = "core-plugins-folder";
static final String PLUGIN_PROPERTIES_FILE_NAME = "plugin.properties";
......@@ -188,8 +190,17 @@ class CorePluginsInjector
File file = new File(dssFolder, pluginType.getSubFolderName());
if (file.isDirectory())
{
for (File definingFolder : file.listFiles())
File[] pluginFolders = file.listFiles(new FilenameFilter()
{
public boolean accept(File dir, String name)
{
return name.startsWith(".") == false;
}
});
for (File pluginFolder : pluginFolders)
{
String pluginName = pluginFolder.getName();
assertValidPluginName(pluginName);
Map<String, DssCorePlugin> map = typeToPluginsMap.get(pluginType);
if (map == null)
{
......@@ -197,8 +208,7 @@ class CorePluginsInjector
typeToPluginsMap.put(pluginType, map);
}
DssCorePlugin plugin =
new DssCorePlugin(technology, pluginType, definingFolder);
String pluginName = definingFolder.getName();
new DssCorePlugin(technology, pluginType, pluginFolder);
if (pluginType.isUniquePluginNameRequired())
{
if (pluginNames.contains(pluginName))
......@@ -216,6 +226,19 @@ class CorePluginsInjector
return typeToPluginsMap;
}
private void assertValidPluginName(String pluginName)
{
for (int i = 0; i < UNALLOWED_PLUGIN_NAME_CHARACTERS.length(); i++)
{
char c = UNALLOWED_PLUGIN_NAME_CHARACTERS.charAt(i);
if (pluginName.contains(Character.toString(c)))
{
throw new EnvironmentFailureException("Plugin name contains '" + c + "': "
+ pluginName);
}
}
}
/**
* Load plugin properties file where all references to script names are replaced by script paths.
*/
......
......@@ -107,6 +107,28 @@ public class CorePluginsInjectorTest extends AbstractFileSystemTestCase
context.assertIsSatisfied();
}
@Test
public void testInvalidPluginNameAndIgnoringDotFilesAndFolders() throws IOException
{
File alpha = new File(corePluginsFolder, "screening/1/dss/drop-boxes/a b");
alpha.mkdirs();
new File(alpha.getParentFile(), ".svn").mkdirs();
new File(alpha.getParentFile(), ".blabla").createNewFile();
Properties properties = createProperties();
properties.setProperty(INPUT_THREAD_NAMES, "a, b");
try
{
injector.injectCorePlugins(properties);
fail("EnvironmentFailureException expected.");
} catch (EnvironmentFailureException ex)
{
assertEquals("Plugin name contains ' ': a b", ex.getMessage());
}
context.assertIsSatisfied();
}
@Test
public void testPluginIsNotAFolder() throws IOException
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment