Fixed hard coded rewriting of html files was fixed on SqlStringInjection
Added testcases for this situation
This commit is contained in:
45
src/test/java/org/owasp/webgoat/plugins/PluginTest.java
Normal file
45
src/test/java/org/owasp/webgoat/plugins/PluginTest.java
Normal file
@ -0,0 +1,45 @@
|
||||
package org.owasp.webgoat.plugins;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
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 java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.matchers.JUnitMatchers.containsString;
|
||||
import static org.junit.matchers.JUnitMatchers.hasItem;
|
||||
|
||||
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("lessons/plugin/TestPlugin/lessonSolutions/en/TestPlugin_files/image001.png")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotRewriteOtherLinksStartingWithLesson_solutions() 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("lesson_solutions/Unknown_files/image001.png")));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user