@@ -37,6 +37,7 @@ class TwoFactorListenerTest extends TestCase
3737{
3838 private const FORM_PATH = '/form_path ' ;
3939 private const CHECK_PATH = '/check_path ' ;
40+ private const POST_ONLY = true ;
4041 private const AUTH_CODE_PARAM = 'auth_code_param ' ;
4142 private const TRUSTED_PARAM = 'trusted_param ' ;
4243 private const FIREWALL_NAME = 'firewallName ' ;
@@ -164,6 +165,7 @@ protected function setUp(): void
164165 $ options = [
165166 'auth_form_path ' => self ::FORM_PATH ,
166167 'check_path ' => self ::CHECK_PATH ,
168+ 'post_only ' => self ::POST_ONLY ,
167169 'auth_code_parameter_name ' => self ::AUTH_CODE_PARAM ,
168170 'trusted_parameter_name ' => self ::TRUSTED_PARAM ,
169171 ];
@@ -248,6 +250,21 @@ private function stubCurrentPath(string $currentPath): void
248250 });
249251 }
250252
253+ private function stubPostRequest (): void
254+ {
255+ $ this ->request
256+ ->expects ($ this ->any ())
257+ ->method ('isMethod ' )
258+ ->with ('POST ' )
259+ ->willReturn (true );
260+ }
261+
262+ private function stubCurrentPathIsCheckPath (): void
263+ {
264+ $ this ->stubPostRequest ();
265+ $ this ->stubCurrentPath (self ::CHECK_PATH );
266+ }
267+
251268 private function stubRequestHasParameter (string $ parameterName , $ value ): void
252269 {
253270 $ this ->requestParams [$ parameterName ] = $ value ;
@@ -447,7 +464,7 @@ public function handle_isCheckPath_authenticateWithAuthenticationManager(): void
447464 $ authenticatedToken = $ this ->createMock (TokenInterface::class);
448465 $ twoFactorToken = $ this ->createTwoFactorToken (self ::FIREWALL_NAME , $ authenticatedToken );
449466 $ this ->stubTokenManagerHasToken ($ twoFactorToken );
450- $ this ->stubCurrentPath ( self :: CHECK_PATH );
467+ $ this ->stubCurrentPathIsCheckPath ( );
451468 $ this ->stubCsrfTokenValidatorHasValidCsrfTokenReturnsTrue ();
452469 $ this ->stubHandlersReturnResponse ();
453470
@@ -473,7 +490,7 @@ public function handle_isCheckPath_authenticateWithAuthenticationManager(): void
473490 public function handle_authenticationException_dispatchFailureEvent (): void
474491 {
475492 $ this ->stubTokenManagerHasToken ($ this ->createTwoFactorToken ());
476- $ this ->stubCurrentPath ( self :: CHECK_PATH );
493+ $ this ->stubCurrentPathIsCheckPath ( );
477494 $ this ->stubCsrfTokenValidatorHasValidCsrfTokenReturnsTrue ();
478495 $ this ->stubAuthenticationManagerThrowsAuthenticationException ();
479496 $ this ->stubHandlersReturnResponse ();
@@ -492,7 +509,7 @@ public function handle_authenticationException_dispatchFailureEvent(): void
492509 public function handle_authenticationException_setResponseFromFailureHandler (): void
493510 {
494511 $ this ->stubTokenManagerHasToken ($ this ->createTwoFactorToken ());
495- $ this ->stubCurrentPath ( self :: CHECK_PATH );
512+ $ this ->stubCurrentPathIsCheckPath ( );
496513 $ this ->stubAuthenticationManagerThrowsAuthenticationException ();
497514
498515 $ response = $ this ->createMock (Response::class);
@@ -515,7 +532,7 @@ public function handle_authenticationException_setResponseFromFailureHandler():
515532 public function handle_csrfTokenInvalid_dispatchFailureEvent (): void
516533 {
517534 $ this ->stubTokenManagerHasToken ($ this ->createTwoFactorToken ());
518- $ this ->stubCurrentPath ( self :: CHECK_PATH );
535+ $ this ->stubCurrentPathIsCheckPath ( );
519536 $ this ->stubCsrfTokenValidatorHasValidCsrfTokenReturnsFalse ();
520537 $ this ->stubHandlersReturnResponse ();
521538
@@ -531,7 +548,7 @@ public function handle_authenticationStepSuccessful_dispatchSuccessEvent(): void
531548 {
532549 $ twoFactorToken = $ this ->createTwoFactorToken ();
533550 $ this ->stubTokenManagerHasToken ($ twoFactorToken );
534- $ this ->stubCurrentPath ( self :: CHECK_PATH );
551+ $ this ->stubCurrentPathIsCheckPath ( );
535552 $ this ->stubCsrfTokenValidatorHasValidCsrfTokenReturnsTrue ();
536553 $ this ->stubAuthenticationManagerReturnsToken ($ twoFactorToken ); // Must be TwoFactorToken
537554
@@ -551,7 +568,7 @@ public function handle_authenticationStepSuccessfulButNotCompleted_redirectToAut
551568 {
552569 $ twoFactorToken = $ this ->createTwoFactorToken ();
553570 $ this ->stubTokenManagerHasToken ($ twoFactorToken );
554- $ this ->stubCurrentPath ( self :: CHECK_PATH );
571+ $ this ->stubCurrentPathIsCheckPath ( );
555572 $ this ->stubCsrfTokenValidatorHasValidCsrfTokenReturnsTrue ();
556573 $ this ->stubAuthenticationManagerReturnsToken ($ twoFactorToken ); // Must be TwoFactorToken
557574
@@ -572,7 +589,7 @@ public function handle_authenticationStepSuccessfulButNotCompleted_dispatchRequi
572589 {
573590 $ twoFactorToken = $ this ->createTwoFactorToken ();
574591 $ this ->stubTokenManagerHasToken ($ twoFactorToken );
575- $ this ->stubCurrentPath ( self :: CHECK_PATH );
592+ $ this ->stubCurrentPathIsCheckPath ( );
576593 $ this ->stubCsrfTokenValidatorHasValidCsrfTokenReturnsTrue ();
577594 $ this ->stubAuthenticationManagerReturnsToken ($ twoFactorToken ); // Must be TwoFactorToken
578595
@@ -591,7 +608,7 @@ public function handle_authenticationStepSuccessfulButNotCompleted_dispatchRequi
591608 public function handle_twoFactorProcessComplete_returnResponseFromSuccessHandler (): void
592609 {
593610 $ this ->stubTokenManagerHasToken ($ this ->createTwoFactorToken ());
594- $ this ->stubCurrentPath ( self :: CHECK_PATH );
611+ $ this ->stubCurrentPathIsCheckPath ( );
595612 $ this ->stubCsrfTokenValidatorHasValidCsrfTokenReturnsTrue ();
596613 $ this ->stubAuthenticationManagerReturnsToken ($ this ->createMock (TokenInterface::class)); // Not a TwoFactorToken
597614
@@ -615,7 +632,7 @@ public function handle_twoFactorProcessComplete_returnResponseFromSuccessHandler
615632 public function handle_twoFactorProcessComplete_dispatchCompleteEvent (): void
616633 {
617634 $ this ->stubTokenManagerHasToken ($ this ->createTwoFactorToken ());
618- $ this ->stubCurrentPath ( self :: CHECK_PATH );
635+ $ this ->stubCurrentPathIsCheckPath ( );
619636 $ this ->stubCsrfTokenValidatorHasValidCsrfTokenReturnsTrue ();
620637 $ this ->stubAuthenticationManagerReturnsToken ($ this ->createMock (TokenInterface::class)); // Not a TwoFactorToken
621638 $ this ->stubHandlersReturnResponse ();
@@ -641,7 +658,7 @@ public function handle_twoFactorProcessCompleteWithTrustedEnabled_setTrustedDevi
641658 ->willReturn ('user ' );
642659
643660 $ this ->stubTokenManagerHasToken ($ this ->createTwoFactorToken ());
644- $ this ->stubCurrentPath ( self :: CHECK_PATH );
661+ $ this ->stubCurrentPathIsCheckPath ( );
645662 $ this ->stubCsrfTokenValidatorHasValidCsrfTokenReturnsTrue ();
646663 $ this ->stubRequestHasParameter (self ::TRUSTED_PARAM , '1 ' );
647664 $ this ->stubAuthenticationManagerReturnsToken ($ authenticatedToken ); // Not a TwoFactorToken
@@ -661,7 +678,7 @@ public function handle_twoFactorProcessCompleteWithTrustedEnabled_setTrustedDevi
661678 public function handle_twoFactorProcessCompleteWithTrustedDisabled_notSetTrustedDevice (): void
662679 {
663680 $ this ->stubTokenManagerHasToken ($ this ->createTwoFactorToken ());
664- $ this ->stubCurrentPath ( self :: CHECK_PATH );
681+ $ this ->stubCurrentPathIsCheckPath ( );
665682 $ this ->stubCsrfTokenValidatorHasValidCsrfTokenReturnsTrue ();
666683 $ this ->stubRequestHasParameter (self ::TRUSTED_PARAM , '0 ' );
667684 $ this ->stubAuthenticationManagerReturnsToken ($ this ->createMock (TokenInterface::class)); // Not a TwoFactorToken
@@ -690,7 +707,7 @@ public function handle_twoFactorProcessCompleteWithRememberMeEnabled_setRemember
690707 $ twoFactorToken = $ this ->createTwoFactorToken (self ::FIREWALL_NAME , null , $ attributes );
691708
692709 $ this ->stubTokenManagerHasToken ($ twoFactorToken );
693- $ this ->stubCurrentPath ( self :: CHECK_PATH );
710+ $ this ->stubCurrentPathIsCheckPath ( );
694711 $ this ->stubCsrfTokenValidatorHasValidCsrfTokenReturnsTrue ();
695712 $ this ->stubAuthenticationManagerReturnsToken ($ authenticatedToken ); // Not a TwoFactorToken
696713 $ response = $ this ->stubHandlersReturnResponse ();
0 commit comments