@@ -107,6 +107,12 @@ public class DirectoryBrowserSupportTest {
107107
108108 @ Rule public JenkinsRule j = new JenkinsRule ();
109109
110+ private JenkinsRule .WebClient getWebClient () {
111+ var wc = j .createWebClient ();
112+ wc .getOptions ().setJavaScriptEnabled (false );
113+ return wc ;
114+ }
115+
110116 /**
111117 * Double dots that appear in file name is OK.
112118 */
@@ -122,7 +128,7 @@ public void doubleDots() throws Exception {
122128 j .buildAndAssertSuccess (p );
123129
124130 // can we see it?
125- j . createWebClient ().goTo ("job/" + p .getName () + "/ws/abc..def" , "application/octet-stream" );
131+ getWebClient ().goTo ("job/" + p .getName () + "/ws/abc..def" , "application/octet-stream" );
126132
127133 // TODO: implement negative check to make sure we aren't serving unexpected directories.
128134 // the following trivial attempt failed. Someone in between is normalizing.
@@ -149,7 +155,7 @@ public void doubleDots2() throws Exception {
149155 p .getBuildersList ().add (new Shell ("mkdir abc; touch abc/def.bin" ));
150156 j .buildAndAssertSuccess (p );
151157
152- try (JenkinsRule .WebClient wc = j . createWebClient ()) {
158+ try (JenkinsRule .WebClient wc = getWebClient ()) {
153159 // normal path provided by the UI succeeds
154160 Page page = wc .goTo ("job/" + p .getName () + "/ws/abc%5Cdef.bin" , "application/octet-stream" );
155161 assertEquals (200 , page .getWebResponse ().getStatusCode ());
@@ -170,7 +176,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
170176 j .buildAndAssertSuccess (p );
171177
172178 // can we see it?
173- j . createWebClient ().goTo ("job/" + p .getName () + "/ws/%e6%bc%a2%e5%ad%97.bin" , "application/octet-stream" );
179+ getWebClient ().goTo ("job/" + p .getName () + "/ws/%e6%bc%a2%e5%ad%97.bin" , "application/octet-stream" );
174180 }
175181
176182 @ Test
@@ -190,7 +196,7 @@ public void glob() throws Exception {
190196 }
191197 });
192198 j .buildAndAssertSuccess (p );
193- String text = j . createWebClient ().goTo ("job/" + p .getName () + "/ws/**/*.java" ).asNormalizedText ();
199+ String text = getWebClient ().goTo ("job/" + p .getName () + "/ws/**/*.java" ).asNormalizedText ();
194200 assertTrue (text , text .contains ("X.java" ));
195201 assertTrue (text , text .contains ("XTest.java" ));
196202 assertFalse (text , text .contains ("pom.xml" ));
@@ -205,7 +211,7 @@ public void zipDownload() throws Exception {
205211 p .getPublishersList ().add (new ArtifactArchiver ("*" , "" , true ));
206212 j .buildAndAssertSuccess (p );
207213
208- HtmlPage page = j . createWebClient ().goTo ("job/" + p .getName () + "/lastSuccessfulBuild/artifact/" );
214+ HtmlPage page = getWebClient ().goTo ("job/" + p .getName () + "/lastSuccessfulBuild/artifact/" );
209215 Page download = page .getAnchorByHref ("./*zip*/archive.zip" ).click ();
210216 File zipfile = download ((UnexpectedPage ) download );
211217
@@ -231,7 +237,7 @@ public void zipDownloadFileLeakMx_hypothesis() throws Exception {
231237 p .getPublishersList ().add (new ArtifactArchiver ("*" , "" , true ));
232238 j .buildAndAssertSuccess (p );
233239
234- HtmlPage page = j . createWebClient ().goTo ("job/" + p .getName () + "/lastSuccessfulBuild/artifact/" );
240+ HtmlPage page = getWebClient ().goTo ("job/" + p .getName () + "/lastSuccessfulBuild/artifact/" );
235241 Page downloadPage = page .getAnchorByHref ("artifact.out" ).click ();
236242 assertEquals (content , downloadPage .getWebResponse ().getContentAsString ());
237243 }
@@ -254,7 +260,7 @@ public void zipDownloadFileLeakMx() throws Exception {
254260 p .getPublishersList ().add (new ArtifactArchiver ("*" , "" , true ));
255261 j .buildAndAssertSuccess (p );
256262
257- HtmlPage page = j . createWebClient ().goTo ("job/" + p .getName () + "/lastSuccessfulBuild/artifact/" );
263+ HtmlPage page = getWebClient ().goTo ("job/" + p .getName () + "/lastSuccessfulBuild/artifact/" );
258264 for (int clicks = 0 ; clicks < numOfClicks ; clicks ++) {
259265 page .getAnchorByHref ("artifact.out" ).click ();
260266 }
@@ -308,7 +314,7 @@ public void contentSecurityPolicy() throws Exception {
308314 p .getPublishersList ().add (new ArtifactArchiver ("*" , "" , true ));
309315 j .buildAndAssertSuccess (p );
310316
311- HtmlPage page = j . createWebClient ().goTo ("job/" + p .getName () + "/lastSuccessfulBuild/artifact/test.html" );
317+ HtmlPage page = getWebClient ().goTo ("job/" + p .getName () + "/lastSuccessfulBuild/artifact/test.html" );
312318 for (String header : new String []{"Content-Security-Policy" , "X-WebKit-CSP" , "X-Content-Security-Policy" }) {
313319 assertEquals ("Header set: " + header , DirectoryBrowserSupport .DEFAULT_CSP_VALUE , page .getWebResponse ().getResponseHeaderValue (header ));
314320 }
@@ -317,7 +323,7 @@ public void contentSecurityPolicy() throws Exception {
317323 String initialValue = System .getProperty (propName );
318324 try {
319325 System .setProperty (propName , "" );
320- page = j . createWebClient ().goTo ("job/" + p .getName () + "/lastSuccessfulBuild/artifact/test.html" );
326+ page = getWebClient ().goTo ("job/" + p .getName () + "/lastSuccessfulBuild/artifact/test.html" );
321327 List <String > headers = page .getWebResponse ().getResponseHeaders ().stream ().map (NameValuePair ::getName ).collect (Collectors .toList ());
322328 for (String header : new String []{"Content-Security-Policy" , "X-WebKit-CSP" , "X-Content-Security-Policy" }) {
323329 assertThat (headers , not (hasItem (header )));
@@ -351,7 +357,7 @@ public void externalURLDownload() throws Exception {
351357 p .setScm (new SingleFileSCM ("f" , "Hello world!" ));
352358 p .getPublishersList ().add (new ArtifactArchiver ("f" ));
353359 j .buildAndAssertSuccess (p );
354- HtmlPage page = j . createWebClient ().goTo ("job/" + p .getName () + "/lastSuccessfulBuild/artifact/" );
360+ HtmlPage page = getWebClient ().goTo ("job/" + p .getName () + "/lastSuccessfulBuild/artifact/" );
355361 Page download = page .getAnchorByText ("f" ).click ();
356362 assertEquals ("Hello world!" , download .getWebResponse ().getContentAsString ());
357363 }
@@ -614,7 +620,7 @@ public void symlink_outsideWorkspace_areNotAllowed() throws Exception {
614620
615621 j .buildAndAssertSuccess (p );
616622
617- JenkinsRule .WebClient wc = j . createWebClient ();
623+ JenkinsRule .WebClient wc = getWebClient ();
618624 wc .getOptions ().setThrowExceptionOnFailingStatusCode (false );
619625 { // workspace root must be reachable (regular case)
620626 Page page = wc .goTo (p .getUrl () + "ws/" , null );
@@ -759,7 +765,7 @@ public void symlink_avoidLeakingInformation_aboutIllegalFolder() throws Exceptio
759765
760766 j .buildAndAssertSuccess (p );
761767
762- JenkinsRule .WebClient wc = j . createWebClient ();
768+ JenkinsRule .WebClient wc = getWebClient ();
763769 wc .getOptions ().setThrowExceptionOnFailingStatusCode (false );
764770
765771 // the pattern allow us to search inside the files / folders,
@@ -822,7 +828,7 @@ public void junctionAndSymlink_outsideWorkspace_areNotAllowed_windowsJunction()
822828
823829 j .buildAndAssertSuccess (p );
824830
825- JenkinsRule .WebClient wc = j . createWebClient ();
831+ JenkinsRule .WebClient wc = getWebClient ();
826832 wc .getOptions ().setThrowExceptionOnFailingStatusCode (false );
827833 { // workspace root must be reachable (regular case)
828834 Page page = wc .goTo (p .getUrl () + "ws/" , null );
@@ -975,7 +981,7 @@ public void directSymlink_forTestingZip() throws Exception {
975981 c3 .mkdirs ();
976982 c3 .child ("to_secrets3" ).symlinkTo (secretsFolder .getAbsolutePath (), TaskListener .NULL );
977983
978- JenkinsRule .WebClient wc = j . createWebClient ();
984+ JenkinsRule .WebClient wc = getWebClient ();
979985 wc .getOptions ().setThrowExceptionOnFailingStatusCode (false );
980986 {
981987 Page zipPage = wc .goTo (p .getUrl () + "ws/*zip*/ws.zip" , null );
@@ -1042,7 +1048,7 @@ public void symlink_insideWorkspace_areNotAllowedAnymore() throws Exception {
10421048
10431049 j .buildAndAssertSuccess (p );
10441050
1045- JenkinsRule .WebClient wc = j . createWebClient ();
1051+ JenkinsRule .WebClient wc = getWebClient ();
10461052 wc .getOptions ().setThrowExceptionOnFailingStatusCode (false );
10471053 { // workspace root must be reachable (regular case)
10481054 Page page = wc .goTo (p .getUrl () + "ws/" , null );
@@ -1111,7 +1117,7 @@ public void windows_cannotViewAbsolutePath() throws Exception {
11111117 String content = "random data provided as fixed value" ;
11121118 Files .writeString (targetTmpPath , content , StandardCharsets .UTF_8 );
11131119
1114- try (JenkinsRule .WebClient wc = j . createWebClient ()) {
1120+ try (JenkinsRule .WebClient wc = getWebClient ()) {
11151121 wc .setThrowExceptionOnFailingStatusCode (false );
11161122 HtmlPage page = wc .goTo ("userContent/" + targetTmpPath .toAbsolutePath () + "/*view*" );
11171123 assertEquals (404 , page .getWebResponse ().getStatusCode ());
@@ -1133,7 +1139,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
11331139 });
11341140 assertEquals (Result .SUCCESS , p .scheduleBuild2 (0 ).get ().getResult ());
11351141
1136- String text = j . createWebClient ().goTo ("job/" + p .getName () + "/ws/" ).asNormalizedText ();
1142+ String text = getWebClient ().goTo ("job/" + p .getName () + "/ws/" ).asNormalizedText ();
11371143 assertTrue (text , text .contains ("anotherDir" ));
11381144 assertFalse (text , text .contains ("subdir" ));
11391145 }
@@ -1163,7 +1169,7 @@ public void tmpNotListedWithGlob() throws Exception {
11631169
11641170 assertEquals (Result .SUCCESS , p .scheduleBuild2 (0 ).get ().getResult ());
11651171
1166- String text = j . createWebClient ().goTo ("job/" + p .getName () + "/ws/**/*.txt" ).asNormalizedText ();
1172+ String text = getWebClient ().goTo ("job/" + p .getName () + "/ws/**/*.txt" ).asNormalizedText ();
11671173 assertTrue (text , text .contains ("one.txt" ));
11681174 assertTrue (text , text .contains ("two.txt" ));
11691175 assertFalse (text , text .contains ("three.txt" ));
@@ -1192,7 +1198,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
11921198 });
11931199 assertEquals (Result .SUCCESS , p .scheduleBuild2 (0 ).get ().getResult ());
11941200
1195- JenkinsRule .WebClient wc = j . createWebClient ();
1201+ JenkinsRule .WebClient wc = getWebClient ();
11961202 wc .getOptions ().setThrowExceptionOnFailingStatusCode (false );
11971203
11981204 Page page = wc .goTo (p .getUrl () + "ws/anotherDir/" , null );
@@ -1222,7 +1228,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
12221228 });
12231229 assertEquals (Result .SUCCESS , p .scheduleBuild2 (0 ).get ().getResult ());
12241230
1225- String text = j . createWebClient ().goTo ("job/" + p .getName () + "/ws/*plain*" , "text/plain" ).getWebResponse ().getContentAsString ();
1231+ String text = getWebClient ().goTo ("job/" + p .getName () + "/ws/*plain*" , "text/plain" ).getWebResponse ().getContentAsString ();
12261232 assertTrue (text , text .contains ("anotherDir" ));
12271233 assertFalse (text , text .contains ("subdir" ));
12281234 }
@@ -1255,7 +1261,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
12551261 });
12561262 assertEquals (Result .SUCCESS , p .scheduleBuild2 (0 ).get ().getResult ());
12571263
1258- JenkinsRule .WebClient wc = j . createWebClient ();
1264+ JenkinsRule .WebClient wc = getWebClient ();
12591265 wc .getOptions ().setThrowExceptionOnFailingStatusCode (false );
12601266
12611267 //http://localhost:54407/jenkins/job/test0/ws/**/*.txt/*zip*/glob.zip
@@ -1308,7 +1314,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
13081314 });
13091315 assertEquals (Result .SUCCESS , p .scheduleBuild2 (0 ).get ().getResult ());
13101316
1311- JenkinsRule .WebClient wc = j . createWebClient ();
1317+ JenkinsRule .WebClient wc = getWebClient ();
13121318 wc .getOptions ().setThrowExceptionOnFailingStatusCode (false );
13131319
13141320 Page zipPage = wc .goTo ("job/" + p .getName () + "/ws/**/*.txt/*zip*/glob.zip" , null );
@@ -1329,7 +1335,7 @@ public void canViewRelativePath() throws Exception {
13291335
13301336 Files .writeString (testFile .toPath (), content , StandardCharsets .UTF_8 );
13311337
1332- JenkinsRule .WebClient wc = j . createWebClient ().withThrowExceptionOnFailingStatusCode (false );
1338+ JenkinsRule .WebClient wc = getWebClient ().withThrowExceptionOnFailingStatusCode (false );
13331339 Page page = wc .goTo ("userContent/test.txt/*view*" , null );
13341340
13351341 MatcherAssert .assertThat (page .getWebResponse ().getStatusCode (), equalTo (200 ));
0 commit comments