-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e792f5a
commit 374642b
Showing
8 changed files
with
387 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package htmlpublisher; | ||
|
||
import hudson.model.FreeStyleProject; | ||
import org.junit.Assert; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
import org.jvnet.hudson.test.recipes.LocalData; | ||
|
||
import java.io.File; | ||
|
||
import static hudson.Functions.isWindows; | ||
import static org.junit.Assume.assumeFalse; | ||
|
||
public class Security3301Test { | ||
|
||
@Rule | ||
public JenkinsRule j = new JenkinsRule(); | ||
|
||
@Test | ||
@LocalData | ||
public void security3301sanitizeTest() throws Exception { | ||
|
||
|
||
// Skip on windows | ||
assumeFalse(isWindows()); | ||
|
||
FreeStyleProject job = j.jenkins.getItemByFullName("testJob", FreeStyleProject.class); | ||
|
||
Assert.assertTrue(new File(job.getRootDir(), "htmlreports/HTML_20Report").exists()); | ||
|
||
j.buildAndAssertSuccess(job); | ||
|
||
changeJobReportName(job,"HTML_20Report/javascript:alert(1)"); | ||
|
||
job.save(); | ||
|
||
j.buildAndAssertSuccess(job); | ||
|
||
HtmlPublisherTarget.HTMLAction action = job.getAction(HtmlPublisherTarget.HTMLAction.class); | ||
Assert.assertNotNull(action); | ||
|
||
//Check that the report name is escaped for the Url | ||
Assert.assertEquals("HTML_20Report/javascript:alert(1)", action.getHTMLTarget().getReportName()); | ||
Assert.assertEquals("HTML_5f20Report_2fjavascript_3aalert_281_29", action.getUrlName()); | ||
|
||
Assert.assertTrue(new File(job.getRootDir(), "htmlreports/HTML_5f20Report_2fjavascript_3aalert_281_29").exists()); | ||
|
||
FreeStyleProject anotherJob = j.jenkins.getItemByFullName("anotherJob", FreeStyleProject.class); | ||
|
||
Assert.assertTrue(new File(anotherJob.getRootDir(), "htmlreports/HTML_20Report").exists()); | ||
|
||
j.buildAndAssertSuccess(anotherJob); | ||
|
||
changeJobReportName(job,"../../anotherJob/htmlreports/HTML_20Report"); | ||
|
||
job.save(); | ||
|
||
//Check that the build reports is not from the new job (anotherJob) | ||
Assert.assertEquals("../../anotherJob/htmlreports/HTML_20Report", action.getHTMLTarget().getReportName()); | ||
Assert.assertEquals("_2e_2e_2f_2e_2e_2fanotherJob_2fhtmlreports_2fHTML_5f20Report", action.getUrlName()); | ||
Assert.assertFalse(new File(job.getRootDir(), "htmlreports/_2e_2e_2f_2e_2e_2fanotherJob_2fhtmlreports_2fHTML_5f20Report/test.txt").exists()); | ||
|
||
} | ||
|
||
public void changeJobReportName(FreeStyleProject job, String newName) { | ||
for (Object publisher : job.getPublishersList()) { | ||
if (publisher instanceof HtmlPublisher) { | ||
HtmlPublisher existingPublishHTML = (HtmlPublisher) publisher; | ||
existingPublishHTML.getReportTargets().get(0).setReportName(newName); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...ources/htmlpublisher/Security3301Test/security3301sanitizeTest/jobs/anotherJob/config.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?xml version='1.1' encoding='UTF-8'?> | ||
<project> | ||
<actions/> | ||
<description></description> | ||
<keepDependencies>false</keepDependencies> | ||
<properties/> | ||
<scm class="hudson.scm.NullSCM"/> | ||
<canRoam>true</canRoam> | ||
<disabled>false</disabled> | ||
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding> | ||
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding> | ||
<triggers/> | ||
<concurrentBuild>false</concurrentBuild> | ||
<builders> | ||
<hudson.tasks.Shell> | ||
<command>echo "Test999" > test.txt</command> | ||
<configuredLocalRules/> | ||
</hudson.tasks.Shell> | ||
</builders> | ||
<publishers> | ||
<htmlpublisher.HtmlPublisher plugin="htmlpublisher@1.33-SNAPSHOT"> | ||
<reportTargets> | ||
<htmlpublisher.HtmlPublisherTarget> | ||
<reportName>HTML Report</reportName> | ||
<reportDir></reportDir> | ||
<reportFiles>test.txt</reportFiles> | ||
<alwaysLinkToLastBuild>false</alwaysLinkToLastBuild> | ||
<reportTitles></reportTitles> | ||
<keepAll>false</keepAll> | ||
<allowMissing>false</allowMissing> | ||
<includes>**/*</includes> | ||
<escapeUnderscores>true</escapeUnderscores> | ||
<useWrapperFileDirectly>true</useWrapperFileDirectly> | ||
</htmlpublisher.HtmlPublisherTarget> | ||
</reportTargets> | ||
</htmlpublisher.HtmlPublisher> | ||
</publishers> | ||
<buildWrappers/> | ||
</project> |
Oops, something went wrong.