Merge branch 'master' into PHRAS-2680-webhook-privacy-and-security

This commit is contained in:
Nicolas Maillat
2020-02-26 20:15:37 +01:00
committed by GitHub
122 changed files with 7306 additions and 3391 deletions

View File

@@ -10,6 +10,26 @@ use Alchemy\Phrasea\Command\Plugin\AddPlugin;
*/
class AddPluginTest extends PluginCommandTestCase
{
private $bkp = null;
public function setUp()
{
parent::setUp();
$this->bkp = self::$DI['app']['conf']->get('plugins');
}
public function tearDown()
{
if(is_null($this->bkp)) {
self::$DI['app']['conf']->remove('plugins');
}
else {
self::$DI['app']['conf']->set('plugins', $this->bkp);
}
parent::tearDown();
}
public function testExecute()
{
$source = 'TestPlugin';

View File

@@ -22,6 +22,8 @@ class DisablePluginTest extends PluginCommandTestCase
->with($this->equalTo('name'))
->will($this->returnValue('test-plugin'));
$bkp = self::$DI['cli']['conf']->get('plugins');
self::$DI['cli']['conf']->set(['plugins', 'test-plugin', 'enabled'], $initial);
$command = new DisablePlugin();
@@ -29,6 +31,13 @@ class DisablePluginTest extends PluginCommandTestCase
$this->assertSame(0, $command->execute($input, $output));
$this->assertFalse(self::$DI['cli']['conf']->get(['plugins', 'test-plugin', 'enabled']));
if(is_null($bkp)) {
self::$DI['cli']['conf']->remove('plugins');
}
else {
self::$DI['cli']['conf']->set('plugins', $bkp);
}
}
public function provideVariousInitialConfs()

View File

@@ -22,6 +22,8 @@ class EnablePluginTest extends PluginCommandTestCase
->with($this->equalTo('name'))
->will($this->returnValue('test-plugin'));
$bkp = self::$DI['cli']['conf']->get('plugins');
self::$DI['cli']['conf']->set(['plugins', 'test-plugin', 'enabled'], $initial);
$command = new EnablePlugin();
@@ -29,6 +31,13 @@ class EnablePluginTest extends PluginCommandTestCase
$this->assertSame(0, $command->execute($input, $output));
$this->assertTrue(self::$DI['cli']['conf']->get(['plugins', 'test-plugin', 'enabled']));
if(is_null($bkp)) {
self::$DI['cli']['conf']->remove('plugins');
}
else {
self::$DI['cli']['conf']->set('plugins', $bkp);
}
}
public function provideVariousInitialConfs()

View File

