Skip to content

Commit 84ef1a4

Browse files
daniel-beckjenkinsci-cert-ci
authored andcommitted
1 parent 68425e2 commit 84ef1a4

File tree

7 files changed

+22
-6
lines changed

7 files changed

+22
-6
lines changed

core/src/main/java/jenkins/model/Jenkins.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4165,6 +4165,7 @@ public synchronized HttpRedirect doCancelQuietDown() {
41654165
return new HttpRedirect(".");
41664166
}
41674167

4168+
@POST
41684169
public HttpResponse doToggleCollapse() throws ServletException, IOException {
41694170
final StaplerRequest2 request = Stapler.getCurrentRequest2();
41704171
final String paneId = request.getParameter("paneId");

core/src/main/resources/lib/hudson/executors.jelly

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ THE SOFTWARE.
174174
${executorDetails}
175175
</span>
176176
</j:if>
177-
<a class="collapse" href="${rootURL}/toggleCollapse?paneId=executors"
177+
<st:adjunct includes="lib.form.link.link"/>
178+
<!-- TODO improve l:link so the `a` can be changed to `l:link`. -->
179+
<a class="collapse post" href="${rootURL}/toggleCollapse?paneId=executors"
178180
tooltip="${paneIsCollapsed ? '%Expand' : '%Collapse'}" data-tooltip-append-to-parent="true">
179181
<j:set var="svgIconId" value="${paneIsCollapsed ? 'chevron-up' : 'chevron-down'}" />
180182
<l:icon src="symbol-${svgIconId}" />

core/src/main/resources/lib/layout/pane.jelly

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ THE SOFTWARE.
5959
</span>
6060

6161
<j:if test="${attrs.id != null}">
62-
<a class="collapse" href="${rootURL}/toggleCollapse?paneId=${attrs.id}"
62+
<st:adjunct includes="lib.form.link.link"/>
63+
<!-- TODO improve l:link so the `a` can be changed to `l:link`. -->
64+
<a class="collapse post" href="${rootURL}/toggleCollapse?paneId=${attrs.id}"
6365
title="${paneIsCollapsed ? '%expand' : '%collapse'}">
6466

6567
<j:set var="svgIconId" value="${paneIsCollapsed ? 'chevron-up' : 'chevron-down'}" />

test/src/test/java/hudson/model/ComputerSetTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public void testTerminatedNodeAjaxExecutorsDoesNotShowTrace() throws Exception {
173173
new OfflineCause.ChannelTermination(new RuntimeException(message))
174174
);
175175

176-
WebClient wc = j.createWebClient();
176+
WebClient wc = j.createWebClient().withJavaScriptEnabled(false);
177177
Page page = wc.getPage(wc.createCrumbedUrl(HasWidgetHelper.getWidget(j.jenkins.getComputer(), ExecutorsWidget.class).orElseThrow().getUrl() + "ajax"));
178178
String content = page.getWebResponse().getContentAsString();
179179
assertThat(content, not(containsString(message)));

test/src/test/java/hudson/model/ComputerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ public void testTerminatedNodeAjaxExecutorsDoesNotShowTrace() throws Exception {
285285
new OfflineCause.ChannelTermination(new RuntimeException(message))
286286
);
287287

288-
WebClient wc = j.createWebClient();
288+
WebClient wc = j.createWebClient().withJavaScriptEnabled(false);
289289
Page page = wc.getPage(wc.createCrumbedUrl(HasWidgetHelper.getWidget(agent.toComputer(), ExecutorsWidget.class).orElseThrow().getUrl() + "ajax"));
290290
String content = page.getWebResponse().getContentAsString();
291291
assertThat(content, not(containsString(message)));

test/src/test/java/jenkins/model/JenkinsTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
import hudson.util.FormValidation;
7373
import hudson.util.HttpResponses;
7474
import hudson.util.VersionNumber;
75+
import jakarta.servlet.http.HttpServletResponse;
7576
import java.io.File;
7677
import java.io.IOException;
7778
import java.net.HttpURLConnection;
@@ -130,6 +131,16 @@ public class JenkinsTest {
130131
@Rule
131132
public TemporaryFolder tmp = new TemporaryFolder();
132133

134+
@Test
135+
@Issue("SECURITY-3498")
136+
public void testPaneToggleCollapse() throws Exception {
137+
try (WebClient wc = j.createWebClient()) {
138+
final FailingHttpStatusCodeException ex = assertThrows(FailingHttpStatusCodeException.class, () -> wc.goTo("toggleCollapse?paneId=foo"));
139+
// @POST responds 404 when the verb is wrong; @RequirePOST would respond 405.
140+
assertThat(ex.getStatusCode(), is(HttpServletResponse.SC_NOT_FOUND));
141+
}
142+
}
143+
133144
@Test
134145
@Issue("SECURITY-3073")
135146
public void verifyUploadedFingerprintFilePermission() throws Exception {

test/src/test/java/lib/layout/AjaxTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class AjaxTest {
6161
@Test
6262
@Issue("JENKINS-65288")
6363
public void ajaxPageRenderingPossibleWithoutJellyTrace() throws Exception {
64-
JenkinsRule.WebClient wc = r.createWebClient();
64+
JenkinsRule.WebClient wc = r.createWebClient().withJavaScriptEnabled(false);
6565
HtmlPage htmlPage = wc.goTo(getExecutorsWidgetAjaxViewUrl());
6666
r.assertGoodStatus(htmlPage);
6767
}
@@ -76,7 +76,7 @@ public void ajaxPageRenderingPossibleWithJellyTrace() throws Exception {
7676
try {
7777
JellyFacet.TRACE = true;
7878

79-
JenkinsRule.WebClient wc = r.createWebClient();
79+
JenkinsRule.WebClient wc = r.createWebClient().withJavaScriptEnabled(false);
8080
HtmlPage htmlPage = wc.goTo(getExecutorsWidgetAjaxViewUrl());
8181
r.assertGoodStatus(htmlPage);
8282
} finally {

0 commit comments

Comments
 (0)