-
Notifications
You must be signed in to change notification settings - Fork 398
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GitHubWebHookCrumbExclusion should be more forgiving if the user leav…
…es off the trailing slash
- Loading branch information
Showing
2 changed files
with
75 additions
and
4 deletions.
There are no files selected for viewing
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
67 changes: 67 additions & 0 deletions
67
src/test/java/com/cloudbees/jenkins/GitHubWebHookCrumbExclusionTest.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,67 @@ | ||
package com.cloudbees.jenkins; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import javax.servlet.FilterChain; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import static junit.framework.Assert.assertFalse; | ||
import static junit.framework.TestCase.assertTrue; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.never; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class GitHubWebHookCrumbExclusionTest { | ||
|
||
private GitHubWebHookCrumbExclusion exclusion; | ||
private HttpServletRequest req; | ||
private HttpServletResponse resp; | ||
private FilterChain chain; | ||
|
||
@Before | ||
public void before() { | ||
exclusion = new GitHubWebHookCrumbExclusion(); | ||
req = mock(HttpServletRequest.class); | ||
resp = mock(HttpServletResponse.class); | ||
chain = mock(FilterChain.class); | ||
} | ||
|
||
@Test | ||
public void testFullPath() throws Exception { | ||
when(req.getPathInfo()).thenReturn("/github-webhook/"); | ||
assertTrue(exclusion.process(req, resp, chain)); | ||
verify(chain, times(1)).doFilter(req, resp); | ||
} | ||
|
||
@Test | ||
public void testFullPathWithoutSlash() throws Exception { | ||
when(req.getPathInfo()).thenReturn("/github-webhook"); | ||
assertTrue(exclusion.process(req, resp, chain)); | ||
verify(chain, times(1)).doFilter(req, resp); | ||
} | ||
|
||
@Test | ||
public void testInvalidPath() throws Exception { | ||
when(req.getPathInfo()).thenReturn("/some-other-url/"); | ||
assertFalse(exclusion.process(req, resp, chain)); | ||
verify(chain, never()).doFilter(req, resp); | ||
} | ||
|
||
@Test | ||
public void testNullPath() throws Exception { | ||
when(req.getPathInfo()).thenReturn(null); | ||
assertFalse(exclusion.process(req, resp, chain)); | ||
verify(chain, never()).doFilter(req, resp); | ||
} | ||
|
||
@Test | ||
public void testEmptyPath() throws Exception { | ||
when(req.getPathInfo()).thenReturn(""); | ||
assertFalse(exclusion.process(req, resp, chain)); | ||
verify(chain, never()).doFilter(req, resp); | ||
} | ||
} |