mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 07:23:13 +00:00
Add API auth events
This commit is contained in:
@@ -12,6 +12,8 @@
|
|||||||
namespace Alchemy\Phrasea\Application;
|
namespace Alchemy\Phrasea\Application;
|
||||||
|
|
||||||
use Alchemy\Phrasea\Application as PhraseaApplication;
|
use Alchemy\Phrasea\Application as PhraseaApplication;
|
||||||
|
use Alchemy\Phrasea\Authentication\Context;
|
||||||
|
use Alchemy\Phrasea\Core\Event\PreAuthenticate;
|
||||||
use Alchemy\Phrasea\Core\PhraseaEvents;
|
use Alchemy\Phrasea\Core\PhraseaEvents;
|
||||||
use Alchemy\Phrasea\Controller\Api\Oauth2;
|
use Alchemy\Phrasea\Controller\Api\Oauth2;
|
||||||
use Alchemy\Phrasea\Controller\Api\V1;
|
use Alchemy\Phrasea\Controller\Api\V1;
|
||||||
|
@@ -4,6 +4,7 @@ namespace Alchemy\Tests\Phrasea\Application;
|
|||||||
|
|
||||||
use Alchemy\Phrasea\Border\File;
|
use Alchemy\Phrasea\Border\File;
|
||||||
use Alchemy\Phrasea\Border\Manager;
|
use Alchemy\Phrasea\Border\Manager;
|
||||||
|
use Alchemy\Phrasea\Core\PhraseaEvents;
|
||||||
use Symfony\Component\HttpKernel\Client;
|
use Symfony\Component\HttpKernel\Client;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
@@ -112,6 +113,38 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
|
|||||||
parent::tearDownAfterClass();
|
parent::tearDownAfterClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider provideEventNames
|
||||||
|
*/
|
||||||
|
public function testThatEventsAreDispatched($eventName, $className, $route)
|
||||||
|
{
|
||||||
|
$preEvent = 0;
|
||||||
|
$phpunit = $this;
|
||||||
|
self::$DI['app']['dispatcher']->addListener($eventName, function ($event) use ($phpunit, &$preEvent, $className) {
|
||||||
|
$preEvent++;
|
||||||
|
$phpunit->assertInstanceOf($className, $event);
|
||||||
|
});
|
||||||
|
|
||||||
|
$this->setToken(self::$token);
|
||||||
|
self::$DI['client']->request('GET', '/databoxes/list/', $this->getParameters(), array(), array('HTTP_Accept' => $this->getAcceptMimeType()));
|
||||||
|
|
||||||
|
$this->assertEquals(1, $preEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function provideEventNames()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array(PhraseaEvents::PRE_AUTHENTICATE, 'Alchemy\Phrasea\Core\Event\PreAuthenticate', '/databoxes/list/'),
|
||||||
|
array(PhraseaEvents::API_OAUTH2_START, 'Alchemy\Phrasea\Core\Event\ApiOAuth2StartEvent', '/databoxes/list/'),
|
||||||
|
array(PhraseaEvents::API_OAUTH2_END, 'Alchemy\Phrasea\Core\Event\ApiOAuth2EndEvent', '/databoxes/list/'),
|
||||||
|
array(PhraseaEvents::API_RESULT, 'Alchemy\Phrasea\Core\Event\ApiResultEvent', '/databoxes/list/'),
|
||||||
|
array(PhraseaEvents::PRE_AUTHENTICATE, 'Alchemy\Phrasea\Core\Event\PreAuthenticate', '/no-route'),
|
||||||
|
array(PhraseaEvents::API_OAUTH2_START, 'Alchemy\Phrasea\Core\Event\ApiOAuth2StartEvent', '/no-route'),
|
||||||
|
array(PhraseaEvents::API_OAUTH2_END, 'Alchemy\Phrasea\Core\Event\ApiOAuth2EndEvent', '/no-route'),
|
||||||
|
array(PhraseaEvents::API_RESULT, 'Alchemy\Phrasea\Core\Event\ApiResultEvent', '/no-route'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function testRouteNotFound()
|
public function testRouteNotFound()
|
||||||
{
|
{
|
||||||
$route = '/api/v1/nothinghere';
|
$route = '/api/v1/nothinghere';
|
||||||
|
Reference in New Issue
Block a user