Merge pull request #742 from romainneutron/fix-1555

Fix #1555 : API sessions remain open
This commit is contained in:
Romain Neutron
2013-10-31 08:35:00 -07:00
21 changed files with 130 additions and 95 deletions

View File

@@ -116,6 +116,15 @@ class Authenticator
*/ */
public function closeAccount() 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->session->invalidate();
$this->reinitUser(); $this->reinitUser();

View File

@@ -162,6 +162,10 @@ class V1 implements ControllerProviderInterface
); );
}); });
$controllers->after(function () use ($app) {
$app['authentication']->closeAccount();
});
/** /**
* Method Not Allowed Closure * Method Not Allowed Closure
*/ */

View File

@@ -35,8 +35,10 @@
{% set row = session['session'] %} {% set row = session['session'] %}
<tr id="row-{{ row.Id() }}"> <tr id="row-{{ row.Id() }}">
<td> <td>
{% if app['session'].get('phrasea_session_id') != row.Id() %} {% if app['session'].get('session_id') != row.Id() %}
<a href="{{ path('delete_session', {"id": row.Id()}) }}" title="{% trans %}End Activity{% endtrans %}" class="btn btn-inverse btn-small delete-session"><i class="icon-remove"> {% trans %}End Activity{% endtrans %}</i></a> <a href="{{ path('delete_session', {"id": row.Id()}) }}" title="{% trans %}End Activity{% endtrans %}" class="btn btn-inverse btn-small delete-session"><i class="icon-remove"> {% trans %}End Activity{% endtrans %}</i></a>
{% else %}
{% trans 'Current session' %}
{% endif %} {% endif %}
</td> </td>
<td> <td>

View File

