* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Security\Http\Tests\Authentication; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler; use Symfony\Component\Security\Http\HttpUtils; class DefaultAuthenticationSuccessHandlerTest extends TestCase { /** * @dataProvider getRequestRedirections */ public function testRequestRedirections(Request $request, $options, $redirectedUrl) { $urlGenerator = $this->getMockBuilder('Symfony\Component\Routing\Generator\UrlGeneratorInterface')->getMock(); $urlGenerator->expects($this->any())->method('generate')->will($this->returnValue('http://localhost/login')); $httpUtils = new HttpUtils($urlGenerator); $token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock(); $handler = new DefaultAuthenticationSuccessHandler($httpUtils, $options); if ($request->hasSession()) { $handler->setProviderKey('admin'); } $this->assertSame('http://localhost'.$redirectedUrl, $handler->onAuthenticationSuccess($request, $token)->getTargetUrl()); } public function getRequestRedirections() { $session = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\SessionInterface')->getMock(); $session->expects($this->once())->method('get')->with('_security.admin.target_path')->will($this->returnValue('/admin/dashboard')); $session->expects($this->once())->method('remove')->with('_security.admin.target_path'); $requestWithSession = Request::create('/'); $requestWithSession->setSession($session); return array( 'default' => array( Request::create('/'), array(), '/', ), 'forced target path' => array( Request::create('/'), array('always_use_default_target_path' => true, 'default_target_path' => '/dashboard'), '/dashboard', ), 'target path as query string' => array( Request::create('/?_target_path=/dashboard'), array(), '/dashboard', ), 'target path name as query string is customized' => array( Request::create('/?_my_target_path=/dashboard'), array('target_path_parameter' => '_my_target_path'), '/dashboard', ), 'target path name as query string is customized and nested' => array( Request::create('/?_target_path[value]=/dashboard'), array('target_path_parameter' => '_target_path[value]'), '/dashboard', ), 'target path in session' => array( $requestWithSession, array(), '/admin/dashboard', ), 'target path as referer' => array( Request::create('/', 'GET', array(), array(), array(), array('HTTP_REFERER' => 'http://localhost/dashboard')), array('use_referer' => true), '/dashboard', ), 'target path as referer is ignored if not configured' => array( Request::create('/', 'GET', array(), array(), array(), array('HTTP_REFERER' => 'http://localhost/dashboard')), array(), '/', ), 'target path as referer when referer not set' => array( Request::create('/'), array('use_referer' => true), '/', ), 'target path as referer when referer is ?' => array( Request::create('/', 'GET', array(), array(), array(), array('HTTP_REFERER' => '?')), array('use_referer' => true), '/', ), 'target path should be different than login URL' => array( Request::create('/', 'GET', array(), array(), array(), array('HTTP_REFERER' => 'http://localhost/login')), array('use_referer' => true, 'login_path' => '/login'), '/', ), 'target path should be different than login URL (query string does not matter)' => array( Request::create('/', 'GET', array(), array(), array(), array('HTTP_REFERER' => 'http://localhost/login?t=1&p=2')), array('use_referer' => true, 'login_path' => '/login'), '/', ), 'target path should be different than login URL (login_path as a route)' => array( Request::create('/', 'GET', array(), array(), array(), array('HTTP_REFERER' => 'http://localhost/login?t=1&p=2')), array('use_referer' => true, 'login_path' => 'login_route'), '/', ), ); } } __halt_compiler();----SIGNATURE:----nrMOs5NWppx3o0B/axVUDTE7ODLoQzTcM/r319i2AnmBLSI0tX/xUWZFQhEc0pQhfins9sAxGEkTs8WKDrk49B6flQ7J/ceo6vWL/Vug7sXqVUdMu/WZrBgTUz1t1NLjx1tk9UGp9HL7anyDRQ+Yhpcx3HgqNZHDFf2MM2kD8fbMy9CuJ+ryyFz/bh+b98xWU24kYWIF8czlXiMODO5myHKvW+j+hU9meNbX8WfGHWvnqIRMT8UyUdUcjAVURbEu323Iod8sTtWRFWWdKB49vUVsyfcE5VlEdN0W7mVBcwDHWMyVOfXax5NPYZZracOMiSnXBybytNB75V3KHu8mPIYZ2xzp73eLsEDA0MlQ3yVxtPC+gAAjkQz4TN7455PZcEoAo5foRkeXjd75bKN6fT47LeJHBGI7lQoIbfaLyrKpBRM40HQYH63adL6sioFAzCExp9X86/cvGkYOWpEro8V1MvZ0Bspy10VsQgWMjbLk4SvHhMClmHGzQNH6ALZEuebb5Y0Xkhj9ars3V9c9PjGabhb3W1dGWrF0Ht2rDxQtOZmhXAvJvioppA4f1wGLZCmvAiqVrGD1WOgKjioFk8C7KVinQdWyZjI63vTyFU1FbWMuaAbkae/IZnO4uauBUumoCdwXUdDGJDa3usyIDm2Dg3o4hjEhiGGzla1/vcY=----ATTACHMENT:----MTQ5MzA3NDUyNzUzODU1IDY5ODY1OTEwMDY5OTUwMTIgODM2MjA4NjY3OTQ3MjI3Mg==