Skip to content

Commit

Permalink
[FIXED JENKINS-16918] Use HTTP 405 when POST is required.
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed Aug 9, 2013
1 parent 7e8bbea commit ec9d809
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelog.html
Expand Up @@ -60,6 +60,9 @@
<li class=bug>
Form validation methods weren't getting triggered when one of its dependency controls change.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-19124">issue 19124</a>)
<li class=bug>
When POST is required for some HTTP operation but GET was used, the response should have status code 405.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-16918">issue 16918</a>)
</ul>
</div><!--=TRUNK-END=-->

Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/hudson/model/BuildAuthorizationToken.java
Expand Up @@ -31,6 +31,7 @@
import org.kohsuke.stapler.StaplerResponse;

import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import jenkins.security.ApiTokenProperty;
import org.acegisecurity.AccessDeniedException;
import org.kohsuke.stapler.HttpResponses;
Expand Down Expand Up @@ -84,6 +85,8 @@ public static void checkPermission(AbstractProject project, BuildAuthorizationTo
return;
}

rsp.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
rsp.addHeader("Allow", "POST");
throw HttpResponses.forwardToView(project, "requirePOST.jelly");
}

Expand Down
2 changes: 1 addition & 1 deletion test/src/test/java/jenkins/model/JenkinsTest.java
Expand Up @@ -290,7 +290,7 @@ public void testDoEval() throws Exception {
jenkins.setCrumbIssuer(null);
WebClient wc = createWebClient();
wc.login("alice");
wc.assertFails("eval", HttpURLConnection.HTTP_INTERNAL_ERROR);
wc.assertFails("eval", HttpURLConnection.HTTP_BAD_METHOD);
assertEquals("3", eval(wc));
wc.login("bob");
try {
Expand Down

0 comments on commit ec9d809

Please sign in to comment.