From fcf967687bc1132747336fba98c227bad6c0a401 Mon Sep 17 00:00:00 2001 From: Rob Winch Date: Thu, 8 Feb 2018 17:08:59 -0600 Subject: [PATCH] Add FilterSecurityInterceptor once per request test Issue: gh-4997 --- .../intercept/FilterSecurityInterceptorTests.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/web/src/test/java/org/springframework/security/web/access/intercept/FilterSecurityInterceptorTests.java b/web/src/test/java/org/springframework/security/web/access/intercept/FilterSecurityInterceptorTests.java index 1916092640..5f05019432 100644 --- a/web/src/test/java/org/springframework/security/web/access/intercept/FilterSecurityInterceptorTests.java +++ b/web/src/test/java/org/springframework/security/web/access/intercept/FilterSecurityInterceptorTests.java @@ -21,6 +21,7 @@ import static org.mockito.Mockito.*; import org.junit.*; import org.springframework.context.ApplicationEventPublisher; +import org.springframework.mock.web.MockFilterChain; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.security.access.AccessDecisionManager; @@ -178,6 +179,18 @@ public class FilterSecurityInterceptorTests { assertThat(SecurityContextHolder.getContext().getAuthentication()).isSameAs(token); } + @Test + // gh-4997 + public void doFilterWhenObserveOncePerRequestThenAttributeNotSet() throws Exception { + this.interceptor.setObserveOncePerRequest(false); + MockHttpServletResponse response = new MockHttpServletResponse(); + MockHttpServletRequest request = new MockHttpServletRequest(); + + this.interceptor.doFilter(request, response, new MockFilterChain()); + + assertThat(request.getAttributeNames().hasMoreElements()).isFalse(); + } + private FilterInvocation createinvocation() { MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletRequest request = new MockHttpServletRequest();