Merge branch '2.8' into 3.2
* 2.8: Fixed pathinfo calculation for requests starting with a question mark. [Security] simplify the SwitchUserListenerTest
This commit is contained in:
commit
f29664893d
@ -1774,6 +1774,9 @@ class Request
|
|||||||
|
|
||||||
// Does the baseUrl have anything in common with the request_uri?
|
// Does the baseUrl have anything in common with the request_uri?
|
||||||
$requestUri = $this->getRequestUri();
|
$requestUri = $this->getRequestUri();
|
||||||
|
if ($requestUri !== '' && $requestUri[0] !== '/') {
|
||||||
|
$requestUri = '/'.$requestUri;
|
||||||
|
}
|
||||||
|
|
||||||
if ($baseUrl && false !== $prefix = $this->getUrlencodedPrefix($requestUri, $baseUrl)) {
|
if ($baseUrl && false !== $prefix = $this->getUrlencodedPrefix($requestUri, $baseUrl)) {
|
||||||
// full $baseUrl matches
|
// full $baseUrl matches
|
||||||
@ -1846,9 +1849,12 @@ class Request
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Remove the query string from REQUEST_URI
|
// Remove the query string from REQUEST_URI
|
||||||
if ($pos = strpos($requestUri, '?')) {
|
if (false !== $pos = strpos($requestUri, '?')) {
|
||||||
$requestUri = substr($requestUri, 0, $pos);
|
$requestUri = substr($requestUri, 0, $pos);
|
||||||
}
|
}
|
||||||
|
if ($requestUri !== '' && $requestUri[0] !== '/') {
|
||||||
|
$requestUri = '/'.$requestUri;
|
||||||
|
}
|
||||||
|
|
||||||
$pathInfo = substr($requestUri, strlen($baseUrl));
|
$pathInfo = substr($requestUri, strlen($baseUrl));
|
||||||
if (null !== $baseUrl && (false === $pathInfo || '' === $pathInfo)) {
|
if (null !== $baseUrl && (false === $pathInfo || '' === $pathInfo)) {
|
||||||
|
@ -1281,6 +1281,12 @@ class RequestTest extends TestCase
|
|||||||
$request->initialize(array(), array(), array(), array(), array(), $server);
|
$request->initialize(array(), array(), array(), array(), array(), $server);
|
||||||
|
|
||||||
$this->assertEquals('/path%20test/info', $request->getPathInfo());
|
$this->assertEquals('/path%20test/info', $request->getPathInfo());
|
||||||
|
|
||||||
|
$server = array();
|
||||||
|
$server['REQUEST_URI'] = '?a=b';
|
||||||
|
$request->initialize(array(), array(), array(), array(), array(), $server);
|
||||||
|
|
||||||
|
$this->assertEquals('/', $request->getPathInfo());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetParameterPrecedence()
|
public function testGetParameterPrecedence()
|
||||||
@ -2110,6 +2116,61 @@ class RequestTest extends TestCase
|
|||||||
array('CONNECT', false),
|
array('CONNECT', false),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function nonstandardRequestsData()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array('', '', '/', 'http://host:8080/', ''),
|
||||||
|
array('/', '', '/', 'http://host:8080/', ''),
|
||||||
|
|
||||||
|
array('hello/app.php/x', '', '/x', 'http://host:8080/hello/app.php/x', '/hello', '/hello/app.php'),
|
||||||
|
array('/hello/app.php/x', '', '/x', 'http://host:8080/hello/app.php/x', '/hello', '/hello/app.php'),
|
||||||
|
|
||||||
|
array('', 'a=b', '/', 'http://host:8080/?a=b'),
|
||||||
|
array('?a=b', 'a=b', '/', 'http://host:8080/?a=b'),
|
||||||
|
array('/?a=b', 'a=b', '/', 'http://host:8080/?a=b'),
|
||||||
|
|
||||||
|
array('x', 'a=b', '/x', 'http://host:8080/x?a=b'),
|
||||||
|
array('x?a=b', 'a=b', '/x', 'http://host:8080/x?a=b'),
|
||||||
|
array('/x?a=b', 'a=b', '/x', 'http://host:8080/x?a=b'),
|
||||||
|
|
||||||
|
array('hello/x', '', '/x', 'http://host:8080/hello/x', '/hello'),
|
||||||
|
array('/hello/x', '', '/x', 'http://host:8080/hello/x', '/hello'),
|
||||||
|
|
||||||
|
array('hello/app.php/x', 'a=b', '/x', 'http://host:8080/hello/app.php/x?a=b', '/hello', '/hello/app.php'),
|
||||||
|
array('hello/app.php/x?a=b', 'a=b', '/x', 'http://host:8080/hello/app.php/x?a=b', '/hello', '/hello/app.php'),
|
||||||
|
array('/hello/app.php/x?a=b', 'a=b', '/x', 'http://host:8080/hello/app.php/x?a=b', '/hello', '/hello/app.php'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider nonstandardRequestsData
|
||||||
|
*/
|
||||||
|
public function testNonstandardRequests($requestUri, $queryString, $expectedPathInfo, $expectedUri, $expectedBasePath = '', $expectedBaseUrl = null)
|
||||||
|
{
|
||||||
|
if (null === $expectedBaseUrl) {
|
||||||
|
$expectedBaseUrl = $expectedBasePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
$server = array(
|
||||||
|
'HTTP_HOST' => 'host:8080',
|
||||||
|
'SERVER_PORT' => '8080',
|
||||||
|
'QUERY_STRING' => $queryString,
|
||||||
|
'PHP_SELF' => '/hello/app.php',
|
||||||
|
'SCRIPT_FILENAME' => '/some/path/app.php',
|
||||||
|
'REQUEST_URI' => $requestUri,
|
||||||
|
);
|
||||||
|
|
||||||
|
$request = new Request(array(), array(), array(), array(), array(), $server);
|
||||||
|
|
||||||
|
$this->assertEquals($expectedPathInfo, $request->getPathInfo());
|
||||||
|
$this->assertEquals($expectedUri, $request->getUri());
|
||||||
|
$this->assertEquals($queryString, $request->getQueryString());
|
||||||
|
$this->assertEquals(8080, $request->getPort());
|
||||||
|
$this->assertEquals('host:8080', $request->getHttpHost());
|
||||||
|
$this->assertEquals($expectedBaseUrl, $request->getBaseUrl());
|
||||||
|
$this->assertEquals($expectedBasePath, $request->getBasePath());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class RequestContentProxy extends Request
|
class RequestContentProxy extends Request
|
||||||
|
@ -12,6 +12,13 @@
|
|||||||
namespace Symfony\Component\Security\Http\Tests\Firewall;
|
namespace Symfony\Component\Security\Http\Tests\Firewall;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
||||||
|
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||||
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
|
||||||
|
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
|
||||||
|
use Symfony\Component\Security\Core\Role\SwitchUserRole;
|
||||||
|
use Symfony\Component\Security\Core\User\User;
|
||||||
use Symfony\Component\Security\Http\Event\SwitchUserEvent;
|
use Symfony\Component\Security\Http\Event\SwitchUserEvent;
|
||||||
use Symfony\Component\Security\Http\Firewall\SwitchUserListener;
|
use Symfony\Component\Security\Http\Firewall\SwitchUserListener;
|
||||||
use Symfony\Component\Security\Http\SecurityEvents;
|
use Symfony\Component\Security\Http\SecurityEvents;
|
||||||
@ -32,14 +39,12 @@ class SwitchUserListenerTest extends TestCase
|
|||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
$this->tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock();
|
$this->tokenStorage = new TokenStorage();
|
||||||
$this->userProvider = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserProviderInterface')->getMock();
|
$this->userProvider = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserProviderInterface')->getMock();
|
||||||
$this->userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
|
$this->userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
|
||||||
$this->accessDecisionManager = $this->getMockBuilder('Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface')->getMock();
|
$this->accessDecisionManager = $this->getMockBuilder('Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface')->getMock();
|
||||||
$this->request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->getMock();
|
$this->request = new Request();
|
||||||
$this->request->query = $this->getMockBuilder('Symfony\Component\HttpFoundation\ParameterBag')->getMock();
|
$this->event = new GetResponseEvent($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $this->request, HttpKernelInterface::MASTER_REQUEST);
|
||||||
$this->request->server = $this->getMockBuilder('Symfony\Component\HttpFoundation\ServerBag')->getMock();
|
|
||||||
$this->event = $this->getEvent($this->request);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,13 +58,11 @@ class SwitchUserListenerTest extends TestCase
|
|||||||
|
|
||||||
public function testEventIsIgnoredIfUsernameIsNotPassedWithTheRequest()
|
public function testEventIsIgnoredIfUsernameIsNotPassedWithTheRequest()
|
||||||
{
|
{
|
||||||
$this->request->expects($this->any())->method('get')->with('_switch_user')->will($this->returnValue(null));
|
|
||||||
|
|
||||||
$this->event->expects($this->never())->method('setResponse');
|
|
||||||
$this->tokenStorage->expects($this->never())->method('setToken');
|
|
||||||
|
|
||||||
$listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager);
|
$listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager);
|
||||||
$listener->handle($this->event);
|
$listener->handle($this->event);
|
||||||
|
|
||||||
|
$this->assertNull($this->event->getResponse());
|
||||||
|
$this->assertNull($this->tokenStorage->getToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -67,10 +70,10 @@ class SwitchUserListenerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testExitUserThrowsAuthenticationExceptionIfOriginalTokenCannotBeFound()
|
public function testExitUserThrowsAuthenticationExceptionIfOriginalTokenCannotBeFound()
|
||||||
{
|
{
|
||||||
$token = $this->getToken(array($this->getMockBuilder('Symfony\Component\Security\Core\Role\RoleInterface')->getMock()));
|
$token = new UsernamePasswordToken('username', '', 'key', array('ROLE_FOO'));
|
||||||
|
|
||||||
$this->tokenStorage->expects($this->any())->method('getToken')->will($this->returnValue($token));
|
$this->tokenStorage->setToken($token);
|
||||||
$this->request->expects($this->any())->method('get')->with('_switch_user')->will($this->returnValue('_exit'));
|
$this->request->query->set('_switch_user', '_exit');
|
||||||
|
|
||||||
$listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager);
|
$listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager);
|
||||||
$listener->handle($this->event);
|
$listener->handle($this->event);
|
||||||
@ -78,29 +81,19 @@ class SwitchUserListenerTest extends TestCase
|
|||||||
|
|
||||||
public function testExitUserUpdatesToken()
|
public function testExitUserUpdatesToken()
|
||||||
{
|
{
|
||||||
$originalToken = $this->getToken();
|
$originalToken = new UsernamePasswordToken('username', '', 'key', array());
|
||||||
$role = $this->getMockBuilder('Symfony\Component\Security\Core\Role\SwitchUserRole')
|
$this->tokenStorage->setToken(new UsernamePasswordToken('username', '', 'key', array(new SwitchUserRole('ROLE_PREVIOUS', $originalToken))));
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
$role->expects($this->any())->method('getSource')->will($this->returnValue($originalToken));
|
|
||||||
|
|
||||||
$this->tokenStorage->expects($this->any())
|
$this->request->query->set('_switch_user', '_exit');
|
||||||
->method('getToken')
|
|
||||||
->will($this->returnValue($this->getToken(array($role))));
|
|
||||||
|
|
||||||
$this->request->expects($this->any())->method('get')->with('_switch_user')->will($this->returnValue('_exit'));
|
|
||||||
$this->request->expects($this->any())->method('getUri')->will($this->returnValue('/'));
|
|
||||||
$this->request->query->expects($this->once())->method('remove', '_switch_user');
|
|
||||||
$this->request->query->expects($this->any())->method('all')->will($this->returnValue(array()));
|
|
||||||
$this->request->server->expects($this->once())->method('set')->with('QUERY_STRING', '');
|
|
||||||
|
|
||||||
$this->tokenStorage->expects($this->once())
|
|
||||||
->method('setToken')->with($originalToken);
|
|
||||||
$this->event->expects($this->once())
|
|
||||||
->method('setResponse')->with($this->isInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse'));
|
|
||||||
|
|
||||||
$listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager);
|
$listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager);
|
||||||
$listener->handle($this->event);
|
$listener->handle($this->event);
|
||||||
|
|
||||||
|
$this->assertSame(array(), $this->request->query->all());
|
||||||
|
$this->assertSame('', $this->request->server->get('QUERY_STRING'));
|
||||||
|
$this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $this->event->getResponse());
|
||||||
|
$this->assertSame($this->request->getUri(), $this->event->getResponse()->getTargetUrl());
|
||||||
|
$this->assertSame($originalToken, $this->tokenStorage->getToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testExitUserDispatchesEventWithRefreshedUser()
|
public function testExitUserDispatchesEventWithRefreshedUser()
|
||||||
@ -113,38 +106,9 @@ class SwitchUserListenerTest extends TestCase
|
|||||||
->method('refreshUser')
|
->method('refreshUser')
|
||||||
->with($originalUser)
|
->with($originalUser)
|
||||||
->willReturn($refreshedUser);
|
->willReturn($refreshedUser);
|
||||||
$originalToken = $this->getToken();
|
$originalToken = new UsernamePasswordToken($originalUser, '', 'key');
|
||||||
$originalToken
|
$this->tokenStorage->setToken(new UsernamePasswordToken('username', '', 'key', array(new SwitchUserRole('ROLE_PREVIOUS', $originalToken))));
|
||||||
->expects($this->any())
|
$this->request->query->set('_switch_user', '_exit');
|
||||||
->method('getUser')
|
|
||||||
->willReturn($originalUser);
|
|
||||||
$role = $this
|
|
||||||
->getMockBuilder('Symfony\Component\Security\Core\Role\SwitchUserRole')
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
$role->expects($this->any())->method('getSource')->willReturn($originalToken);
|
|
||||||
$this
|
|
||||||
->tokenStorage
|
|
||||||
->expects($this->any())
|
|
||||||
->method('getToken')
|
|
||||||
->willReturn($this->getToken(array($role)));
|
|
||||||
$this
|
|
||||||
->request
|
|
||||||
->expects($this->any())
|
|
||||||
->method('get')
|
|
||||||
->with('_switch_user')
|
|
||||||
->willReturn('_exit');
|
|
||||||
$this
|
|
||||||
->request
|
|
||||||
->expects($this->any())
|
|
||||||
->method('getUri')
|
|
||||||
->willReturn('/');
|
|
||||||
$this
|
|
||||||
->request
|
|
||||||
->query
|
|
||||||
->expects($this->any())
|
|
||||||
->method('all')
|
|
||||||
->will($this->returnValue(array()));
|
|
||||||
|
|
||||||
$dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
|
$dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
|
||||||
$dispatcher
|
$dispatcher
|
||||||
@ -166,41 +130,9 @@ class SwitchUserListenerTest extends TestCase
|
|||||||
->userProvider
|
->userProvider
|
||||||
->expects($this->never())
|
->expects($this->never())
|
||||||
->method('refreshUser');
|
->method('refreshUser');
|
||||||
$originalToken = $this->getToken();
|
$originalToken = new UsernamePasswordToken($originalUser, '', 'key');
|
||||||
$originalToken
|
$this->tokenStorage->setToken(new UsernamePasswordToken('username', '', 'key', array(new SwitchUserRole('ROLE_PREVIOUS', $originalToken))));
|
||||||
->expects($this->any())
|
$this->request->query->set('_switch_user', '_exit');
|
||||||
->method('getUser')
|
|
||||||
->willReturn($originalUser);
|
|
||||||
$role = $this
|
|
||||||
->getMockBuilder('Symfony\Component\Security\Core\Role\SwitchUserRole')
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
$role
|
|
||||||
->expects($this->any())
|
|
||||||
->method('getSource')
|
|
||||||
->willReturn($originalToken);
|
|
||||||
$this
|
|
||||||
->tokenStorage
|
|
||||||
->expects($this->any())
|
|
||||||
->method('getToken')
|
|
||||||
->willReturn($this->getToken(array($role)));
|
|
||||||
$this
|
|
||||||
->request
|
|
||||||
->expects($this->any())
|
|
||||||
->method('get')
|
|
||||||
->with('_switch_user')
|
|
||||||
->willReturn('_exit');
|
|
||||||
$this
|
|
||||||
->request
|
|
||||||
->query
|
|
||||||
->expects($this->any())
|
|
||||||
->method('all')
|
|
||||||
->will($this->returnValue(array()));
|
|
||||||
$this
|
|
||||||
->request
|
|
||||||
->expects($this->any())
|
|
||||||
->method('getUri')
|
|
||||||
->willReturn('/');
|
|
||||||
|
|
||||||
$dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
|
$dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
|
||||||
$dispatcher
|
$dispatcher
|
||||||
@ -217,10 +149,10 @@ class SwitchUserListenerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testSwitchUserIsDisallowed()
|
public function testSwitchUserIsDisallowed()
|
||||||
{
|
{
|
||||||
$token = $this->getToken(array($this->getMockBuilder('Symfony\Component\Security\Core\Role\RoleInterface')->getMock()));
|
$token = new UsernamePasswordToken('username', '', 'key', array('ROLE_FOO'));
|
||||||
|
|
||||||
$this->tokenStorage->expects($this->any())->method('getToken')->will($this->returnValue($token));
|
$this->tokenStorage->setToken($token);
|
||||||
$this->request->expects($this->any())->method('get')->with('_switch_user')->will($this->returnValue('kuba'));
|
$this->request->query->set('_switch_user', 'kuba');
|
||||||
|
|
||||||
$this->accessDecisionManager->expects($this->once())
|
$this->accessDecisionManager->expects($this->once())
|
||||||
->method('decide')->with($token, array('ROLE_ALLOWED_TO_SWITCH'))
|
->method('decide')->with($token, array('ROLE_ALLOWED_TO_SWITCH'))
|
||||||
@ -232,17 +164,11 @@ class SwitchUserListenerTest extends TestCase
|
|||||||
|
|
||||||
public function testSwitchUser()
|
public function testSwitchUser()
|
||||||
{
|
{
|
||||||
$token = $this->getToken(array($this->getMockBuilder('Symfony\Component\Security\Core\Role\RoleInterface')->getMock()));
|
$token = new UsernamePasswordToken('username', '', 'key', array('ROLE_FOO'));
|
||||||
$user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock();
|
$user = new User('username', 'password', array());
|
||||||
$user->expects($this->any())->method('getRoles')->will($this->returnValue(array()));
|
|
||||||
|
|
||||||
$this->tokenStorage->expects($this->any())->method('getToken')->will($this->returnValue($token));
|
$this->tokenStorage->setToken($token);
|
||||||
$this->request->expects($this->any())->method('get')->with('_switch_user')->will($this->returnValue('kuba'));
|
$this->request->query->set('_switch_user', 'kuba');
|
||||||
$this->request->query->expects($this->once())->method('remove', '_switch_user');
|
|
||||||
$this->request->query->expects($this->any())->method('all')->will($this->returnValue(array()));
|
|
||||||
|
|
||||||
$this->request->expects($this->any())->method('getUri')->will($this->returnValue('/'));
|
|
||||||
$this->request->server->expects($this->once())->method('set')->with('QUERY_STRING', '');
|
|
||||||
|
|
||||||
$this->accessDecisionManager->expects($this->once())
|
$this->accessDecisionManager->expects($this->once())
|
||||||
->method('decide')->with($token, array('ROLE_ALLOWED_TO_SWITCH'))
|
->method('decide')->with($token, array('ROLE_ALLOWED_TO_SWITCH'))
|
||||||
@ -253,25 +179,26 @@ class SwitchUserListenerTest extends TestCase
|
|||||||
->will($this->returnValue($user));
|
->will($this->returnValue($user));
|
||||||
$this->userChecker->expects($this->once())
|
$this->userChecker->expects($this->once())
|
||||||
->method('checkPostAuth')->with($user);
|
->method('checkPostAuth')->with($user);
|
||||||
$this->tokenStorage->expects($this->once())
|
|
||||||
->method('setToken')->with($this->isInstanceOf('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken'));
|
|
||||||
|
|
||||||
$listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager);
|
$listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager);
|
||||||
$listener->handle($this->event);
|
$listener->handle($this->event);
|
||||||
|
|
||||||
|
$this->assertSame(array(), $this->request->query->all());
|
||||||
|
$this->assertSame('', $this->request->server->get('QUERY_STRING'));
|
||||||
|
$this->assertInstanceOf('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken', $this->tokenStorage->getToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSwitchUserKeepsOtherQueryStringParameters()
|
public function testSwitchUserKeepsOtherQueryStringParameters()
|
||||||
{
|
{
|
||||||
$token = $this->getToken(array($this->getMockBuilder('Symfony\Component\Security\Core\Role\RoleInterface')->getMock()));
|
$token = new UsernamePasswordToken('username', '', 'key', array('ROLE_FOO'));
|
||||||
$user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock();
|
$user = new User('username', 'password', array());
|
||||||
$user->expects($this->any())->method('getRoles')->will($this->returnValue(array()));
|
|
||||||
|
|
||||||
$this->tokenStorage->expects($this->any())->method('getToken')->will($this->returnValue($token));
|
$this->tokenStorage->setToken($token);
|
||||||
$this->request->expects($this->any())->method('get')->with('_switch_user')->will($this->returnValue('kuba'));
|
$this->request->query->replace(array(
|
||||||
$this->request->query->expects($this->once())->method('remove', '_switch_user');
|
'_switch_user' => 'kuba',
|
||||||
$this->request->query->expects($this->any())->method('all')->will($this->returnValue(array('page' => 3, 'section' => 2)));
|
'page' => 3,
|
||||||
$this->request->expects($this->any())->method('getUri')->will($this->returnValue('/'));
|
'section' => 2,
|
||||||
$this->request->server->expects($this->once())->method('set')->with('QUERY_STRING', 'page=3§ion=2');
|
));
|
||||||
|
|
||||||
$this->accessDecisionManager->expects($this->once())
|
$this->accessDecisionManager->expects($this->once())
|
||||||
->method('decide')->with($token, array('ROLE_ALLOWED_TO_SWITCH'))
|
->method('decide')->with($token, array('ROLE_ALLOWED_TO_SWITCH'))
|
||||||
@ -282,33 +209,11 @@ class SwitchUserListenerTest extends TestCase
|
|||||||
->will($this->returnValue($user));
|
->will($this->returnValue($user));
|
||||||
$this->userChecker->expects($this->once())
|
$this->userChecker->expects($this->once())
|
||||||
->method('checkPostAuth')->with($user);
|
->method('checkPostAuth')->with($user);
|
||||||
$this->tokenStorage->expects($this->once())
|
|
||||||
->method('setToken')->with($this->isInstanceOf('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken'));
|
|
||||||
|
|
||||||
$listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager);
|
$listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager);
|
||||||
$listener->handle($this->event);
|
$listener->handle($this->event);
|
||||||
}
|
|
||||||
|
|
||||||
private function getEvent($request)
|
$this->assertSame('page=3§ion=2', $this->request->server->get('QUERY_STRING'));
|
||||||
{
|
$this->assertInstanceOf('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken', $this->tokenStorage->getToken());
|
||||||
$event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
|
|
||||||
$event->expects($this->any())
|
|
||||||
->method('getRequest')
|
|
||||||
->will($this->returnValue($request));
|
|
||||||
|
|
||||||
return $event;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getToken(array $roles = array())
|
|
||||||
{
|
|
||||||
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
|
|
||||||
$token->expects($this->any())
|
|
||||||
->method('getRoles')
|
|
||||||
->will($this->returnValue($roles));
|
|
||||||
|
|
||||||
return $token;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,7 +144,7 @@ class HttpUtilsTest extends TestCase
|
|||||||
// Plus must not decoded to space
|
// Plus must not decoded to space
|
||||||
$this->assertTrue($utils->checkRequestPath($this->getRequest('/foo+bar'), '/foo+bar'));
|
$this->assertTrue($utils->checkRequestPath($this->getRequest('/foo+bar'), '/foo+bar'));
|
||||||
// Checking unicode
|
// Checking unicode
|
||||||
$this->assertTrue($utils->checkRequestPath($this->getRequest(urlencode('/вход')), '/вход'));
|
$this->assertTrue($utils->checkRequestPath($this->getRequest('/'.urlencode('вход')), '/вход'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCheckRequestPathWithUrlMatcherAndResourceNotFound()
|
public function testCheckRequestPathWithUrlMatcherAndResourceNotFound()
|
||||||
|
Reference in New Issue
Block a user