@@ -148,6 +148,14 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->assertEquals(1, $preEvent); $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() public function provideEventNames()
{ {
return array( return array(

View File

@@ -39,7 +39,7 @@ class ApplicationLightboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac
public function testRouteSlash() public function testRouteSlash()
{ {
self::$DI['app']['authentication']->openAccount(self::$DI['user']); $this->authenticate(self::$DI['app']);
$baskets = $this->insertFiveBasket(); $baskets = $this->insertFiveBasket();
@@ -66,7 +66,7 @@ class ApplicationLightboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac
public function testAuthenticationWithToken() public function testAuthenticationWithToken()
{ {
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
$Basket = $this->insertOneBasket(); $Basket = $this->insertOneBasket();
$token = self::$DI['app']['tokens']->getUrlToken(\random::TYPE_VIEW, self::$DI['user_alt2']->get_id(), null, $Basket->getId()); $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() public function testValidate()
{ {
self::$DI['app']['authentication']->openAccount(self::$DI['user']); $this->authenticate(self::$DI['app']);
$basket = $this->insertOneValidationBasket(); $basket = $this->insertOneValidationBasket();
@@ -212,7 +212,7 @@ class ApplicationLightboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac
public function testCompare() public function testCompare()
{ {
self::$DI['app']['authentication']->openAccount(self::$DI['user']); $this->authenticate(self::$DI['app']);
$basket = $this->insertOneBasket(); $basket = $this->insertOneBasket();
@@ -237,7 +237,7 @@ class ApplicationLightboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac
public function testFeedEntry() 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']); $this->set_user_agent(self::USER_AGENT_FIREFOX8MAC, self::$DI['app']);

View File

@@ -55,7 +55,7 @@ class ApplicationOverviewTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac
public function testDatafilesRouteNotAuthenticated() 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/'); 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()); $this->assertForbiddenResponse(self::$DI['client']->getResponse());
@@ -79,7 +79,7 @@ class ApplicationOverviewTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac
public function testDatafilesRouteNotAuthenticatedUnknownSubdef() 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/'); 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()); $this->assertForbiddenResponse(self::$DI['client']->getResponse());
@@ -96,7 +96,7 @@ class ApplicationOverviewTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac
public function testPermalinkNotAuthenticated() public function testPermalinkNotAuthenticated()
{ {
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
$this->assertFalse(self::$DI['app']['authentication']->isAuthenticated()); $this->assertFalse(self::$DI['app']['authentication']->isAuthenticated());
$this->get_a_permalinkBCcompatibility(array("Content-Type" => "image/jpeg")); $this->get_a_permalinkBCcompatibility(array("Content-Type" => "image/jpeg"));
$this->get_a_permaviewBCcompatibility(array("Content-Type" => "text/html; charset=UTF-8")); $this->get_a_permaviewBCcompatibility(array("Content-Type" => "text/html; charset=UTF-8"));
@@ -112,7 +112,7 @@ class ApplicationOverviewTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac
public function testCaptionNotAuthenticated() public function testCaptionNotAuthenticated()
{ {
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
$this->assertFalse(self::$DI['app']['authentication']->isAuthenticated()); $this->assertFalse(self::$DI['app']['authentication']->isAuthenticated());
$this->get_a_caption(array("Content-Type" => "application/json")); $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); $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']); $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/'); 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()); $this->assertEquals(200, self::$DI['client']->getResponse()->getStatusCode());

View File

@@ -207,21 +207,25 @@ class AuthenticatorTest extends \PhraseanetPHPUnitAbstract
*/ */
public function testCloseAccount() public function testCloseAccount()
{ {
$app = new Application(); $app = self::$DI['app'];
$user = self::$DI['user']; $user = self::$DI['user'];
$app['browser'] = $browser = $this->getBrowserMock(); $authenticator = new Authenticator($app, $app['browser'], $app['session'], $app['EM']);
$app['session'] = $session = $this->getSessionMock(); $authenticator->openAccount($user);
$app['EM'] = $em = $this->getEntityManagerMock(); $this->assertNotNull($authenticator->getUser());
$session->set('usr_id', $user->get_id());
$authenticator = new Authenticator($app, $browser, $session, $em);
$authenticator->closeAccount(); $authenticator->closeAccount();
$this->assertNull($authenticator->getUser()); $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 * @covers Alchemy\Phrasea\Authentication\Authenticator::isAuthenticated
*/ */

View File

@@ -11,7 +11,7 @@ class RootTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testRouteSlash() 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')); self::$DI['client']->request('GET', '/admin/', array('section' => 'base:featured'));
$this->assertTrue(self::$DI['client']->getResponse()->isOk()); $this->assertTrue(self::$DI['client']->getResponse()->isOk());

View File

@@ -23,7 +23,7 @@ class RootTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testGetClient() public function testGetClient()
{ {
self::$DI['app']['authentication']->openAccount(self::$DI['user']); $this->authenticate(self::$DI['app']);
self::$DI['client']->request("GET", "/client/"); self::$DI['client']->request("GET", "/client/");
$this->assertTrue(self::$DI['client']->getResponse()->isOk()); $this->assertTrue(self::$DI['client']->getResponse()->isOk());
} }

View File

@@ -30,7 +30,7 @@ class QueryTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testQueryAnswerTrain() public function testQueryAnswerTrain()
{ {
self::$DI['app']['authentication']->openAccount(self::$DI['user']); $this->authenticate(self::$DI['app']);
self::$DI['record_24']; self::$DI['record_24'];
$options = new SearchEngineOptions(); $options = new SearchEngineOptions();

View File

@@ -83,7 +83,7 @@ class RecordsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testGetRecordDetailResult() public function testGetRecordDetailResult()
{ {
self::$DI['app']['authentication']->openAccount(self::$DI['user']); $this->authenticate(self::$DI['app']);
self::$DI['record_24']; self::$DI['record_24'];
$options = new SearchEngineOptions(); $options = new SearchEngineOptions();
@@ -119,7 +119,7 @@ class RecordsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testGetRecordDetailREG() public function testGetRecordDetailREG()
{ {
self::$DI['app']['authentication']->openAccount(self::$DI['user']); $this->authenticate(self::$DI['app']);
self::$DI['record_story_1']; self::$DI['record_story_1'];
$this->XMLHTTPRequest('POST', '/prod/records/', array( $this->XMLHTTPRequest('POST', '/prod/records/', array(
@@ -149,7 +149,7 @@ class RecordsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testGetRecordDetailBasket() public function testGetRecordDetailBasket()
{ {
self::$DI['app']['authentication']->openAccount(self::$DI['user']); $this->authenticate(self::$DI['app']);
$basket = $this->insertOneBasket(); $basket = $this->insertOneBasket();
$record = self::$DI['record_1']; $record = self::$DI['record_1'];
@@ -191,7 +191,7 @@ class RecordsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testGetRecordDetailFeed() public function testGetRecordDetailFeed()
{ {
self::$DI['app']['authentication']->openAccount(self::$DI['user']); $this->authenticate(self::$DI['app']);
self::$feed = \Feed_Adapter::create( self::$feed = \Feed_Adapter::create(
self::$DI['app'], self::$DI['app'],

View File

@@ -11,7 +11,7 @@ class ControllerRootTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testRouteSlash() public function testRouteSlash()
{ {
self::$DI['app']['authentication']->openAccount(self::$DI['user']); $this->authenticate(self::$DI['app']);
$crawler = self::$DI['client']->request('GET', '/prod/'); $crawler = self::$DI['client']->request('GET', '/prod/');

View File

@@ -15,7 +15,7 @@ class RootTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testRouteDashboard() public function testRouteDashboard()
{ {
self::$DI['app']['authentication']->openAccount(self::$DI['user']); $this->authenticate(self::$DI['app']);
self::$DI['client']->request('GET', '/report/dashboard'); self::$DI['client']->request('GET', '/report/dashboard');
@@ -26,7 +26,7 @@ class RootTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testRouteDashboardJson() public function testRouteDashboardJson()
{ {
self::$DI['app']['authentication']->openAccount(self::$DI['user']); $this->authenticate(self::$DI['app']);
$this->XMLHTTPRequest('GET', '/report/dashboard', array( $this->XMLHTTPRequest('GET', '/report/dashboard', array(
'dmin' => $this->dmin->format('Y-m-d H:i:s'), 'dmin' => $this->dmin->format('Y-m-d H:i:s'),

View File

@@ -55,7 +55,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testLoginRedirectPostLog() public function testLoginRedirectPostLog()
{ {
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
self::$DI['client']->request('GET', '/login/', array('postlog' => '1', 'redirect' => 'prod')); self::$DI['client']->request('GET', '/login/', array('postlog' => '1', 'redirect' => 'prod'));
$response = self::$DI['client']->getResponse(); $response = self::$DI['client']->getResponse();
@@ -68,7 +68,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testLoginError($type, $message) public function testLoginError($type, $message)
{ {
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
self::$DI['app']->addFlash($type, $message); self::$DI['app']->addFlash($type, $message);
$crawler = self::$DI['client']->request('GET', '/login/'); $crawler = self::$DI['client']->request('GET', '/login/');
@@ -83,7 +83,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testRegisterConfirmMailNoCode() public function testRegisterConfirmMailNoCode()
{ {
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
self::$DI['client']->request('GET', '/login/register-confirm/'); self::$DI['client']->request('GET', '/login/register-confirm/');
$response = self::$DI['client']->getResponse(); $response = self::$DI['client']->getResponse();
@@ -97,7 +97,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testRegisterConfirmMailWrongCode() public function testRegisterConfirmMailWrongCode()
{ {
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
self::$DI['client']->request('GET', '/login/register-confirm/', array( self::$DI['client']->request('GET', '/login/register-confirm/', array(
'code' => '34dT0k3n' 'code' => '34dT0k3n'
)); ));
@@ -113,7 +113,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testRegisterConfirmMailUserNotFound() public function testRegisterConfirmMailUserNotFound()
{ {
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
$email = $this->generateEmail(); $email = $this->generateEmail();
$token = self::$DI['app']['tokens']->getUrlToken(\random::TYPE_EMAIL, 0, null, $email); $token = self::$DI['app']['tokens']->getUrlToken(\random::TYPE_EMAIL, 0, null, $email);
self::$DI['client']->request('GET', '/login/register-confirm/', array( self::$DI['client']->request('GET', '/login/register-confirm/', array(
@@ -131,7 +131,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testRegisterConfirmMailUnlocked() public function testRegisterConfirmMailUnlocked()
{ {
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
$email = $this->generateEmail(); $email = $this->generateEmail();
$token = self::$DI['app']['tokens']->getUrlToken(\random::TYPE_EMAIL, self::$DI['user']->get_id(), null, $email); $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'); $this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailSuccessEmailConfirmationRegistered');
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
$email = $this->generateEmail(); $email = $this->generateEmail();
$appboxRegister = new \appbox_register(self::$DI['app']['phraseanet.appbox']); $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); $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); $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(); $email = $this->generateEmail();
$token = self::$DI['app']['tokens']->getUrlToken(\random::TYPE_EMAIL, $user->get_id(), null, $email); $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() public function testRenewPasswordInvalidEmail()
{ {
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
$crawler = self::$DI['client']->request('POST', '/login/forgot-password/', array( $crawler = self::$DI['client']->request('POST', '/login/forgot-password/', array(
'email' => 'invalid.email.com', 'email' => 'invalid.email.com',
'_token' => 'token', '_token' => 'token',
@@ -218,7 +218,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testRenewPasswordUnknowEmail() public function testRenewPasswordUnknowEmail()
{ {
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
$crawler = self::$DI['client']->request('POST', '/login/forgot-password/', array( $crawler = self::$DI['client']->request('POST', '/login/forgot-password/', array(
'email' => 'invalid_email@test.com', 'email' => 'invalid_email@test.com',
'_token' => 'token', '_token' => 'token',
@@ -236,7 +236,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{ {
$this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailRequestPasswordUpdate'); $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( self::$DI['client']->request('POST', '/login/forgot-password/', array(
'email' => self::$DI['user']->get_email(), 'email' => self::$DI['user']->get_email(),
'_token' => 'token', '_token' => 'token',
@@ -253,7 +253,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testRenewPasswordBadArguments() 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()); $token = self::$DI['app']['tokens']->getUrlToken(\random::TYPE_PASSWORD, self::$DI['user']->get_id());
$crawler = self::$DI['client']->request('POST', '/login/renew-password/', array( $crawler = self::$DI['client']->request('POST', '/login/renew-password/', array(
'token' => $token, 'token' => $token,
@@ -269,7 +269,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testRenewPasswordBadToken() public function testRenewPasswordBadToken()
{ {
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
self::$DI['client']->request('POST', '/login/renew-password/', array( self::$DI['client']->request('POST', '/login/renew-password/', array(
'token' => 'badToken', 'token' => 'badToken',
'_token' => 'token', '_token' => 'token',
@@ -296,7 +296,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testRenewPasswordNoToken() public function testRenewPasswordNoToken()
{ {
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
self::$DI['client']->request('POST', '/login/renew-password/', array( self::$DI['client']->request('POST', '/login/renew-password/', array(
'_token' => 'token', '_token' => 'token',
'password' => array('password' => 'password', 'confirm' => 'password') 'password' => array('password' => 'password', 'confirm' => 'password')
@@ -325,7 +325,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testRenewPassword() 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()); $token = self::$DI['app']['tokens']->getUrlToken(\random::TYPE_PASSWORD, self::$DI['user']->get_id());
self::$DI['client']->request('POST', '/login/renew-password/', array( self::$DI['client']->request('POST', '/login/renew-password/', array(
@@ -347,7 +347,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testRenewPasswordPageShowsFlashMessages($type, $message) public function testRenewPasswordPageShowsFlashMessages($type, $message)
{ {
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
self::$DI['app']->addFlash($type, $message); self::$DI['app']->addFlash($type, $message);
$token = self::$DI['app']['tokens']->getUrlToken(\random::TYPE_PASSWORD, self::$DI['user']->get_id()); $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() public function testForgotPasswordGet()
{ {
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
self::$DI['client']->request('GET', '/login/forgot-password/'); self::$DI['client']->request('GET', '/login/forgot-password/');
$this->assertTrue(self::$DI['client']->getResponse()->isOk()); $this->assertTrue(self::$DI['client']->getResponse()->isOk());
@@ -381,7 +381,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testForgotPasswordInvalidEmail() public function testForgotPasswordInvalidEmail()
{ {
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
$crawler = self::$DI['client']->request('POST', '/login/forgot-password/', array( $crawler = self::$DI['client']->request('POST', '/login/forgot-password/', array(
'_token' => 'token', '_token' => 'token',
'email' => 'invalid.email', 'email' => 'invalid.email',
@@ -395,7 +395,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testForgotPasswordWrongEmail() public function testForgotPasswordWrongEmail()
{ {
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
$crawler = self::$DI['client']->request('POST', '/login/forgot-password/', array( $crawler = self::$DI['client']->request('POST', '/login/forgot-password/', array(
'_token' => 'token', '_token' => 'token',
'email' => 'invalid@email.com', 'email' => 'invalid@email.com',
@@ -411,7 +411,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{ {
$this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailRequestPasswordUpdate'); $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( $crawler = self::$DI['client']->request('POST', '/login/forgot-password/', array(
'_token' => 'token', '_token' => 'token',
'email' => self::$DI['user']->get_email(), 'email' => self::$DI['user']->get_email(),
@@ -429,7 +429,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testGetRegister($type, $message) public function testGetRegister($type, $message)
{ {
self::$DI['app']['registration.enabled'] = true; self::$DI['app']['registration.enabled'] = true;
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
self::$DI['app']->addFlash($type, $message); self::$DI['app']->addFlash($type, $message);
$crawler = self::$DI['client']->request('GET', '/login/register-classic/'); $crawler = self::$DI['client']->request('GET', '/login/register-classic/');
@@ -442,7 +442,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testGetRegisterWithRegisterIdBindDataToForm() public function testGetRegisterWithRegisterIdBindDataToForm()
{ {
self::$DI['app']['registration.enabled'] = true; self::$DI['app']['registration.enabled'] = true;
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
$provider = $this->getMock('Alchemy\Phrasea\Authentication\Provider\ProviderInterface'); $provider = $this->getMock('Alchemy\Phrasea\Authentication\Provider\ProviderInterface');
@@ -488,7 +488,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testGetPostRegisterWhenRegistrationDisabled($method, $route) public function testGetPostRegisterWhenRegistrationDisabled($method, $route)
{ {
self::$DI['app']['registration.enabled'] = false; self::$DI['app']['registration.enabled'] = false;
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
self::$DI['client']->request($method, $route); self::$DI['client']->request($method, $route);
$this->assertEquals(404, self::$DI['client']->getResponse()->getStatusCode()); $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.enabled'] = true;
self::$DI['app']['registration.fields'] = $extraParameters; self::$DI['app']['registration.fields'] = $extraParameters;
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
$parameters = array_merge(array('_token' => 'token'), $parameters); $parameters = array_merge(array('_token' => 'token'), $parameters);
foreach ($parameters as $key => $parameter) { foreach ($parameters as $key => $parameter) {
@@ -528,7 +528,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testPostRegisterWithoutParams() public function testPostRegisterWithoutParams()
{ {
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
$crawler = self::$DI['client']->request('POST', '/login/register-classic/'); $crawler = self::$DI['client']->request('POST', '/login/register-classic/');
$this->assertFalse(self::$DI['client']->getResponse()->isRedirect()); $this->assertFalse(self::$DI['client']->getResponse()->isRedirect());
@@ -782,7 +782,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testPostRegisterWithProviderIdAndAlreadyBoundProvider() public function testPostRegisterWithProviderIdAndAlreadyBoundProvider()
{ {
self::$DI['app']['registration.fields'] = array(); self::$DI['app']['registration.fields'] = array();
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
$provider = $this->getMock('Alchemy\Phrasea\Authentication\Provider\ProviderInterface'); $provider = $this->getMock('Alchemy\Phrasea\Authentication\Provider\ProviderInterface');
$this->addProvider('provider-test', $provider); $this->addProvider('provider-test', $provider);
@@ -832,7 +832,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testPostRegisterWithUnknownProvider() public function testPostRegisterWithUnknownProvider()
{ {
self::$DI['app']['registration.fields'] = array(); self::$DI['app']['registration.fields'] = array();
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
$parameters = array_merge(array('_token' => 'token'), array( $parameters = array_merge(array('_token' => 'token'), array(
"password" => array( "password" => array(
@@ -867,7 +867,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testPostRegisterWithProviderNotAuthenticated() public function testPostRegisterWithProviderNotAuthenticated()
{ {
self::$DI['app']['registration.fields'] = array(); self::$DI['app']['registration.fields'] = array();
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
$provider = $this->getMock('Alchemy\Phrasea\Authentication\Provider\ProviderInterface'); $provider = $this->getMock('Alchemy\Phrasea\Authentication\Provider\ProviderInterface');
$this->addProvider('provider-test', $provider); $this->addProvider('provider-test', $provider);
@@ -909,7 +909,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testPostRegisterWithProviderId() public function testPostRegisterWithProviderId()
{ {
self::$DI['app']['registration.fields'] = array(); self::$DI['app']['registration.fields'] = array();
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
$emails = array( $emails = array(
'Alchemy\Phrasea\Notification\Mail\MailRequestEmailConfirmation'=>0, 'Alchemy\Phrasea\Notification\Mail\MailRequestEmailConfirmation'=>0,
@@ -983,7 +983,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{ {
self::$DI['app']['registration.fields'] = $extraParameters; self::$DI['app']['registration.fields'] = $extraParameters;
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
$emails = array( $emails = array(
'Alchemy\Phrasea\Notification\Mail\MailRequestEmailConfirmation'=>0, 'Alchemy\Phrasea\Notification\Mail\MailRequestEmailConfirmation'=>0,
@@ -1044,7 +1044,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testSendConfirmMailBadRequest() public function testSendConfirmMailBadRequest()
{ {
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
self::$DI['client']->request('GET', '/login/send-mail-confirm/'); self::$DI['client']->request('GET', '/login/send-mail-confirm/');
$this->assertBadResponse(self::$DI['client']->getResponse()); $this->assertBadResponse(self::$DI['client']->getResponse());
@@ -1057,7 +1057,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{ {
$this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailRequestEmailConfirmation'); $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())); self::$DI['client']->request('GET', '/login/send-mail-confirm/', array('usr_id' => self::$DI['user']->get_id()));
$response = self::$DI['client']->getResponse(); $response = self::$DI['client']->getResponse();
@@ -1071,7 +1071,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testSendConfirmMailWrongUser() 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)); self::$DI['client']->request('GET', '/login/send-mail-confirm/', array('usr_id' => 0));
$response = self::$DI['client']->getResponse(); $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_password($password);
self::$DI['app']['authentication']->getUser()->set_mail_locked(false); 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()); 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']);
@@ -1116,7 +1116,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
self::$DI['app']['authentication']->getUser()->set_password($password); self::$DI['app']['authentication']->getUser()->set_password($password);
self::$DI['app']['authentication']->getUser()->set_mail_locked(false); self::$DI['app']['authentication']->getUser()->set_mail_locked(false);
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
$preEvent = 0; $preEvent = 0;
$phpunit = $this; $phpunit = $this;
@@ -1163,7 +1163,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$login = self::$DI['app']['authentication']->getUser()->get_login(); $login = self::$DI['app']['authentication']->getUser()->get_login();
self::$DI['app']['authentication']->getUser()->set_password($password); 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()); 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']);
@@ -1189,7 +1189,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$user->ACL()->give_access_to_base(array(self::$DI['collection']->get_base_id())); $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()); 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']);
@@ -1221,7 +1221,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$user = \User_Adapter::getInstance($usr_id, self::$DI['app']); $user = \User_Adapter::getInstance($usr_id, self::$DI['app']);
$user->ACL()->give_access_to_base(array(self::$DI['collection']->get_base_id())); $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()); 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']);
@@ -1235,7 +1235,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testGuestAuthenticateWithGetMethod() public function testGuestAuthenticateWithGetMethod()
{ {
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
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']);
@@ -1255,7 +1255,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testBadAuthenticate() public function testBadAuthenticate()
{ {
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
self::$DI['client']->request('POST', '/login/authenticate/', array( self::$DI['client']->request('POST', '/login/authenticate/', array(
'login' => self::$DI['user']->get_login(), 'login' => self::$DI['user']->get_login(),
'password' => 'test', 'password' => 'test',
@@ -1272,7 +1272,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testBadAuthenticateCheckRedirect() public function testBadAuthenticateCheckRedirect()
{ {
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
self::$DI['client']->request('POST', '/login/authenticate/', array( self::$DI['client']->request('POST', '/login/authenticate/', array(
'login' => self::$DI['user']->get_login(), 'login' => self::$DI['user']->get_login(),
'password' => 'test', 'password' => 'test',
@@ -1290,7 +1290,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testMailLockedAuthenticate() public function testMailLockedAuthenticate()
{ {
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
$password = \random::generatePassword(); $password = \random::generatePassword();
self::$DI['user']->set_mail_locked(true); self::$DI['user']->set_mail_locked(true);
self::$DI['client']->request('POST', '/login/authenticate/', array( self::$DI['client']->request('POST', '/login/authenticate/', array(
@@ -1327,7 +1327,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
->with($parameters) ->with($parameters)
->will($this->returnValue($response)); ->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); self::$DI['client']->request('GET', '/login/provider/provider-test/authenticate/', $parameters);
$this->assertSame($response, self::$DI['client']->getResponse()); $this->assertSame($response, self::$DI['client']->getResponse());
@@ -1367,7 +1367,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
->with($this->equalTo('provider-test')) ->with($this->equalTo('provider-test'))
->will($this->throwException(new InvalidArgumentException('Provider not found'))); ->will($this->throwException(new InvalidArgumentException('Provider not found')));
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
self::$DI['client']->request($method, $route); self::$DI['client']->request($method, $route);
$this->assertEquals(404, self::$DI['client']->getResponse()->getStatusCode()); $this->assertEquals(404, self::$DI['client']->getResponse()->getStatusCode());
@@ -1398,7 +1398,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
->method('onCallback') ->method('onCallback')
->will($this->throwException(new NotAuthenticatedException('Not authenticated.'))); ->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/'); self::$DI['client']->request('GET', '/login/provider/provider-test/callback/');
$this->assertSame(302, self::$DI['client']->getResponse()->getStatusCode()); $this->assertSame(302, self::$DI['client']->getResponse()->getStatusCode());
@@ -1428,7 +1428,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
->method('getToken') ->method('getToken')
->will($this->returnValue($token)); ->will($this->returnValue($token));
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
self::$DI['client']->request('GET', '/login/provider/provider-test/callback/'); self::$DI['client']->request('GET', '/login/provider/provider-test/callback/');
$this->assertSame(302, self::$DI['client']->getResponse()->getStatusCode()); $this->assertSame(302, self::$DI['client']->getResponse()->getStatusCode());
@@ -1462,7 +1462,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
->with($token) ->with($token)
->will($this->returnValue($user)); ->will($this->returnValue($user));
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
self::$DI['client']->request('GET', '/login/provider/provider-test/callback/'); self::$DI['client']->request('GET', '/login/provider/provider-test/callback/');
$this->assertSame(302, self::$DI['client']->getResponse()->getStatusCode()); $this->assertSame(302, self::$DI['client']->getResponse()->getStatusCode());
@@ -1537,7 +1537,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
->method('isEnabled') ->method('isEnabled')
->will($this->returnValue(true)); ->will($this->returnValue(true));
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
self::$DI['client']->request('GET', '/login/provider/provider-test/callback/'); self::$DI['client']->request('GET', '/login/provider/provider-test/callback/');
$this->assertSame(302, self::$DI['client']->getResponse()->getStatusCode()); $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']['registration.enabled'] = true;
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
self::$DI['client']->request('GET', '/login/provider/provider-test/callback/'); self::$DI['client']->request('GET', '/login/provider/provider-test/callback/');
$this->assertSame(302, self::$DI['client']->getResponse()->getStatusCode()); $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']['registration.enabled'] = false;
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
self::$DI['client']->request('GET', '/login/provider/provider-test/callback/'); self::$DI['client']->request('GET', '/login/provider/provider-test/callback/');
$this->assertSame(302, self::$DI['client']->getResponse()->getStatusCode()); $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']['registration.fields'] = $fields;
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
self::$DI['client']->request('GET', '/login/registration-fields/'); self::$DI['client']->request('GET', '/login/registration-fields/');
$this->assertSame(200, self::$DI['client']->getResponse()->getStatusCode()); $this->assertSame(200, self::$DI['client']->getResponse()->getStatusCode());
@@ -1662,7 +1662,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testRegisterRedirectsNoAuthProvidersAvailable() public function testRegisterRedirectsNoAuthProvidersAvailable()
{ {
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
self::$DI['app']['authentication.providers'] = new ProvidersCollection(); self::$DI['app']['authentication.providers'] = new ProvidersCollection();
@@ -1674,7 +1674,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testRegisterDisplaysIfAuthProvidersAvailable() public function testRegisterDisplaysIfAuthProvidersAvailable()
{ {
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
$provider = $this->getMock('Alchemy\Phrasea\Authentication\Provider\ProviderInterface'); $provider = $this->getMock('Alchemy\Phrasea\Authentication\Provider\ProviderInterface');
$provider->expects($this->any()) $provider->expects($this->any())

View File

@@ -83,7 +83,7 @@ class RootTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testNoPersistentCookie() public function testNoPersistentCookie()
{ {
$app = self::$DI['app']; $app = self::$DI['app'];
$app['authentication']->closeAccount(); $this->logout($app);
$boolean = false; $boolean = false;
@@ -102,7 +102,7 @@ class RootTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testPersistentCookie() public function testPersistentCookie()
{ {
$app = self::$DI['app']; $app = self::$DI['app'];
$app['authentication']->closeAccount(); $this->logout(self::$DI['app']);
$browser = $this->getMockBuilder('\Browser') $browser = $this->getMockBuilder('\Browser')
->disableOriginalConstructor() ->disableOriginalConstructor()

View File

@@ -38,7 +38,7 @@ class SessionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testUpdSession() public function testUpdSession()
{ {
self::$DI['app']['authentication']->openAccount(self::$DI['user']); $this->authenticate(self::$DI['app']);
$this->XMLHTTPRequest('POST', '/session/update/', array( $this->XMLHTTPRequest('POST', '/session/update/', array(
'usr' => self::$DI['user']->get_id(), 'usr' => self::$DI['user']->get_id(),
@@ -55,7 +55,7 @@ class SessionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testUpdSessionBadRequestMissingModuleArgument() public function testUpdSessionBadRequestMissingModuleArgument()
{ {
self::$DI['app']['authentication']->openAccount(self::$DI['user']); $this->authenticate(self::$DI['app']);
$this->XMLHTTPRequest('POST', '/session/update/', array( $this->XMLHTTPRequest('POST', '/session/update/', array(
'usr' => self::$DI['user']->get_id() 'usr' => self::$DI['user']->get_id()

View File

@@ -39,7 +39,7 @@ class SearchEngineOptionsTest extends \PhraseanetPHPUnitAbstract
*/ */
public function testFromRequest() public function testFromRequest()
{ {
self::$DI['app']['authentication']->openAccount(self::$DI['user']); $this->authenticate(self::$DI['app']);
foreach ($this->provideRequestData() as $pack) { foreach ($this->provideRequestData() as $pack) {
list ($query, $request, $field, $dateField) = $pack; list ($query, $request, $field, $dateField) = $pack;

View File

@@ -19,7 +19,7 @@ class FirewallTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testRequiredAuthNotAuthenticated() public function testRequiredAuthNotAuthenticated()
{ {
self::$DI['app']['authentication']->closeAccount(); $this->logout(self::$DI['app']);
self::$DI['app']['firewall']->requireAuthentication(self::$DI['app']); self::$DI['app']['firewall']->requireAuthentication(self::$DI['app']);
} }
} }

View File

@@ -920,6 +920,14 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
{ {
$app['session']->clear(); $app['session']->clear();
$app['session']->set('usr_id', self::$DI['user']->get_id()); $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(); self::$DI['app']['authentication']->reinitUser();
} }

View File

@@ -17,7 +17,7 @@ class Session_LoggerTest extends PhraseanetPHPUnitAbstract
{ {
$user = self::$DI['user']; $user = self::$DI['user'];
self::$DI['app']['authentication']->openAccount(self::$DI['user']); $this->authenticate(self::$DI['app']);
$logger_creater = self::$DI['app']['phraseanet.logger']; $logger_creater = self::$DI['app']['phraseanet.logger'];
foreach ($user->ACL()->get_granted_sbas() as $databox) { 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'); $ses_id = self::$DI['app']['session']->get('session_id');
$usr_id = self::$DI['app']['authentication']->getUser()->get_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 $sql = 'SELECT id FROM log
WHERE sit_session = :ses_id AND usrid = :usr_id AND site = :site'; WHERE sit_session = :ses_id AND usrid = :usr_id AND site = :site';

View File

@@ -160,7 +160,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
public function testSearch_recordsWithRecords() 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']); $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() 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']); $story = \record_adapter::createStory(self::$DI['app'], self::$DI['collection']);
@@ -272,7 +272,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
public function testSearchWithStories() 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']); $story = \record_adapter::createStory(self::$DI['app'], self::$DI['collection']);
@@ -307,7 +307,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
public function testSearchWithRecords() 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']); $record = \record_adapter::createFromFile(BorderFile::buildFromPathfile(__DIR__ . '/../../../files/cestlafete.jpg', self::$DI['collection'], self::$DI['app']), self::$DI['app']);