From 8c80ef97273acb7ad5aa08a39d6e8cada4576c7a Mon Sep 17 00:00:00 2001 From: wcluijt Date: Thu, 1 Jun 2017 18:45:31 -0700 Subject: [PATCH] Added tests to check referer URL with a login_path route name --- ...efaultAuthenticationSuccessHandlerTest.php | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/Symfony/Component/Security/Http/Tests/Authentication/DefaultAuthenticationSuccessHandlerTest.php b/src/Symfony/Component/Security/Http/Tests/Authentication/DefaultAuthenticationSuccessHandlerTest.php index 577fa506bcff7..ce041d2f9ba3c 100644 --- a/src/Symfony/Component/Security/Http/Tests/Authentication/DefaultAuthenticationSuccessHandlerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Authentication/DefaultAuthenticationSuccessHandlerTest.php @@ -179,6 +179,52 @@ public function testRefererWithoutParametersHasToBeDifferentThanLoginUrl() $this->assertSame($response, $result); } + public function testRefererUrlAndLoginPathRouteNameHasToBeDifferentThanLoginUrl() + { + $options = array( + 'login_path' => 'login_route', + 'use_referer' => true, + ); + + $this->request->headers->expects($this->any()) + ->method('get')->with('Referer') + ->will($this->returnValue('http://example.com/login')); + + $this->httpUtils->expects($this->once()) + ->method('generateUri')->with($this->request, 'login_route') + ->will($this->returnValue('http://example.com/login')); + + $response = $this->expectRedirectResponse('/'); + + $handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, $options); + $result = $handler->onAuthenticationSuccess($this->request, $this->token); + + $this->assertSame($response, $result); + } + + public function testRefererUrlWithoutParametersAndLoginPathRouteNameHasToBeDifferentThanLoginUrl() + { + $options = array( + 'login_path' => 'login_route', + 'use_referer' => true, + ); + + $this->request->headers->expects($this->any()) + ->method('get')->with('Referer') + ->will($this->returnValue('http://example.com/subfolder/login?t=1&p=2')); + + $this->httpUtils->expects($this->once()) + ->method('generateUri')->with($this->request, 'login_route') + ->will($this->returnValue('http://example.com/subfolder/login')); + + $response = $this->expectRedirectResponse('/'); + + $handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, $options); + $result = $handler->onAuthenticationSuccess($this->request, $this->token); + + $this->assertSame($response, $result); + } + public function testRefererTargetPathIsIgnoredByDefault() { $this->request->headers->expects($this->never())->method('get');