From 24a6dce5980ef3c6516bdbf0aab8787f3cf29d82 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Thu, 31 Oct 2013 13:09:56 +0100 Subject: [PATCH 1/2] Fix #1555 : API sessions remains open --- .../Phrasea/Authentication/Authenticator.php | 9 ++ lib/Alchemy/Phrasea/Controller/Api/V1.php | 4 + templates/web/account/sessions.html.twig | 4 +- .../Tests/Phrasea/Application/ApiAbstract.php | 8 ++ .../Phrasea/Application/LightboxTest.php | 10 +- .../Phrasea/Application/OverviewTest.php | 10 +- .../Authentication/AuthenticatorTest.php | 22 ++-- .../Phrasea/Controller/Admin/RootTest.php | 2 +- .../Phrasea/Controller/Client/RootTest.php | 2 +- .../Phrasea/Controller/Prod/QueryTest.php | 2 +- .../Phrasea/Controller/Prod/RecordsTest.php | 8 +- .../Phrasea/Controller/Prod/RootTest.php | 2 +- .../Phrasea/Controller/Report/RootTest.php | 4 +- .../Phrasea/Controller/Root/LoginTest.php | 106 +++++++++--------- .../Phrasea/Controller/Root/RootTest.php | 4 +- .../Phrasea/Controller/Root/SessionTest.php | 4 +- .../SearchEngine/SearchEngineOptionsTest.php | 2 +- .../Tests/Phrasea/Security/FirewallTest.php | 2 +- tests/classes/PhraseanetPHPUnitAbstract.php | 8 ++ tests/classes/Session/Session_LoggerTest.php | 4 +- tests/classes/api/v1/api_v1_adapterTest.php | 8 +- 21 files changed, 130 insertions(+), 95 deletions(-) diff --git a/lib/Alchemy/Phrasea/Authentication/Authenticator.php b/lib/Alchemy/Phrasea/Authentication/Authenticator.php index 0874804dde..8766d46096 100644 --- a/lib/Alchemy/Phrasea/Authentication/Authenticator.php +++ b/lib/Alchemy/Phrasea/Authentication/Authenticator.php @@ -116,6 +116,15 @@ class Authenticator */ public function closeAccount() { + if (!$this->session->has('session_id')) { + throw new RuntimeException('No session to close.'); + } + + if (null !== $session = $this->em->find('Entities\Session', $this->session->get('session_id'))) { + $this->em->remove($session); + $this->em->flush(); + } + $this->session->invalidate(); $this->reinitUser(); diff --git a/lib/Alchemy/Phrasea/Controller/Api/V1.php b/lib/Alchemy/Phrasea/Controller/Api/V1.php index a85b1296a0..2d04fac8f8 100644 --- a/lib/Alchemy/Phrasea/Controller/Api/V1.php +++ b/lib/Alchemy/Phrasea/Controller/Api/V1.php @@ -162,6 +162,10 @@ class V1 implements ControllerProviderInterface ); }); + $controllers->after(function () use ($app) { + $app['authentication']->closeAccount(); + }); + /** * Method Not Allowed Closure */ diff --git a/templates/web/account/sessions.html.twig b/templates/web/account/sessions.html.twig index cdb966e871..ee8dc9673e 100644 --- a/templates/web/account/sessions.html.twig +++ b/templates/web/account/sessions.html.twig @@ -35,8 +35,10 @@ {% set row = session['session'] %} - {% if app['session'].get('phrasea_session_id') != row.Id() %} + {% if app['session'].get('session_id') != row.Id() %} {% trans %}End Activity{% endtrans %} + {% else %} + {% trans 'Current session' %} {% endif %} diff --git a/tests/Alchemy/Tests/Phrasea/Application/ApiAbstract.php b/tests/Alchemy/Tests/Phrasea/Application/ApiAbstract.php index 35911c09cd..d3e63350ed 100644 --- a/tests/Alchemy/Tests/Phrasea/Application/ApiAbstract.php +++ b/tests/Alchemy/Tests/Phrasea/Application/ApiAbstract.php @@ -148,6 +148,14 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract $this->assertEquals(1, $preEvent); } + public function testThatSessionIsClosedAfterRequest() + { + $this->assertCount(0, self::$DI['app']['EM']->getRepository('Entities\Session')->findAll()); + $this->setToken(self::$token); + self::$DI['client']->request('GET', '/api/v1/databoxes/list/', $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType())); + $this->assertCount(0, self::$DI['app']['EM']->getRepository('Entities\Session')->findAll()); + } + public function provideEventNames() { return array( diff --git a/tests/Alchemy/Tests/Phrasea/Application/LightboxTest.php b/tests/Alchemy/Tests/Phrasea/Application/LightboxTest.php index ce73c17d19..9239e34c06 100644 --- a/tests/Alchemy/Tests/Phrasea/Application/LightboxTest.php +++ b/tests/Alchemy/Tests/Phrasea/Application/LightboxTest.php @@ -39,7 +39,7 @@ class ApplicationLightboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac public function testRouteSlash() { - self::$DI['app']['authentication']->openAccount(self::$DI['user']); + $this->authenticate(self::$DI['app']); $baskets = $this->insertFiveBasket(); @@ -66,7 +66,7 @@ class ApplicationLightboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac public function testAuthenticationWithToken() { - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); $Basket = $this->insertOneBasket(); $token = self::$DI['app']['tokens']->getUrlToken(\random::TYPE_VIEW, self::$DI['user_alt2']->get_id(), null, $Basket->getId()); @@ -187,7 +187,7 @@ class ApplicationLightboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac public function testValidate() { - self::$DI['app']['authentication']->openAccount(self::$DI['user']); + $this->authenticate(self::$DI['app']); $basket = $this->insertOneValidationBasket(); @@ -212,7 +212,7 @@ class ApplicationLightboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac public function testCompare() { - self::$DI['app']['authentication']->openAccount(self::$DI['user']); + $this->authenticate(self::$DI['app']); $basket = $this->insertOneBasket(); @@ -237,7 +237,7 @@ class ApplicationLightboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac public function testFeedEntry() { - self::$DI['app']['authentication']->openAccount(self::$DI['user']); + $this->authenticate(self::$DI['app']); $this->set_user_agent(self::USER_AGENT_FIREFOX8MAC, self::$DI['app']); diff --git a/tests/Alchemy/Tests/Phrasea/Application/OverviewTest.php b/tests/Alchemy/Tests/Phrasea/Application/OverviewTest.php index 793882265b..6e4e86f264 100644 --- a/tests/Alchemy/Tests/Phrasea/Application/OverviewTest.php +++ b/tests/Alchemy/Tests/Phrasea/Application/OverviewTest.php @@ -55,7 +55,7 @@ class ApplicationOverviewTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac public function testDatafilesRouteNotAuthenticated() { - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); self::$DI['client']->request('GET', '/datafiles/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/preview/'); $this->assertForbiddenResponse(self::$DI['client']->getResponse()); @@ -79,7 +79,7 @@ class ApplicationOverviewTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac public function testDatafilesRouteNotAuthenticatedUnknownSubdef() { - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); self::$DI['client']->request('GET', '/datafiles/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/notfoundreview/'); $this->assertForbiddenResponse(self::$DI['client']->getResponse()); @@ -96,7 +96,7 @@ class ApplicationOverviewTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac public function testPermalinkNotAuthenticated() { - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); $this->assertFalse(self::$DI['app']['authentication']->isAuthenticated()); $this->get_a_permalinkBCcompatibility(array("Content-Type" => "image/jpeg")); $this->get_a_permaviewBCcompatibility(array("Content-Type" => "text/html; charset=UTF-8")); @@ -112,7 +112,7 @@ class ApplicationOverviewTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac public function testCaptionNotAuthenticated() { - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); $this->assertFalse(self::$DI['app']['authentication']->isAuthenticated()); $this->get_a_caption(array("Content-Type" => "application/json")); } @@ -213,7 +213,7 @@ class ApplicationOverviewTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac $entry = \Feed_Entry_Adapter::create(self::$DI['app'], $publicFeed, $publisher, 'titre', 'sub titre entry', 'author name', 'author email', false); $item = \Feed_Entry_Item::create(self::$DI['app']['phraseanet.appbox'], $entry, self::$DI['record_1']); - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); self::$DI['client']->request('GET', '/permalink/v1/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/preview/'); $this->assertEquals(200, self::$DI['client']->getResponse()->getStatusCode()); diff --git a/tests/Alchemy/Tests/Phrasea/Authentication/AuthenticatorTest.php b/tests/Alchemy/Tests/Phrasea/Authentication/AuthenticatorTest.php index 7b09915010..682192ecf1 100644 --- a/tests/Alchemy/Tests/Phrasea/Authentication/AuthenticatorTest.php +++ b/tests/Alchemy/Tests/Phrasea/Authentication/AuthenticatorTest.php @@ -207,21 +207,25 @@ class AuthenticatorTest extends \PhraseanetPHPUnitAbstract */ public function testCloseAccount() { - $app = new Application(); - + $app = self::$DI['app']; $user = self::$DI['user']; - $app['browser'] = $browser = $this->getBrowserMock(); - $app['session'] = $session = $this->getSessionMock(); - $app['EM'] = $em = $this->getEntityManagerMock(); - - $session->set('usr_id', $user->get_id()); - - $authenticator = new Authenticator($app, $browser, $session, $em); + $authenticator = new Authenticator($app, $app['browser'], $app['session'], $app['EM']); + $authenticator->openAccount($user); + $this->assertNotNull($authenticator->getUser()); $authenticator->closeAccount(); $this->assertNull($authenticator->getUser()); } + public function testCloseAccountWhenNoSessionThrowsAnException() + { + $app = self::$DI['app']; + + $authenticator = new Authenticator($app, $app['browser'], $app['session'], $app['EM']); + $this->setExpectedException('Alchemy\Phrasea\Exception\RuntimeException', 'No session to close.'); + $authenticator->closeAccount(); + } + /** * @covers Alchemy\Phrasea\Authentication\Authenticator::isAuthenticated */ diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Admin/RootTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Admin/RootTest.php index f8ec057e56..93df91f20a 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Admin/RootTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Admin/RootTest.php @@ -11,7 +11,7 @@ class RootTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testRouteSlash() { - self::$DI['app']['authentication']->openAccount(self::$DI['user']); + $this->authenticate(self::$DI['app']); self::$DI['client']->request('GET', '/admin/', array('section' => 'base:featured')); $this->assertTrue(self::$DI['client']->getResponse()->isOk()); diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Client/RootTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Client/RootTest.php index c1ee3902bb..0ee6efcd7c 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Client/RootTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Client/RootTest.php @@ -23,7 +23,7 @@ class RootTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testGetClient() { - self::$DI['app']['authentication']->openAccount(self::$DI['user']); + $this->authenticate(self::$DI['app']); self::$DI['client']->request("GET", "/client/"); $this->assertTrue(self::$DI['client']->getResponse()->isOk()); } diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/QueryTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/QueryTest.php index 092a6b3ed8..cc6256891e 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/QueryTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/QueryTest.php @@ -30,7 +30,7 @@ class QueryTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testQueryAnswerTrain() { - self::$DI['app']['authentication']->openAccount(self::$DI['user']); + $this->authenticate(self::$DI['app']); self::$DI['record_24']; $options = new SearchEngineOptions(); diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/RecordsTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/RecordsTest.php index 60cd4da6d5..696c8d5435 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/RecordsTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/RecordsTest.php @@ -83,7 +83,7 @@ class RecordsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testGetRecordDetailResult() { - self::$DI['app']['authentication']->openAccount(self::$DI['user']); + $this->authenticate(self::$DI['app']); self::$DI['record_24']; $options = new SearchEngineOptions(); @@ -119,7 +119,7 @@ class RecordsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testGetRecordDetailREG() { - self::$DI['app']['authentication']->openAccount(self::$DI['user']); + $this->authenticate(self::$DI['app']); self::$DI['record_story_1']; $this->XMLHTTPRequest('POST', '/prod/records/', array( @@ -149,7 +149,7 @@ class RecordsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testGetRecordDetailBasket() { - self::$DI['app']['authentication']->openAccount(self::$DI['user']); + $this->authenticate(self::$DI['app']); $basket = $this->insertOneBasket(); $record = self::$DI['record_1']; @@ -191,7 +191,7 @@ class RecordsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testGetRecordDetailFeed() { - self::$DI['app']['authentication']->openAccount(self::$DI['user']); + $this->authenticate(self::$DI['app']); self::$feed = \Feed_Adapter::create( self::$DI['app'], diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/RootTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/RootTest.php index 4e307baf41..e797968daa 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/RootTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/RootTest.php @@ -11,7 +11,7 @@ class ControllerRootTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testRouteSlash() { - self::$DI['app']['authentication']->openAccount(self::$DI['user']); + $this->authenticate(self::$DI['app']); $crawler = self::$DI['client']->request('GET', '/prod/'); diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Report/RootTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Report/RootTest.php index 2b8fac5145..07ff64abf8 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Report/RootTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Report/RootTest.php @@ -15,7 +15,7 @@ class RootTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function testRouteDashboard() { - self::$DI['app']['authentication']->openAccount(self::$DI['user']); + $this->authenticate(self::$DI['app']); self::$DI['client']->request('GET', '/report/dashboard'); @@ -26,7 +26,7 @@ class RootTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function testRouteDashboardJson() { - self::$DI['app']['authentication']->openAccount(self::$DI['user']); + $this->authenticate(self::$DI['app']); $this->XMLHTTPRequest('GET', '/report/dashboard', array( 'dmin' => $this->dmin->format('Y-m-d H:i:s'), diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Root/LoginTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Root/LoginTest.php index ba7dcf0af5..88dcf7d6ec 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Root/LoginTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Root/LoginTest.php @@ -55,7 +55,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function testLoginRedirectPostLog() { - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); self::$DI['client']->request('GET', '/login/', array('postlog' => '1', 'redirect' => 'prod')); $response = self::$DI['client']->getResponse(); @@ -68,7 +68,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testLoginError($type, $message) { - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); self::$DI['app']->addFlash($type, $message); $crawler = self::$DI['client']->request('GET', '/login/'); @@ -83,7 +83,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testRegisterConfirmMailNoCode() { - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); self::$DI['client']->request('GET', '/login/register-confirm/'); $response = self::$DI['client']->getResponse(); @@ -97,7 +97,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testRegisterConfirmMailWrongCode() { - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); self::$DI['client']->request('GET', '/login/register-confirm/', array( 'code' => '34dT0k3n' )); @@ -113,7 +113,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testRegisterConfirmMailUserNotFound() { - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); $email = $this->generateEmail(); $token = self::$DI['app']['tokens']->getUrlToken(\random::TYPE_EMAIL, 0, null, $email); self::$DI['client']->request('GET', '/login/register-confirm/', array( @@ -131,7 +131,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testRegisterConfirmMailUnlocked() { - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); $email = $this->generateEmail(); $token = self::$DI['app']['tokens']->getUrlToken(\random::TYPE_EMAIL, self::$DI['user']->get_id(), null, $email); @@ -152,7 +152,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract { $this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailSuccessEmailConfirmationRegistered'); - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); $email = $this->generateEmail(); $appboxRegister = new \appbox_register(self::$DI['app']['phraseanet.appbox']); $token = self::$DI['app']['tokens']->getUrlToken(\random::TYPE_EMAIL, self::$DI['user']->get_id(), null, $email); @@ -178,7 +178,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $user = \User_Adapter::create(self::$DI['app'], 'test'.mt_rand(), \random::generatePassword(), 'email-random'.mt_rand().'@phraseanet.com', false); - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); $email = $this->generateEmail(); $token = self::$DI['app']['tokens']->getUrlToken(\random::TYPE_EMAIL, $user->get_id(), null, $email); @@ -201,7 +201,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testRenewPasswordInvalidEmail() { - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); $crawler = self::$DI['client']->request('POST', '/login/forgot-password/', array( 'email' => 'invalid.email.com', '_token' => 'token', @@ -218,7 +218,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testRenewPasswordUnknowEmail() { - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); $crawler = self::$DI['client']->request('POST', '/login/forgot-password/', array( 'email' => 'invalid_email@test.com', '_token' => 'token', @@ -236,7 +236,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract { $this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailRequestPasswordUpdate'); - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); self::$DI['client']->request('POST', '/login/forgot-password/', array( 'email' => self::$DI['user']->get_email(), '_token' => 'token', @@ -253,7 +253,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testRenewPasswordBadArguments() { - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); $token = self::$DI['app']['tokens']->getUrlToken(\random::TYPE_PASSWORD, self::$DI['user']->get_id()); $crawler = self::$DI['client']->request('POST', '/login/renew-password/', array( 'token' => $token, @@ -269,7 +269,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function testRenewPasswordBadToken() { - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); self::$DI['client']->request('POST', '/login/renew-password/', array( 'token' => 'badToken', '_token' => 'token', @@ -296,7 +296,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function testRenewPasswordNoToken() { - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); self::$DI['client']->request('POST', '/login/renew-password/', array( '_token' => 'token', 'password' => array('password' => 'password', 'confirm' => 'password') @@ -325,7 +325,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testRenewPassword() { - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); $token = self::$DI['app']['tokens']->getUrlToken(\random::TYPE_PASSWORD, self::$DI['user']->get_id()); self::$DI['client']->request('POST', '/login/renew-password/', array( @@ -347,7 +347,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testRenewPasswordPageShowsFlashMessages($type, $message) { - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); self::$DI['app']->addFlash($type, $message); $token = self::$DI['app']['tokens']->getUrlToken(\random::TYPE_PASSWORD, self::$DI['user']->get_id()); @@ -363,7 +363,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function testForgotPasswordGet() { - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); self::$DI['client']->request('GET', '/login/forgot-password/'); $this->assertTrue(self::$DI['client']->getResponse()->isOk()); @@ -381,7 +381,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function testForgotPasswordInvalidEmail() { - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); $crawler = self::$DI['client']->request('POST', '/login/forgot-password/', array( '_token' => 'token', 'email' => 'invalid.email', @@ -395,7 +395,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function testForgotPasswordWrongEmail() { - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); $crawler = self::$DI['client']->request('POST', '/login/forgot-password/', array( '_token' => 'token', 'email' => 'invalid@email.com', @@ -411,7 +411,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract { $this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailRequestPasswordUpdate'); - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); $crawler = self::$DI['client']->request('POST', '/login/forgot-password/', array( '_token' => 'token', 'email' => self::$DI['user']->get_email(), @@ -429,7 +429,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function testGetRegister($type, $message) { self::$DI['app']['registration.enabled'] = true; - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); self::$DI['app']->addFlash($type, $message); $crawler = self::$DI['client']->request('GET', '/login/register-classic/'); @@ -442,7 +442,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function testGetRegisterWithRegisterIdBindDataToForm() { self::$DI['app']['registration.enabled'] = true; - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); $provider = $this->getMock('Alchemy\Phrasea\Authentication\Provider\ProviderInterface'); @@ -488,7 +488,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function testGetPostRegisterWhenRegistrationDisabled($method, $route) { self::$DI['app']['registration.enabled'] = false; - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); self::$DI['client']->request($method, $route); $this->assertEquals(404, self::$DI['client']->getResponse()->getStatusCode()); } @@ -501,7 +501,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract self::$DI['app']['registration.enabled'] = true; self::$DI['app']['registration.fields'] = $extraParameters; - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); $parameters = array_merge(array('_token' => 'token'), $parameters); foreach ($parameters as $key => $parameter) { @@ -528,7 +528,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function testPostRegisterWithoutParams() { - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); $crawler = self::$DI['client']->request('POST', '/login/register-classic/'); $this->assertFalse(self::$DI['client']->getResponse()->isRedirect()); @@ -782,7 +782,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function testPostRegisterWithProviderIdAndAlreadyBoundProvider() { self::$DI['app']['registration.fields'] = array(); - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); $provider = $this->getMock('Alchemy\Phrasea\Authentication\Provider\ProviderInterface'); $this->addProvider('provider-test', $provider); @@ -832,7 +832,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function testPostRegisterWithUnknownProvider() { self::$DI['app']['registration.fields'] = array(); - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); $parameters = array_merge(array('_token' => 'token'), array( "password" => array( @@ -867,7 +867,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function testPostRegisterWithProviderNotAuthenticated() { self::$DI['app']['registration.fields'] = array(); - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); $provider = $this->getMock('Alchemy\Phrasea\Authentication\Provider\ProviderInterface'); $this->addProvider('provider-test', $provider); @@ -909,7 +909,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function testPostRegisterWithProviderId() { self::$DI['app']['registration.fields'] = array(); - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); $emails = array( 'Alchemy\Phrasea\Notification\Mail\MailRequestEmailConfirmation'=>0, @@ -983,7 +983,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract { self::$DI['app']['registration.fields'] = $extraParameters; - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); $emails = array( 'Alchemy\Phrasea\Notification\Mail\MailRequestEmailConfirmation'=>0, @@ -1044,7 +1044,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testSendConfirmMailBadRequest() { - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); self::$DI['client']->request('GET', '/login/send-mail-confirm/'); $this->assertBadResponse(self::$DI['client']->getResponse()); @@ -1057,7 +1057,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract { $this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailRequestEmailConfirmation'); - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); self::$DI['client']->request('GET', '/login/send-mail-confirm/', array('usr_id' => self::$DI['user']->get_id())); $response = self::$DI['client']->getResponse(); @@ -1071,7 +1071,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testSendConfirmMailWrongUser() { - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); self::$DI['client']->request('GET', '/login/send-mail-confirm/', array('usr_id' => 0)); $response = self::$DI['client']->getResponse(); @@ -1091,7 +1091,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract self::$DI['app']['authentication']->getUser()->set_password($password); self::$DI['app']['authentication']->getUser()->set_mail_locked(false); - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); self::$DI['client'] = new Client(self::$DI['app'], array()); $this->set_user_agent(self::USER_AGENT_FIREFOX8MAC, self::$DI['app']); @@ -1116,7 +1116,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract self::$DI['app']['authentication']->getUser()->set_password($password); self::$DI['app']['authentication']->getUser()->set_mail_locked(false); - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); $preEvent = 0; $phpunit = $this; @@ -1163,7 +1163,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $login = self::$DI['app']['authentication']->getUser()->get_login(); self::$DI['app']['authentication']->getUser()->set_password($password); - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); self::$DI['client'] = new Client(self::$DI['app'], array()); $this->set_user_agent(self::USER_AGENT_FIREFOX8MAC, self::$DI['app']); @@ -1189,7 +1189,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $user->ACL()->give_access_to_base(array(self::$DI['collection']->get_base_id())); - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); self::$DI['client'] = new Client(self::$DI['app'], array()); $this->set_user_agent(self::USER_AGENT_FIREFOX8MAC, self::$DI['app']); @@ -1221,7 +1221,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $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']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); self::$DI['client'] = new Client(self::$DI['app'], array()); $this->set_user_agent(self::USER_AGENT_FIREFOX8MAC, self::$DI['app']); @@ -1235,7 +1235,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testGuestAuthenticateWithGetMethod() { - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); self::$DI['client'] = new Client(self::$DI['app'], array()); $this->set_user_agent(self::USER_AGENT_FIREFOX8MAC, self::$DI['app']); @@ -1255,7 +1255,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testBadAuthenticate() { - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); self::$DI['client']->request('POST', '/login/authenticate/', array( 'login' => self::$DI['user']->get_login(), 'password' => 'test', @@ -1272,7 +1272,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testBadAuthenticateCheckRedirect() { - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); self::$DI['client']->request('POST', '/login/authenticate/', array( 'login' => self::$DI['user']->get_login(), 'password' => 'test', @@ -1290,7 +1290,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testMailLockedAuthenticate() { - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); $password = \random::generatePassword(); self::$DI['user']->set_mail_locked(true); self::$DI['client']->request('POST', '/login/authenticate/', array( @@ -1327,7 +1327,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract ->with($parameters) ->will($this->returnValue($response)); - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); self::$DI['client']->request('GET', '/login/provider/provider-test/authenticate/', $parameters); $this->assertSame($response, self::$DI['client']->getResponse()); @@ -1367,7 +1367,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract ->with($this->equalTo('provider-test')) ->will($this->throwException(new InvalidArgumentException('Provider not found'))); - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); self::$DI['client']->request($method, $route); $this->assertEquals(404, self::$DI['client']->getResponse()->getStatusCode()); @@ -1398,7 +1398,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract ->method('onCallback') ->will($this->throwException(new NotAuthenticatedException('Not authenticated.'))); - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); self::$DI['client']->request('GET', '/login/provider/provider-test/callback/'); $this->assertSame(302, self::$DI['client']->getResponse()->getStatusCode()); @@ -1428,7 +1428,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract ->method('getToken') ->will($this->returnValue($token)); - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); self::$DI['client']->request('GET', '/login/provider/provider-test/callback/'); $this->assertSame(302, self::$DI['client']->getResponse()->getStatusCode()); @@ -1462,7 +1462,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract ->with($token) ->will($this->returnValue($user)); - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); self::$DI['client']->request('GET', '/login/provider/provider-test/callback/'); $this->assertSame(302, self::$DI['client']->getResponse()->getStatusCode()); @@ -1537,7 +1537,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract ->method('isEnabled') ->will($this->returnValue(true)); - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); self::$DI['client']->request('GET', '/login/provider/provider-test/callback/'); $this->assertSame(302, self::$DI['client']->getResponse()->getStatusCode()); @@ -1589,7 +1589,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract self::$DI['app']['registration.enabled'] = true; - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); self::$DI['client']->request('GET', '/login/provider/provider-test/callback/'); $this->assertSame(302, self::$DI['client']->getResponse()->getStatusCode()); @@ -1632,7 +1632,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract self::$DI['app']['registration.enabled'] = false; - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); self::$DI['client']->request('GET', '/login/provider/provider-test/callback/'); $this->assertSame(302, self::$DI['client']->getResponse()->getStatusCode()); @@ -1651,7 +1651,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract ); self::$DI['app']['registration.fields'] = $fields; - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); self::$DI['client']->request('GET', '/login/registration-fields/'); $this->assertSame(200, self::$DI['client']->getResponse()->getStatusCode()); @@ -1662,7 +1662,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function testRegisterRedirectsNoAuthProvidersAvailable() { - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); self::$DI['app']['authentication.providers'] = new ProvidersCollection(); @@ -1674,7 +1674,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function testRegisterDisplaysIfAuthProvidersAvailable() { - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); $provider = $this->getMock('Alchemy\Phrasea\Authentication\Provider\ProviderInterface'); $provider->expects($this->any()) diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Root/RootTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Root/RootTest.php index 348ff7590c..383c080256 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Root/RootTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Root/RootTest.php @@ -83,7 +83,7 @@ class RootTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function testNoPersistentCookie() { $app = self::$DI['app']; - $app['authentication']->closeAccount(); + $this->logout($app); $boolean = false; @@ -102,7 +102,7 @@ class RootTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function testPersistentCookie() { $app = self::$DI['app']; - $app['authentication']->closeAccount(); + $this->logout(self::$DI['app']); $browser = $this->getMockBuilder('\Browser') ->disableOriginalConstructor() diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Root/SessionTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Root/SessionTest.php index 93afb4d969..f0cb48db28 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Root/SessionTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Root/SessionTest.php @@ -38,7 +38,7 @@ class SessionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testUpdSession() { - self::$DI['app']['authentication']->openAccount(self::$DI['user']); + $this->authenticate(self::$DI['app']); $this->XMLHTTPRequest('POST', '/session/update/', array( 'usr' => self::$DI['user']->get_id(), @@ -55,7 +55,7 @@ class SessionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testUpdSessionBadRequestMissingModuleArgument() { - self::$DI['app']['authentication']->openAccount(self::$DI['user']); + $this->authenticate(self::$DI['app']); $this->XMLHTTPRequest('POST', '/session/update/', array( 'usr' => self::$DI['user']->get_id() diff --git a/tests/Alchemy/Tests/Phrasea/SearchEngine/SearchEngineOptionsTest.php b/tests/Alchemy/Tests/Phrasea/SearchEngine/SearchEngineOptionsTest.php index 139d501f1f..78b69c4e96 100644 --- a/tests/Alchemy/Tests/Phrasea/SearchEngine/SearchEngineOptionsTest.php +++ b/tests/Alchemy/Tests/Phrasea/SearchEngine/SearchEngineOptionsTest.php @@ -39,7 +39,7 @@ class SearchEngineOptionsTest extends \PhraseanetPHPUnitAbstract */ public function testFromRequest() { - self::$DI['app']['authentication']->openAccount(self::$DI['user']); + $this->authenticate(self::$DI['app']); foreach ($this->provideRequestData() as $pack) { list ($query, $request, $field, $dateField) = $pack; diff --git a/tests/Alchemy/Tests/Phrasea/Security/FirewallTest.php b/tests/Alchemy/Tests/Phrasea/Security/FirewallTest.php index e6b6090d20..b4d25280a0 100644 --- a/tests/Alchemy/Tests/Phrasea/Security/FirewallTest.php +++ b/tests/Alchemy/Tests/Phrasea/Security/FirewallTest.php @@ -19,7 +19,7 @@ class FirewallTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testRequiredAuthNotAuthenticated() { - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); self::$DI['app']['firewall']->requireAuthentication(self::$DI['app']); } } diff --git a/tests/classes/PhraseanetPHPUnitAbstract.php b/tests/classes/PhraseanetPHPUnitAbstract.php index a9d1208203..123084232d 100644 --- a/tests/classes/PhraseanetPHPUnitAbstract.php +++ b/tests/classes/PhraseanetPHPUnitAbstract.php @@ -920,6 +920,14 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase { $app['session']->clear(); $app['session']->set('usr_id', self::$DI['user']->get_id()); + $session = new \Entities\Session(); + $session->setUsrId(self::$DI['user']->get_id()); + $session->setUserAgent(''); + self::$DI['app']['EM']->persist($session); + self::$DI['app']['EM']->flush(); + + $app['session']->set('session_id', $session->getId()); + self::$DI['app']['authentication']->reinitUser(); } diff --git a/tests/classes/Session/Session_LoggerTest.php b/tests/classes/Session/Session_LoggerTest.php index bf6aaab598..48b6213f54 100644 --- a/tests/classes/Session/Session_LoggerTest.php +++ b/tests/classes/Session/Session_LoggerTest.php @@ -17,7 +17,7 @@ class Session_LoggerTest extends PhraseanetPHPUnitAbstract { $user = self::$DI['user']; - self::$DI['app']['authentication']->openAccount(self::$DI['user']); + $this->authenticate(self::$DI['app']); $logger_creater = self::$DI['app']['phraseanet.logger']; foreach ($user->ACL()->get_granted_sbas() as $databox) { @@ -52,7 +52,7 @@ class Session_LoggerTest extends PhraseanetPHPUnitAbstract $ses_id = self::$DI['app']['session']->get('session_id'); $usr_id = self::$DI['app']['authentication']->getUser()->get_id(); - self::$DI['app']['authentication']->closeAccount(); + $this->logout(self::$DI['app']); $sql = 'SELECT id FROM log WHERE sit_session = :ses_id AND usrid = :usr_id AND site = :site'; diff --git a/tests/classes/api/v1/api_v1_adapterTest.php b/tests/classes/api/v1/api_v1_adapterTest.php index 2b84a0fb73..2818c154dc 100644 --- a/tests/classes/api/v1/api_v1_adapterTest.php +++ b/tests/classes/api/v1/api_v1_adapterTest.php @@ -160,7 +160,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract public function testSearch_recordsWithRecords() { - self::$DI['app']['authentication']->openAccount(self::$DI['user']); + $this->authenticate(self::$DI['app']); $record = \record_adapter::createFromFile(BorderFile::buildFromPathfile(__DIR__ . '/../../../files/cestlafete.jpg', self::$DI['collection'], self::$DI['app']), self::$DI['app']); @@ -240,7 +240,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract public function testSearch_recordsWithStories() { - self::$DI['app']['authentication']->openAccount(self::$DI['user']); + $this->authenticate(self::$DI['app']); $story = \record_adapter::createStory(self::$DI['app'], self::$DI['collection']); @@ -272,7 +272,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract public function testSearchWithStories() { - self::$DI['app']['authentication']->openAccount(self::$DI['user']); + $this->authenticate(self::$DI['app']); $story = \record_adapter::createStory(self::$DI['app'], self::$DI['collection']); @@ -307,7 +307,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract public function testSearchWithRecords() { - self::$DI['app']['authentication']->openAccount(self::$DI['user']); + $this->authenticate(self::$DI['app']); $record = \record_adapter::createFromFile(BorderFile::buildFromPathfile(__DIR__ . '/../../../files/cestlafete.jpg', self::$DI['collection'], self::$DI['app']), self::$DI['app']); From c5d52c2c1081ee7df1e706a03ce4f01fd19cfa83 Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Thu, 31 Oct 2013 15:35:19 +0100 Subject: [PATCH 2/2] Fix z-index issue for datepickers --- templates/web/prod/index.html.twig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/web/prod/index.html.twig b/templates/web/prod/index.html.twig index 573383c2f5..957a104631 100644 --- a/templates/web/prod/index.html.twig +++ b/templates/web/prod/index.html.twig @@ -423,14 +423,14 @@
- +
{% trans 'phraseanet::time:: a' %}
- +