@@ -12,6 +12,21 @@ use Alchemy\Phrasea\Core\Configuration\StructureTemplate;
*/
class InstallTest extends \PhraseanetTestCase
{
private $bkp = null;
public function setUp()
{
parent::setUp();
$this->bkp = self::$DI['app']['conf']->get('main');
}
public function tearDown()
{
self::$DI['app']['conf']->set('main', $this->bkp);
parent::tearDown();
}
public function testRunWithoutProblems()
{
$input = $this->getMock('Symfony\Component\Console\Input\InputInterface');
@@ -78,9 +93,12 @@ class InstallTest extends \PhraseanetTestCase
case 'db-password':
return $infoDb['database']['password'];
break;
case 'yes':
return true;
break;
case 'es-host':
return 'localhost';
case 'es-port':
return 9200;
case 'es-index':
return 'phrasea_test';
default:
return '';
}

View File

@@ -1281,7 +1281,7 @@ class ApiJsonTest extends ApiTestCase
$tochange = [];
foreach ($statusStructure as $n => $datas) {
$tochange[$n] = substr($record_status, ($n - 1), 1) == '0' ? '1' : '0';
$tochange[$n] = substr($record_status, $n, 1) == '0' ? '1' : '0';
}
$this->evaluateMethodNotAllowedRoute($route, ['GET', 'PUT', 'DELETE']);
@@ -1305,7 +1305,8 @@ class ApiJsonTest extends ApiTestCase
// test record_status in string
$record_status_expected = $record_status;
$pos = strpos($record_status, '1');
$bitToChange = [];
$pos = strpos($record_status, '1', 4);
$bitToChange[$pos] = '1';
$response = $this->request('POST', $route, $this->getParameters(['status' => $bitToChange]), ['HTTP_Accept' => $this->getAcceptMimeType()]);

View File

@@ -132,9 +132,11 @@ class ExportTest extends \PhraseanetAuthenticatedWebTestCase
{
$app = $this->getApplication();
$bkp = $app['conf']->get('registry');
if (!$app['conf']->get(['registry', 'ftp', 'ftp-enabled'])) {
$app['conf']->set(['registry', 'ftp', 'ftp-enabled'], true);
self::$GV_activeFTP = true;
self::$GV_activeFTP = true;
}
/** @var User $user */
@@ -158,6 +160,8 @@ class ExportTest extends \PhraseanetAuthenticatedWebTestCase
$this->assertArrayHasKey('message', $datas);
$this->assertTrue($datas['success']);
unset($response, $datas);
$app['conf']->set('registry', $bkp);
}
/**

View File

@@ -2017,6 +2017,9 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
{
$app = $this->getApplication();
$this->logout($app);
$bkp = $app['phraseanet.configuration']['session'];
$app['phraseanet.configuration']['session'] = [
'idle' => 10,
'lifetime' => 60475,
@@ -2027,12 +2030,17 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
$this->assertSame(200, $client->getResponse()->getStatusCode());
$this->assertEquals('hidden', $crawler->filter('input[name="remember-me"]')->attr('type'));
$app['phraseanet.configuration']['session'] = $bkp;
}
public function testLoginPageWithNoIdleSessionTime()
{
$app = $this->getApplication();
$this->logout($app);
$bkp = $app['phraseanet.configuration']['session'];
$app['phraseanet.configuration']['session'] = [
'idle' => 0,
'lifetime' => 60475,
@@ -2043,6 +2051,8 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
$this->assertSame(200, $client->getResponse()->getStatusCode());
$this->assertEquals('checkbox', $crawler->filter('input[name="remember-me"]')->attr('type'));
$app['phraseanet.configuration']['session'] = $bkp;
}
private function addUsrAuthDoctrineEntitySupport($id, $out, $participants = false)

View File

@@ -81,16 +81,26 @@ class PluginServiceProviderTest extends ServiceProviderTestCase
}
$app = self::$DI['cli'];
$app['conf']->set(['binaries', 'php_binary'], null);
$bkp = $app['conf']->get(['main', 'binaries']);
$app['conf']->set(['main', 'binaries', 'php_binary'], null);
$app->register(new PluginServiceProvider());
$this->assertInstanceOf('Alchemy\Phrasea\Plugin\Management\ComposerInstaller', $app['plugins.composer-installer']);
$app['conf']->set(['main', 'binaries'], $bkp);
}
public function testInstallerCanDetectPhpConf()
{
$app = self::$DI['cli'];
$app['conf']->set(['binaries', 'php_binary'], null);
$bkp = $app['conf']->get(['main', 'binaries']);
$app['conf']->set(['main', 'binaries', 'php_binary'], null);
$app->register(new PluginServiceProvider());
$this->assertInstanceOf('Alchemy\Phrasea\Plugin\Management\ComposerInstaller', $app['plugins.composer-installer']);
$app['conf']->set(['main', 'binaries'], $bkp);
}
}

View File

@@ -11,33 +11,33 @@ use Doctrine\Common\Collections\ArrayCollection;
*/
class DisplaySettingServiceTest extends \PhraseanetTestCase
{
private static $userSettings;
private static $appSettings;
private $userSettings = false;
private $appSettings = false;
public function setUp()
{
parent::setUp();
if (null === self::$userSettings) {
self::$userSettings = self::$DI['app']['conf']->get(['user-settings'], []);
}
if (null === self::$appSettings) {
self::$appSettings = self::$DI['app']['conf']->get(['registry'], []);
}
$this->userSettings = self::$DI['app']['conf']->get(['user-settings']);
$this->appSettings = self::$DI['app']['conf']->get(['registry']);
}
public static function tearDownAfterClass()
public function tearDown()
{
if (null !== self::$userSettings) {
self::$DI['app']['conf']->set('user-settings', self::$userSettings);
if (is_null($this->userSettings)) {
self::$DI['app']['conf']->remove('user-settings');
}
else {
self::$DI['app']['conf']->set('user-settings', $this->userSettings);
}
if (null !== self::$appSettings) {
self::$DI['app']['conf']->set('registry', self::$appSettings);
if (is_null($this->appSettings)) {
self::$DI['app']['conf']->remove('registry');
}
else {
self::$DI['app']['conf']->set('registry', $this->appSettings);
}
self::$userSettings = self::$appSettings = null;
parent::tearDownAfterClass();
}

View File

@@ -12,8 +12,22 @@ use Symfony\Component\HttpFoundation\Request;
*/
class DebuggerSubscriberTest extends \PhraseanetTestCase
{
private $bkp = null;
public function setUp()
{
parent::setUp();
$this->bkp = self::$DI['app']['conf']->get('debugger');
}
public function tearDown()
{
if(is_null($this->bkp)) {
self::$DI['app']['conf']->remove('debugger');
}
else {
self::$DI['app']['conf']->set('debugger', $this->bkp);
}
if (is_file(__DIR__ . '/Fixtures/configuration-debugger.php')) {
unlink(__DIR__ . '/Fixtures/configuration-debugger.php');
}

View File

@@ -19,6 +19,9 @@ class SessionManagerSubscriberTest extends \PhraseanetAuthenticatedWebTestCase
{
$app = new Application(Application::ENV_TEST);
$app['dispatcher']->addSubscriber(new SessionManagerSubscriber($app));
$bkp = $app['phraseanet.configuration']['session'];
$app['phraseanet.configuration']['session'] = [
'idle' => 0,
'lifetime' => 60475,
@@ -39,12 +42,17 @@ class SessionManagerSubscriberTest extends \PhraseanetAuthenticatedWebTestCase
$this->assertNotNUll($client->getResponse()->headers->get('x-phraseanet-end-session'));
$this->assertNotNUll($client->getResponse()->headers->get('location'));
$this->assertRegExp('#/login\?redirect=..(?:%2F|/)prod#', $client->getResponse()->headers->get('location'));
$app['phraseanet.configuration']['session'] = $bkp;
}
public function testEndSessionXmlXhttpRequest()
{
$app = new Application(Application::ENV_TEST);
$app['dispatcher']->addSubscriber(new SessionManagerSubscriber($app));
$bkp = $app['phraseanet.configuration']['session'];
$app['phraseanet.configuration']['session'] = [
'idle' => 0,
'lifetime' => 60475,
@@ -67,6 +75,8 @@ class SessionManagerSubscriberTest extends \PhraseanetAuthenticatedWebTestCase
$this->assertTrue($client->getResponse()->isClientError());
$this->assertNotNUll($client->getResponse()->headers->get('x-phraseanet-end-session'));
$app['phraseanet.configuration']['session'] = $bkp;
}
public function testEndSessionAuthenticated()
@@ -85,6 +95,8 @@ class SessionManagerSubscriberTest extends \PhraseanetAuthenticatedWebTestCase
$app['orm.em']->expects($this->exactly(4))->method('persist')->will($this->returnValue(null));
$app['orm.em']->expects($this->exactly(2))->method('flush')->will($this->returnValue(null));
$bkp = $app['phraseanet.configuration']['session'];
$app['phraseanet.configuration']['session'] = [
'idle' => 0,
'lifetime' => 60475,
@@ -101,6 +113,8 @@ class SessionManagerSubscriberTest extends \PhraseanetAuthenticatedWebTestCase
$client->request('GET', '/prod');
$this->assertTrue($client->getResponse()->isOK());
$app['phraseanet.configuration']['session'] = $bkp;
}
public function testEndSessionAuthenticatedWithOutdatedIdle()
@@ -120,6 +134,8 @@ class SessionManagerSubscriberTest extends \PhraseanetAuthenticatedWebTestCase
$app['orm.em']->expects($this->any())->method('persist')->will($this->returnValue(null));
$app['orm.em']->expects($this->any())->method('flush')->will($this->returnValue(null));
$bkp = $app['phraseanet.configuration']['session'];
$app['phraseanet.configuration']['session'] = [
'idle' => 10,
'lifetime' => 60475,
@@ -139,6 +155,8 @@ class SessionManagerSubscriberTest extends \PhraseanetAuthenticatedWebTestCase
$this->assertNotNUll($client->getResponse()->headers->get('x-phraseanet-end-session'));
$this->assertNotNUll($client->getResponse()->headers->get('location'));
$this->assertRegExp('#/login\?redirect=..(?:%2F|/)prod#', $client->getResponse()->headers->get('location'));
$app['phraseanet.configuration']['session'] = $bkp;
}
public function testEndSessionAuthenticatedWithOutdatedIdleXmlHttpRequest()
@@ -158,6 +176,8 @@ class SessionManagerSubscriberTest extends \PhraseanetAuthenticatedWebTestCase
$app['orm.em']->expects($this->any())->method('persist')->will($this->returnValue(null));
$app['orm.em']->expects($this->any())->method('flush')->will($this->returnValue(null));
$bkp = $app['phraseanet.configuration']['session'];
$app['phraseanet.configuration']['session'] = [
'idle' => 10,
'lifetime' => 60475,
@@ -178,6 +198,8 @@ class SessionManagerSubscriberTest extends \PhraseanetAuthenticatedWebTestCase
$this->assertTrue($client->getResponse()->isClientError());
$this->assertNotNUll($client->getResponse()->headers->get('x-phraseanet-end-session'));
$app['phraseanet.configuration']['session'] = $bkp;
}
public function testUndefinedModule()

View File

@@ -95,6 +95,8 @@ class AuthenticationManagerServiceProviderTest extends ServiceProviderTestCase
{
$app = $this->loadApp();
$bkp = $app['conf']->get('authentication');
$app['conf']->set(['authentication', 'captcha', 'trials-before-display'], 42);
//$app['orm.em'] = $this->createEntityManagerMock();
@@ -102,14 +104,21 @@ class AuthenticationManagerServiceProviderTest extends ServiceProviderTestCase
$manager = $app['auth.native.failure-manager'];
$this->assertEquals(42, $manager->getTrials());
$app['conf']->set('authentication', $bkp);
}
public function testFailureAccountCreator()
{
$app = $this->getApplication();
$bkp = $app['conf']->get('authentication');
$app->register(new ConfigurationServiceProvider());
$app['conf']->set(['authentication', 'auto-create'], ['templates' => []]);
$app['authentication.providers.account-creator'];
$app['conf']->set('authentication', $bkp);
}
public function testAuthNativeWithCaptchaEnabled()
@@ -121,6 +130,8 @@ class AuthenticationManagerServiceProviderTest extends ServiceProviderTestCase
$app->register(new RepositoriesServiceProvider());
$app['phraseanet.appbox'] = self::$DI['app']['phraseanet.appbox'];
$bkp = $app['conf']->get('authentication');
$app['conf']->set(['authentication', 'captcha'], ['enabled' => true]);
$app['orm.em'] = $this->createEntityManagerMock();
@@ -131,6 +142,8 @@ class AuthenticationManagerServiceProviderTest extends ServiceProviderTestCase
$app['recaptcha'] = $this->createReCaptchaMock();
$this->assertInstanceOf(FailureHandledNativeAuthentication::class, $app['auth.native']);
$app['conf']->set('authentication', $bkp);
}
public function testAuthNativeWithCaptchaDisabled()
@@ -141,6 +154,8 @@ class AuthenticationManagerServiceProviderTest extends ServiceProviderTestCase
$app->register(new ConfigurationServiceProvider());
$app['phraseanet.appbox'] = self::$DI['app']['phraseanet.appbox'];
$bkp = $app['conf']->get('authentication');
$app['conf']->set(['authentication', 'captcha'], ['enabled' => false]);
$app['orm.em'] = $this->createEntityManagerMock();
@@ -148,6 +163,8 @@ class AuthenticationManagerServiceProviderTest extends ServiceProviderTestCase
$app['recaptcha'] = $this->createReCaptchaMock();
$this->assertInstanceOf(NativeAuthentication::class, $app['auth.native']);
$app['conf']->set('authentication', $bkp);
}
public function testAccountCreator()
@@ -156,6 +173,8 @@ class AuthenticationManagerServiceProviderTest extends ServiceProviderTestCase
$template1 = $user = $app['manipulator.user']->createTemplate('template1', self::$DI['user']);
$template2 = $user = $app['manipulator.user']->createTemplate('template2', self::$DI['user']);
$bkp = $app['conf']->get('authentication');
$app['conf']->set(['authentication', 'auto-create'], ['templates' => [$template1->getId(), $template2->getId()]]);
$this->assertEquals([$template1->getLogin(), $template2->getLogin()], array_map(function (User $user) {
@@ -164,6 +183,8 @@ class AuthenticationManagerServiceProviderTest extends ServiceProviderTestCase
$this->removeUser($app, $template1);
$this->removeUser($app, $template2);
$app['conf']->set('authentication', $bkp);
}
private function createUserRepositoryMock()

View File

@@ -38,10 +38,20 @@ class BorderManagerServiceProviderTest extends ServiceProviderTestCase
$app->register(new PhraseanetServiceProvider());
$app['root.path'] = __DIR__ . '/../../../../../..';
$app->register(new ConfigurationServiceProvider());
$bkp = $app['conf']->get('border-manager');
$app['conf']->set(['border-manager', 'enabled'], false);
$this->assertInstanceOf('Alchemy\Phrasea\Border\Manager', $app['border-manager']);
$this->assertNull($app['phraseanet.metadata-reader']->getPdfToText());
if(is_null($bkp)) {
$app['conf']->remove('border-manager');
}
else {
$app['conf']->set('border-manager', $bkp);
}
}
public function testItLoadsWithXPDF()
@@ -63,9 +73,19 @@ class BorderManagerServiceProviderTest extends ServiceProviderTestCase
$app->register(new BorderManagerServiceProvider());
$app['root.path'] = __DIR__ . '/../../../../../..';
$app->register(new ConfigurationServiceProvider());
$bkp = $app['conf']->get('border-manager');
$app['conf']->set(['border-manager', 'enabled'], false);
$this->assertInstanceOf('Alchemy\Phrasea\Border\Manager', $app['border-manager']);
$this->assertInstanceOf('XPDF\PdfToText', $app['phraseanet.metadata-reader']->getPdfToText());
if(is_null($bkp)) {
$app['conf']->remove('border-manager');
}
else {
$app['conf']->set('border-manager', $bkp);
}
}
}

View File

@@ -27,6 +27,9 @@ class LocaleServiceProviderTest extends \PhraseanetTestCase
$app->register(new LocaleServiceProvider());
$app['root.path'] = __DIR__ . '/../../../../../..';
$app->register(new ConfigurationServiceProvider());
$bkp = $app['conf']->get('languages');
$app['conf']->set(['languages', 'available'], ['fr', 'zh', 'de']);
$original = Application::getAvailableLanguages();
@@ -34,6 +37,8 @@ class LocaleServiceProviderTest extends \PhraseanetTestCase
unset($original['nl']);
$this->assertEquals($original, $app['locales.available']);
$app['conf']->set('languages', $bkp);
}
public function testLocalesCustomizedWithError()
@@ -43,6 +48,8 @@ class LocaleServiceProviderTest extends \PhraseanetTestCase
$app['root.path'] = __DIR__ . '/../../../../../..';
$app->register(new ConfigurationServiceProvider());
$bkp = $app['conf']->get('languages');
$app['conf']->set(['languages', 'available'], ['en_US']);
$app['monolog'] = $this->getMock('Psr\Log\LoggerInterface');
@@ -52,6 +59,8 @@ class LocaleServiceProviderTest extends \PhraseanetTestCase
$original = Application::getAvailableLanguages();
$this->assertEquals($original, $app['locales.available']);
$app['conf']->set('languages', $bkp);
}
public function testLocaleBeforeBoot()

View File

@@ -15,6 +15,25 @@ use Symfony\Component\Process\ExecutableFinder;
*/
class AutoloaderGeneratorTest extends \PhraseanetTestCase
{
private $bkp = null;
public function setUp()
{
parent::setUp();
$this->bkp = self::$DI['app']['conf']->get('plugins');
}
public function tearDown()
{
if(is_null($this->bkp)) {
self::$DI['app']['conf']->remove('plugins');
}
else {
self::$DI['app']['conf']->set('plugins', $this->bkp);
}
parent::tearDown();
}
public function testGeneratedFileAfterInstall()
{
$pluginDir = __DIR__ . '/../Fixtures/PluginDirInstalled/test-plugin';

View File

@@ -47,9 +47,16 @@ class PluginManagerTest extends PluginTestCase
public function testHasPlugin()
{
$prevPlugins = self::$DI['cli']['conf']->get('plugins');
self::$DI['cli']['conf']->set('plugins', []);
self::$DI['cli']['conf']->set(['plugins', 'test-plugin', 'enabled'], true);
$manager = new PluginManager(__DIR__ . '/Fixtures/PluginDirInstalled', self::$DI['cli']['plugins.plugins-validator'], self::$DI['cli']['conf']);
$this->assertTrue($manager->hasPlugin('test-plugin'));
$this->assertFalse($manager->hasPlugin('test-plugin2'));
self::$DI['cli']['conf']->set('plugins', $prevPlugins);
}
private function createValidatorMock()

View File

@@ -20,7 +20,6 @@ class StructureTest extends \PHPUnit_Framework_TestCase
$this->assertEmpty($structure->getAllFields());
$this->assertEmpty($structure->getUnrestrictedFields());
$this->assertEmpty($structure->getPrivateFields());
$this->assertEmpty($structure->getFacetFields());
$this->assertEmpty($structure->getThesaurusEnabledFields());
$this->assertEmpty($structure->getDateFields());
}
@@ -95,19 +94,6 @@ class StructureTest extends \PHPUnit_Framework_TestCase
$this->assertNotContains($unrestricted_field, $private_fields);
}
public function testGetFacetFields()
{
$facet = new Field('foo', FieldMapping::TYPE_STRING, ['facet' => Field::FACET_NO_LIMIT]);
$not_facet = new Field('bar', FieldMapping::TYPE_STRING, ['facet' => Field::FACET_DISABLED]);
$structure = new Structure();
$structure->add($facet);
$this->assertContains($facet, $structure->getFacetFields());
$structure->add($not_facet);
$facet_fields = $structure->getFacetFields();
$this->assertContains($facet, $facet_fields);
$this->assertNotContains($not_facet, $facet_fields);
}
public function testGetDateFields()
{
$string = new Field('foo', FieldMapping::TYPE_STRING);