mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-10 03:23:19 +00:00
Add tests to guest access
This commit is contained in:
@@ -803,7 +803,7 @@ class Login implements ControllerProviderInterface
|
|||||||
|
|
||||||
$is_guest = false;
|
$is_guest = false;
|
||||||
|
|
||||||
if (null !== $request->request->get('nolog') && \phrasea::guest_allowed($app)) {
|
if (null !== $request->get('nolog') && \phrasea::guest_allowed($app)) {
|
||||||
$is_guest = true;
|
$is_guest = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -10,6 +10,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
use Alchemy\Phrasea\Application;
|
use Alchemy\Phrasea\Application;
|
||||||
|
use Symfony\Component\HttpKernel\KernelEvents;
|
||||||
|
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||||
|
use Symfony\Component\HttpFoundation\Cookie;
|
||||||
|
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Session Authentication Object for guest access
|
* Session Authentication Object for guest access
|
||||||
@@ -90,11 +94,20 @@ class Session_Authentication_Guest implements Session_Authentication_Interface
|
|||||||
*/
|
*/
|
||||||
public function postlog()
|
public function postlog()
|
||||||
{
|
{
|
||||||
/**
|
$this->app['dispatcher']->addListener(KernelEvents::RESPONSE, array($this, 'addInviteCookie'), -128);
|
||||||
* TODO NEUTRON FIX THIS
|
|
||||||
*/
|
|
||||||
\Session_Handler::set_cookie('invite-usr_id', $this->user->get_id(), 0, true);
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addInviteCookie(FilterResponseEvent $event)
|
||||||
|
{
|
||||||
|
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = $event->getResponse();
|
||||||
|
$response->headers->setCookie(new Cookie('invite-usr-id', $this->user->get_id()));
|
||||||
|
|
||||||
|
$event->setResponse($response);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
|
require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
|
||||||
|
|
||||||
use Symfony\Component\HttpKernel\Client;
|
use Symfony\Component\HttpKernel\Client;
|
||||||
|
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||||
|
|
||||||
class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||||
{
|
{
|
||||||
@@ -657,9 +658,12 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
|||||||
public function testAuthenticate()
|
public function testAuthenticate()
|
||||||
{
|
{
|
||||||
$password = \random::generatePassword();
|
$password = \random::generatePassword();
|
||||||
|
|
||||||
$login = self::$DI['app']['phraseanet.user']->get_login();
|
$login = self::$DI['app']['phraseanet.user']->get_login();
|
||||||
self::$DI['app']['phraseanet.user']->set_password($password);
|
self::$DI['app']['phraseanet.user']->set_password($password);
|
||||||
|
|
||||||
self::$DI['app']->closeAccount();
|
self::$DI['app']->closeAccount();
|
||||||
|
|
||||||
self::$DI['client'] = new Client(self::$DI['app'], array());
|
self::$DI['client'] = new Client(self::$DI['app'], array());
|
||||||
$this->set_user_agent(self::USER_AGENT_FIREFOX8MAC, self::$DI['app']);
|
$this->set_user_agent(self::USER_AGENT_FIREFOX8MAC, self::$DI['app']);
|
||||||
self::$DI['client']->request('POST', '/login/authenticate/', array(
|
self::$DI['client']->request('POST', '/login/authenticate/', array(
|
||||||
@@ -671,6 +675,52 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
|||||||
$this->assertRegExp('/^\/prod\/$/', self::$DI['client']->getResponse()->headers->get('Location'));
|
$this->assertRegExp('/^\/prod\/$/', self::$DI['client']->getResponse()->headers->get('Location'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \Alchemy\Phrasea\Controller\Root\Login::authenticate
|
||||||
|
*/
|
||||||
|
public function testGuestAuthenticate()
|
||||||
|
{
|
||||||
|
$usr_id = \User_Adapter::get_usr_id_from_login(self::$DI['app'], 'invite');
|
||||||
|
|
||||||
|
$user = \User_Adapter::getInstance($usr_id, self::$DI['app']);
|
||||||
|
|
||||||
|
$user->ACL()->give_access_to_base(array(self::$DI['collection']->get_base_id()));
|
||||||
|
|
||||||
|
self::$DI['app']->closeAccount();
|
||||||
|
|
||||||
|
self::$DI['client'] = new Client(self::$DI['app'], array());
|
||||||
|
$this->set_user_agent(self::USER_AGENT_FIREFOX8MAC, self::$DI['app']);
|
||||||
|
self::$DI['client']->request('POST', '/login/authenticate/?nolog');
|
||||||
|
|
||||||
|
$this->assertTrue(self::$DI['client']->getResponse()->isRedirect());
|
||||||
|
$this->assertRegExp('/^\/prod\/$/', self::$DI['client']->getResponse()->headers->get('Location'));
|
||||||
|
|
||||||
|
$cookies = self::$DI['client']->getResponse()->headers->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('invite-usr-id', $cookies['']['/']);
|
||||||
|
$this->assertInternalType('integer', $cookies['']['/']['invite-usr-id']->getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \Alchemy\Phrasea\Controller\Root\Login::authenticate
|
||||||
|
*/
|
||||||
|
public function testGuestAuthenticateWithPostParam()
|
||||||
|
{
|
||||||
|
self::$DI['app']->closeAccount();
|
||||||
|
|
||||||
|
self::$DI['client'] = new Client(self::$DI['app'], array());
|
||||||
|
$this->set_user_agent(self::USER_AGENT_FIREFOX8MAC, self::$DI['app']);
|
||||||
|
self::$DI['client']->request('POST', '/login/authenticate/', array('nolog'=>''));
|
||||||
|
|
||||||
|
$this->assertTrue(self::$DI['client']->getResponse()->isRedirect());
|
||||||
|
$this->assertRegExp('/^\/prod\/$/', self::$DI['client']->getResponse()->headers->get('Location'));
|
||||||
|
|
||||||
|
$cookies = self::$DI['client']->getResponse()->headers->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('invite-usr-id', $cookies['']['/']);
|
||||||
|
$this->assertInternalType('integer', $cookies['']['/']['invite-usr-id']->getValue());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \Alchemy\Phrasea\Controller\Root\Login::authenticate
|
* @covers \Alchemy\Phrasea\Controller\Root\Login::authenticate
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user