Skip to content

Commit a2477f6

Browse files
committed
Extend test to cover more complex dir structure
1 parent fa4ec0a commit a2477f6

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

test/src/test/java/jenkins/security/ResourceDomainTest.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,12 +321,24 @@ public void testMoreUrlEncoding() throws Exception {
321321
webClient.setThrowExceptionOnFailingStatusCode(false);
322322
webClient.setRedirectEnabled(true);
323323

324-
Page page = webClient.goTo("100%25%20evil/%20100%25%20evil%20content%20.html");
324+
Page page = webClient.goTo("100%25%20evil/%20100%25%20evil%20dir%20name%20%20%20/%20100%25%20evil%20content%20.html");
325325
Assert.assertEquals("page is found", 200, page.getWebResponse().getStatusCode());
326326
Assert.assertTrue("page content is as expected", page.getWebResponse().getContentAsString().contains("this is the content"));
327327

328328
URL url = page.getUrl();
329329
Assert.assertTrue("page is served by resource domain", url.toString().contains("/static-files/"));
330+
331+
URL dirUrl = new URL(url.toString().replace("%20100%25%20evil%20content%20.html", ""));
332+
Page dirPage = webClient.getPage(dirUrl);
333+
Assert.assertEquals("page is found", 200, dirPage.getWebResponse().getStatusCode());
334+
Assert.assertTrue("page content is HTML", dirPage.getWebResponse().getContentAsString().contains("href"));
335+
Assert.assertTrue("page content references file", dirPage.getWebResponse().getContentAsString().contains("evil content"));
336+
337+
URL topDirUrl = new URL(url.toString().replace("%20100%25%20evil%20dir%20name%20%20%20/%20100%25%20evil%20content%20.html", ""));
338+
Page topDirPage = webClient.getPage(topDirUrl);
339+
Assert.assertEquals("page is found", 200, topDirPage.getWebResponse().getStatusCode());
340+
Assert.assertTrue("page content is HTML", topDirPage.getWebResponse().getContentAsString().contains("href"));
341+
Assert.assertTrue("page content references directory", topDirPage.getWebResponse().getContentAsString().contains("evil dir name"));
330342
}
331343

332344
@TestExtension
@@ -353,8 +365,8 @@ public String getUrlName() {
353365
public HttpResponse doDynamic() throws Exception {
354366
Jenkins jenkins = Jenkins.get();
355367
FilePath tempDir = jenkins.getRootPath().createTempDir("root", "tmp");
356-
tempDir.child(" 100% evil content .html").write("this is the content", "UTF-8");
357-
return new DirectoryBrowserSupport(jenkins, tempDir, "title", "", false);
368+
tempDir.child(" 100% evil dir name ").child(" 100% evil content .html").write("this is the content", "UTF-8");
369+
return new DirectoryBrowserSupport(jenkins, tempDir, "title", "", true);
358370
}
359371
}
360372
}

0 commit comments

Comments
 (0)