Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge pull request #22 from mcgin/master
[FIXED JENKINS-26234] Adding crumb exclusion
- Loading branch information
Showing
3 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/main/java/com/cloudbees/jenkins/plugins/BitbucketCrumbExclusion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.cloudbees.jenkins.plugins; | ||
|
||
import hudson.Extension; | ||
import hudson.security.csrf.CrumbExclusion; | ||
|
||
import javax.servlet.FilterChain; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
|
||
@Extension | ||
public class BitbucketCrumbExclusion extends CrumbExclusion { | ||
private static final String EXCLUSION_PATH = "/" + BitbucketHookReceiver.BITBUCKET_HOOK_URL; | ||
|
||
@Override | ||
public boolean process(HttpServletRequest req, HttpServletResponse resp, FilterChain chain) | ||
throws IOException, ServletException { | ||
String pathInfo = req.getPathInfo(); | ||
if (pathInfo != null && (pathInfo.equals(EXCLUSION_PATH) || pathInfo.equals(EXCLUSION_PATH + "/"))) { | ||
chain.doFilter(req, resp); | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/test/java/com/cloudbees/jenkins/plugins/CrumbExclusionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.cloudbees.jenkins.plugins; | ||
|
||
import com.gargoylesoftware.htmlunit.HttpMethod; | ||
import com.gargoylesoftware.htmlunit.WebRequestSettings; | ||
import com.gargoylesoftware.htmlunit.WebResponse; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
import org.xml.sax.SAXException; | ||
|
||
import java.io.IOException; | ||
import java.net.URL; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class CrumbExclusionTest { | ||
@Rule | ||
public JenkinsRule jenkins = new JenkinsRule(); | ||
|
||
@Test | ||
public void shouldNotRequireACrumbForTheBitbucketHookUrl() throws IOException, SAXException { | ||
JenkinsRule.WebClient webClient = jenkins.createWebClient(); | ||
WebRequestSettings wrs = new WebRequestSettings(new URL(webClient.getContextPath() + "bitbucket-hook"), | ||
HttpMethod.POST); | ||
WebResponse resp = webClient.getPage(wrs).getWebResponse(); | ||
|
||
assertEquals(resp.getStatusCode(), 200); | ||
} | ||
} |