[JENKINS-34254] Add test

This commit is contained in:
Daniel Beck committed 2017-12-15 23:43:01 +01:00
1 parent 3c695a3ed6
commit f0efdbab08
2 files changed
+18 -1

No files matched your search

@@ -34,7 +34,7 @@ THE SOFTWARE.
</p>
<p><tt>${requestURL}</tt></p>
<p><strong>${%warning}</strong></p>
<f:form method="post">
<f:form method="post" name="retry">
<f:submit value="${%Retry using POST}"/>
</f:form>
</l:main-panel>
@@ -8,6 +8,8 @@ package hudson.security.csrf;
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import jenkins.model.Jenkins;
import junit.framework.Assert;
import net.sf.json.JSONObject;
import org.junit.Before;
import org.junit.Rule;
@@ -135,4 +137,19 @@ public class DefaultCrumbIssuerTest {
wc.assertFails("crumbIssuer/api/json?jsonp=hack", HttpURLConnection.HTTP_FORBIDDEN);
}
@Issue("JENKINS-34254")
@Test public void testRequirePostErrorPageCrumb() throws Exception {
Jenkins.getInstance().setCrumbIssuer(new DefaultCrumbIssuer(false));
WebClient wc = r.createWebClient();
try {
wc.goTo("quietDown");
fail("expected failure");
} catch (FailingHttpStatusCodeException ex) {
Assert.assertEquals("expect HTTP 405 method not allowed", 405, ex.getStatusCode());
}
HtmlPage retry = (HtmlPage) wc.getCurrentWindow().getEnclosedPage();
HtmlPage success = r.submit(retry.getFormByName("retry"));
Assert.assertTrue("quieting down", r.jenkins.isQuietingDown());
}
}