Merge branch '3.8'

Conflicts:
	tests/Alchemy/Tests/Phrasea/Application/OverviewTest.php
This commit is contained in:
Romain Neutron
2013-10-31 17:56:48 +01:00
22 changed files with 144 additions and 107 deletions

View File

@@ -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();

View File

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

View File

@@ -35,8 +35,10 @@
{% set row = session['session'] %}
<tr id="row-{{ row.Id() }}">
<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>
{% else %}
{% trans 'Current session' %}
{% endif %}
</td>
<td>

View File

@@ -427,14 +427,14 @@
<td style="padding-right: 5px;">
<div class="input-prepend">
<span class="add-on"><i class="icon-calendar"></i></span>
<input onchange="checkFilters(true);" class="datepicker input-small" type="text" name="date_min" style="margin: 0;" />
<input onchange="checkFilters(true);" class="datepicker input-small" type="text" name="date_min" style="margin: 0;position: relative; z-index: 10001;" />
</div>
</td>
<td>{% trans 'phraseanet::time:: a' %}</td>
<td>
<div class="input-prepend">
<span class="add-on"><i class="icon-calendar"></i></span>
<input onchange="checkFilters(true);" class="datepicker input-small" type="text" name="date_max" style="margin: 0;" />
<input onchange="checkFilters(true);" class="datepicker input-small" type="text" name="date_max" style="margin: 0;position: relative; z-index: 10001;" />
</div>
</td>
</tr>

View File

@@ -149,6 +149,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(

View File

@@ -27,7 +27,7 @@ class LightboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testRouteSlash()
{
self::$DI['app']['authentication']->openAccount(self::$DI['user']);
$this->authenticate(self::$DI['app']);
$baskets = $this->insertFiveBasket();
@@ -54,7 +54,7 @@ class LightboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
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());
@@ -178,7 +178,7 @@ class LightboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testValidate()
{
self::$DI['app']['authentication']->openAccount(self::$DI['user']);
$this->authenticate(self::$DI['app']);
$basket = $this->insertOneValidationBasket();
@@ -203,7 +203,7 @@ class LightboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testCompare()
{
self::$DI['app']['authentication']->openAccount(self::$DI['user']);
$this->authenticate(self::$DI['app']);
$basket = $this->insertOneBasket();
@@ -228,7 +228,7 @@ class LightboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
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']);

View File

@@ -61,23 +61,20 @@ class OverviewTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
}
public function testDatafilesRouteOnUnaccessibleRecordIsOkInPublicFeed()
public function testDatafilesRouteNotAuthenticatedIsOkInPublicFeed()
{
$tmp = tempnam(sys_get_temp_dir(), 'testEtag');
copy(__DIR__ . '/../../../../files/cestlafete.jpg', $tmp);
$publicFeed = \Feed_Adapter::create(self::$DI['app'], self::$DI['user'], 'titre', 'subtitre');
$publicFeed->set_public(true);
$publisher = \Feed_Publisher_Adapter::getPublisher(self::$DI['app']['phraseanet.appbox'], $publicFeed, self::$DI['user']);
$entry = \Feed_Entry_Adapter::create(self::$DI['app'], $publicFeed, $publisher, 'titre', 'sub titre entry', 'author name', 'author email', false);
self::$DI['record_1']->move_to_collection(self::$DI['collection_no_access'], self::$DI['app']['phraseanet.appbox']);
$item = \Feed_Entry_Item::create(self::$DI['app']['phraseanet.appbox'], $entry, self::$DI['record_1']);
$media = self::$DI['app']['mediavorus']->guess($tmp);
self::$DI['client']->request('GET', '/datafiles/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/preview/');
$file = new File(self::$DI['app'], $media, self::$DI['collection_no_access']);
$record = \record_adapter::createFromFile($file, self::$DI['app']);
$record->generate_subdefs($record->get_databox(), self::$DI['app']);
$item = $this->insertOneFeedItem(self::$DI['user'], true, 1, $record);
self::$DI['client']->request('GET', '/datafiles/' . $record->get_sbas_id() . '/' . $record->get_record_id() . '/preview/');
$this->assertEquals(200, self::$DI['client']->getResponse()->getStatusCode());
unlink($tmp);
self::$DI['record_1']->move_to_collection(self::$DI['collection'], self::$DI['app']['phraseanet.appbox']);
$publicFeed->set_public(false);
}
public function testDatafilesRouteNotAuthenticatedUnknownSubdef()
@@ -210,12 +207,17 @@ class OverviewTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testPermalinkRouteNotAuthenticatedIsOkInPublicFeed()
{
$record = $this->insertOneFeedItem(self::$DI['user'], true)->getRecord(self::$DI['app']);
$publicFeed = \Feed_Adapter::create(self::$DI['app'], self::$DI['user'], 'titre', 'subtitre');
$publicFeed->set_public(true);
$publisher = \Feed_Publisher_Adapter::getPublisher(self::$DI['app']['phraseanet.appbox'], $publicFeed, self::$DI['user']);
$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();
self::$DI['client']->request('GET', '/permalink/v1/' . $record->get_sbas_id() . '/' . $record->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());
$publicFeed->set_public(false);
}
protected function get_a_permaviewBCcompatibility(array $headers = array())

View File

@@ -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
*/

View File

@@ -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());

View File

@@ -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());
}

View File

@@ -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();

View File

@@ -78,7 +78,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();
@@ -114,7 +114,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(
@@ -144,7 +144,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'];
@@ -186,7 +186,7 @@ class RecordsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/
public function testGetRecordDetailFeed()
{
self::$DI['app']['authentication']->openAccount(self::$DI['user']);
$this->authenticate(self::$DI['app']);
self::$DI['app']['notification.deliverer'] = $this->getMockBuilder('Alchemy\Phrasea\Notification\Deliverer')
->disableOriginalConstructor()

View File

@@ -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/');

View File

@@ -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'),

View File

@@ -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())

View File

@@ -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()

View File

@@ -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()

View File

@@ -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;

View File

@@ -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']);
}
}

View File

@@ -1113,6 +1113,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();
}

View File

@@ -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';

View File

@@ -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']);