@@ -336,6 +336,43 @@ public void postWhenUsingCsrfAndXorCsrfTokenRequestAttributeHandlerWithRawTokenT
336336 // @formatter:on
337337 }
338338
339+ @ Test
340+ public void postWhenUsingCsrfAndXorCsrfTokenRequestAttributeHandlerThenCsrfAuthenticationStrategyUses ()
341+ throws Exception {
342+ this .spring .configLocations (this .xml ("WithXorCsrfTokenRequestAttributeHandler" ), this .xml ("shared-controllers" ))
343+ .autowire ();
344+ // @formatter:off
345+ MvcResult mvcResult1 = this .mvc .perform (get ("/csrf" ))
346+ .andExpect (status ().isOk ())
347+ .andReturn ();
348+ // @formatter:on
349+ MockHttpServletRequest request1 = mvcResult1 .getRequest ();
350+ MockHttpSession session = (MockHttpSession ) request1 .getSession ();
351+ CsrfTokenRepository repository = WebTestUtils .getCsrfTokenRepository (request1 );
352+ // @formatter:off
353+ MockHttpServletRequestBuilder login = post ("/login" )
354+ .param ("username" , "user" )
355+ .param ("password" , "password" )
356+ .session (session )
357+ .with (csrf ());
358+ this .mvc .perform (login )
359+ .andExpect (status ().is3xxRedirection ())
360+ .andExpect (redirectedUrl ("/" ));
361+ // @formatter:on
362+ assertThat (repository .loadToken (request1 )).isNull ();
363+ // @formatter:off
364+ MvcResult mvcResult2 = this .mvc .perform (get ("/csrf" ).session (session ))
365+ .andExpect (status ().isOk ())
366+ .andReturn ();
367+ // @formatter:on
368+ MockHttpServletRequest request2 = mvcResult2 .getRequest ();
369+ CsrfToken csrfToken = repository .loadToken (request2 );
370+ CsrfToken csrfTokenAttribute = (CsrfToken ) request2 .getAttribute (CsrfToken .class .getName ());
371+ assertThat (csrfTokenAttribute ).isNotNull ();
372+ assertThat (csrfTokenAttribute .getToken ()).isNotBlank ();
373+ assertThat (csrfTokenAttribute .getToken ()).isNotEqualTo (csrfToken .getToken ());
374+ }
375+
339376 @ Test
340377 public void postWhenHasCsrfTokenButSessionExpiresThenRequestIsCancelledAfterSuccessfulAuthentication ()
341378 throws Exception {
0 commit comments