Moved Maven multiproject setup
This commit is contained in:
@ -0,0 +1,40 @@
|
||||
package org.owasp.webgoat.plugins;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class GlobalPropertiesTest {
|
||||
|
||||
@Test
|
||||
public void propertyFilesShouldBeLoaded() throws IOException {
|
||||
Path tempDirectory = PluginTestHelper.createTmpDir();
|
||||
Path pluginDirectory = Files.createDirectory(Paths.get(tempDirectory.toString(), "plugins"));
|
||||
Path directory = Files.createDirectory(Paths.get(tempDirectory.toString(), "i18n"));
|
||||
Path globalProperties = Files.createFile(Paths.get(directory.toString(), "global.properties"));
|
||||
Files.write(globalProperties, Arrays.asList("test=label for test"), StandardCharsets.UTF_8);
|
||||
new GlobalProperties(pluginDirectory).loadProperties(directory);
|
||||
|
||||
ClassLoader propertyFilesClassLoader =
|
||||
ResourceBundleClassLoader.createPropertyFilesClassLoader();
|
||||
assertNotNull(propertyFilesClassLoader.getResourceAsStream("global.properties"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void propertyFilesDirectoryNotFoundShouldRaiseError() throws IOException {
|
||||
Path tempDirectory = PluginTestHelper.createTmpDir();
|
||||
Path pluginDirectory = Files.createDirectory(Paths.get(tempDirectory.toString(), "plugins"));
|
||||
Path directory = Files.createDirectory(Paths.get(tempDirectory.toString(), "i18n"));
|
||||
Files.delete(directory);
|
||||
|
||||
new GlobalProperties(pluginDirectory).loadProperties(directory);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package org.owasp.webgoat.plugins;
|
||||
|
||||
public class PluginTest {
|
||||
|
||||
// @Test
|
||||
// public void pathShouldBeRewrittenInHtmlFile() throws Exception {
|
||||
// Path tmpDir = PluginTestHelper.createTmpDir();
|
||||
// Path pluginSourcePath = PluginTestHelper.pathForLoading();
|
||||
// Plugin plugin = PluginTestHelper.createPluginFor(TestPlugin.class);
|
||||
// Path htmlFile = Paths.get(pluginSourcePath.toString(), "lessonSolutions", "rewrite_test.html");
|
||||
// plugin.loadFiles(Arrays.asList(htmlFile), true);
|
||||
// plugin.rewritePaths(tmpDir);
|
||||
// List<String> allLines = Files.readAllLines(htmlFile, StandardCharsets.UTF_8);
|
||||
//
|
||||
// assertThat(allLines,
|
||||
// hasItem(containsString("plugin/TestPlugin/lessonSolutions/en/TestPlugin_files/image001.png")));
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void shouldNotRewriteOtherLinks() throws Exception {
|
||||
// Path tmpDir = PluginTestHelper.createTmpDir();
|
||||
// Path pluginSourcePath = PluginTestHelper.pathForLoading();
|
||||
// Plugin plugin = PluginTestHelper.createPluginFor(TestPlugin.class);
|
||||
// Path htmlFile = Paths.get(pluginSourcePath.toString(), "lessonSolutions", "rewrite_test.html");
|
||||
// plugin.loadFiles(Arrays.asList(htmlFile), true);
|
||||
// plugin.rewritePaths(tmpDir);
|
||||
// List<String> allLines = Files.readAllLines(htmlFile, StandardCharsets.UTF_8);
|
||||
//
|
||||
// assertThat(allLines,
|
||||
// hasItem(containsString("Unknown_files/image001.png")));
|
||||
// }
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package org.owasp.webgoat.plugins;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class PluginTestHelper {
|
||||
|
||||
private static Path tempDirectory;
|
||||
|
||||
public static Path createTmpDir() throws IOException {
|
||||
tempDirectory = Files.createTempDirectory(PluginTestHelper.class.getSimpleName());
|
||||
tempDirectory.toFile().deleteOnExit();
|
||||
return tempDirectory;
|
||||
}
|
||||
|
||||
public static Path pathForLoading() throws IOException, URISyntaxException {
|
||||
Path path = Paths.get(PluginTestHelper.class.getProtectionDomain().getCodeSource().getLocation().toURI());
|
||||
return Paths.get(path.toString(), "org/owasp/webgoat/plugins");
|
||||
}
|
||||
|
||||
// public static Plugin createPluginFor(Class pluginClass) throws Exception {
|
||||
// Path pluginTargetPath = Files.createDirectory(Paths.get(tempDirectory.toString(), "pluginTargetPath"));
|
||||
// Map<String, byte[]> classes = new HashMap<>();
|
||||
// classes.put(pluginClass.getName(), Files.readAllBytes(Paths.get(pathForLoading().toString(), pluginClass.getSimpleName() + ".class")));
|
||||
// Plugin plugin = new Plugin(pluginTargetPath, classes);
|
||||
// return plugin;
|
||||
// }
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package org.owasp.webgoat.plugins;
|
||||
|
||||
import org.owasp.webgoat.lessons.SequentialLessonAdapter;
|
||||
|
||||
public class TestPlugin extends SequentialLessonAdapter {
|
||||
}
|
7
webgoat-container/src/test/resources/log4j.properties
Normal file
7
webgoat-container/src/test/resources/log4j.properties
Normal file
@ -0,0 +1,7 @@
|
||||
log4j.rootLogger=DEBUG, CONSOLE
|
||||
|
||||
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.CONSOLE.Target=System.out
|
||||
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.CONSOLE.layout.conversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p - %m%n
|
||||
|
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head lang="en">
|
||||
<meta charset="UTF-8">
|
||||
<title></title>
|
||||
</head>
|
||||
<body>
|
||||
<v:imagedata src="TestPlugin_files/image001.png" o:title=""/>
|
||||
<v:imagedata src="Unknown_files/image001.png" o:title=""/>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user