|
17 | 17 | package org.springframework.security.web.csrf;
|
18 | 18 |
|
19 | 19 | import java.io.IOException;
|
20 |
| -import java.lang.reflect.Method; |
21 | 20 | import java.util.Arrays;
|
22 | 21 |
|
23 | 22 | import javax.servlet.FilterChain;
|
@@ -97,18 +96,6 @@ private void resetRequestResponse() {
|
97 | 96 | this.response = new MockHttpServletResponse();
|
98 | 97 | }
|
99 | 98 |
|
100 |
| - @Test |
101 |
| - public void nullConstantTimeEquals() throws Exception { |
102 |
| - Method method = CsrfFilter.class.getDeclaredMethod("equalsConstantTime", String.class, String.class); |
103 |
| - method.setAccessible(true); |
104 |
| - assertThat(method.invoke(CsrfFilter.class, null, null)).isEqualTo(true); |
105 |
| - String expectedToken = "Hello—World"; |
106 |
| - String actualToken = new String("Hello—World"); |
107 |
| - assertThat(method.invoke(CsrfFilter.class, expectedToken, null)).isEqualTo(false); |
108 |
| - assertThat(method.invoke(CsrfFilter.class, expectedToken, "hello-world")).isEqualTo(false); |
109 |
| - assertThat(method.invoke(CsrfFilter.class, expectedToken, actualToken)).isEqualTo(true); |
110 |
| - } |
111 |
| - |
112 | 99 | @Test
|
113 | 100 | public void constructorNullRepository() {
|
114 | 101 | assertThatIllegalArgumentException().isThrownBy(() -> new CsrfFilter(null));
|
@@ -333,6 +320,20 @@ public void doFilterWhenSkipRequestInvokedThenSkips() throws Exception {
|
333 | 320 | verifyZeroInteractions(repository);
|
334 | 321 | }
|
335 | 322 |
|
| 323 | + // gh-9561 |
| 324 | + @Test |
| 325 | + public void doFilterWhenTokenIsNullThenNoNullPointer() throws Exception { |
| 326 | + CsrfFilter filter = createCsrfFilter(this.tokenRepository); |
| 327 | + CsrfToken token = mock(CsrfToken.class); |
| 328 | + given(token.getToken()).willReturn(null); |
| 329 | + given(token.getHeaderName()).willReturn(this.token.getHeaderName()); |
| 330 | + given(token.getParameterName()).willReturn(this.token.getParameterName()); |
| 331 | + given(this.tokenRepository.loadToken(this.request)).willReturn(token); |
| 332 | + given(this.requestMatcher.matches(this.request)).willReturn(true); |
| 333 | + filter.doFilterInternal(this.request, this.response, this.filterChain); |
| 334 | + assertThat(this.response.getStatus()).isEqualTo(HttpServletResponse.SC_OK); |
| 335 | + } |
| 336 | + |
336 | 337 | @Test
|
337 | 338 | public void setRequireCsrfProtectionMatcherNull() {
|
338 | 339 | assertThatIllegalArgumentException().isThrownBy(() -> this.filter.setRequireCsrfProtectionMatcher(null));
|
|
0 commit comments