mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-23 18:03:17 +00:00
Add better maintenance handling
This commit is contained in:
@@ -302,6 +302,32 @@ class ApplicationTest extends \PhraseanetPHPUnitAbstract
|
||||
$this->assertEquals('cat.turbocat.com', $app['url_generator']->getContext()->getHost());
|
||||
}
|
||||
|
||||
public function testMaintenanceModeTriggers503s()
|
||||
{
|
||||
$app = new Application('test');
|
||||
|
||||
$app['phraseanet.configuration.config-path'] = __DIR__ . '/Core/Event/Subscriber/Fixtures/configuration-maintenance.yml';
|
||||
$app['phraseanet.configuration.config-compiled-path'] = __DIR__ . '/Core/Event/Subscriber/Fixtures/configuration-maintenance.php';
|
||||
|
||||
if (is_file($app['phraseanet.configuration.config-compiled-path'])) {
|
||||
unlink($app['phraseanet.configuration.config-compiled-path']);
|
||||
}
|
||||
|
||||
$app->get('/', function(Application $app, Request $request) {
|
||||
return 'Hello';
|
||||
});
|
||||
|
||||
$client = new Client($app);
|
||||
$client->request('GET', '/');
|
||||
|
||||
$this->assertEquals(503, $client->getResponse()->getStatusCode());
|
||||
$this->assertNotEquals('Hello', $client->getResponse()->getContent());
|
||||
|
||||
if (is_file($app['phraseanet.configuration.config-compiled-path'])) {
|
||||
unlink($app['phraseanet.configuration.config-compiled-path']);
|
||||
}
|
||||
}
|
||||
|
||||
private function getAppThatReturnLocale()
|
||||
{
|
||||
$app = new Application('test');
|
||||
|
@@ -1287,44 +1287,6 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
self::$DI['user']->set_mail_locked(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Alchemy\Phrasea\Controller\Root\Login::authenticate
|
||||
*/
|
||||
public function testAuthenticateUnavailable()
|
||||
{
|
||||
self::$DI['app']['authentication']->closeAccount();
|
||||
$password = \random::generatePassword();
|
||||
self::$DI['app']['phraseanet.registry']->set('GV_maintenance', true , \registry::TYPE_BOOLEAN);
|
||||
|
||||
self::$DI['client'] = new Client(self::$DI['app'], array());
|
||||
|
||||
self::$DI['client']->request('POST', '/login/authenticate/', array(
|
||||
'login' => self::$DI['user']->get_login(),
|
||||
'password' => $password,
|
||||
'_token' => 'token'
|
||||
));
|
||||
self::$DI['app']['phraseanet.registry']->set('GV_maintenance', false, \registry::TYPE_BOOLEAN);
|
||||
$this->assertTrue(self::$DI['client']->getResponse()->isRedirect());
|
||||
$this->assertFlashMessagePopulated(self::$DI['app'], 'warning', 1);
|
||||
$this->assertFalse(self::$DI['app']['authentication']->isAuthenticated());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Alchemy\Phrasea\Controller\Root\Login::authenticate
|
||||
*/
|
||||
public function testMaintenanceOnLoginDoesNotRedirect()
|
||||
{
|
||||
self::$DI['app']['authentication']->closeAccount();
|
||||
self::$DI['app']['phraseanet.registry']->set('GV_maintenance', true , \registry::TYPE_BOOLEAN);
|
||||
|
||||
self::$DI['client'] = new Client(self::$DI['app'], array());
|
||||
|
||||
self::$DI['client']->request('GET', '/login/');
|
||||
self::$DI['app']['phraseanet.registry']->set('GV_maintenance', false, \registry::TYPE_BOOLEAN);
|
||||
$this->assertFalse(self::$DI['client']->getResponse()->isRedirect());
|
||||
}
|
||||
|
||||
public function testAuthenticateWithProvider()
|
||||
{
|
||||
$provider = $this->getMock('Alchemy\Phrasea\Authentication\Provider\ProviderInterface');
|
||||
|
@@ -0,0 +1,141 @@
|
||||
main:
|
||||
servername: 'http://local.phrasea/'
|
||||
maintenance: true
|
||||
database:
|
||||
host: sql-host
|
||||
port: '3306'
|
||||
user: sql-user
|
||||
password: sql-password
|
||||
dbname: ab_phraseanet
|
||||
driver: pdo_mysql
|
||||
charset: UTF8
|
||||
database-test:
|
||||
driver: pdo_sqlite
|
||||
path: /tmp/db.sqlite
|
||||
charset: UTF8
|
||||
api-timers: true
|
||||
cache:
|
||||
type: MemcacheCache
|
||||
options:
|
||||
host: localhost
|
||||
port: 11211
|
||||
opcodecache:
|
||||
type: ArrayCache
|
||||
options: { }
|
||||
search-engine:
|
||||
type: Alchemy\Phrasea\SearchEngine\Phrasea\PhraseaEngine
|
||||
options: { }
|
||||
task-manager:
|
||||
options: ''
|
||||
trusted-proxies: { }
|
||||
debugger:
|
||||
allowed-ips: { }
|
||||
binaries: { }
|
||||
border-manager:
|
||||
enabled: true
|
||||
checkers:
|
||||
-
|
||||
type: Checker\Sha256
|
||||
enabled: true
|
||||
-
|
||||
type: Checker\UUID
|
||||
enabled: true
|
||||
-
|
||||
type: Checker\Colorspace
|
||||
enabled: false
|
||||
options:
|
||||
colorspaces:
|
||||
- cmyk
|
||||
- grayscale
|
||||
- rgb
|
||||
-
|
||||
type: Checker\Dimension
|
||||
enabled: false
|
||||
options:
|
||||
width: 80
|
||||
height: 160
|
||||
-
|
||||
type: Checker\Extension
|
||||
enabled: false
|
||||
options:
|
||||
extensions:
|
||||
- jpg
|
||||
- jpeg
|
||||
- bmp
|
||||
- tif
|
||||
- gif
|
||||
- png
|
||||
- pdf
|
||||
- doc
|
||||
- odt
|
||||
- mpg
|
||||
- mpeg
|
||||
- mov
|
||||
- avi
|
||||
- xls
|
||||
- flv
|
||||
- mp3
|
||||
- mp2
|
||||
-
|
||||
type: Checker\Filename
|
||||
enabled: false
|
||||
options:
|
||||
sensitive: true
|
||||
-
|
||||
type: Checker\MediaType
|
||||
enabled: false
|
||||
options:
|
||||
mediatypes:
|
||||
- Audio
|
||||
- Document
|
||||
- Flash
|
||||
- Image
|
||||
- Video
|
||||
authentication:
|
||||
auto-create:
|
||||
enabled: false
|
||||
templates: { }
|
||||
captcha:
|
||||
enabled: true
|
||||
trials-before-failure: 9
|
||||
providers:
|
||||
facebook:
|
||||
enabled: false
|
||||
options:
|
||||
app-id: ''
|
||||
secret: ''
|
||||
twitter:
|
||||
enabled: false
|
||||
options:
|
||||
consumer-key: ''
|
||||
consumer-secret: ''
|
||||
google-plus:
|
||||
enabled: false
|
||||
options:
|
||||
client-id: ''
|
||||
client-secret: ''
|
||||
github:
|
||||
enabled: false
|
||||
options:
|
||||
client-id: ''
|
||||
client-secret: ''
|
||||
viadeo:
|
||||
enabled: false
|
||||
options:
|
||||
client-id: ''
|
||||
client-secret: ''
|
||||
linkedin:
|
||||
enabled: false
|
||||
options:
|
||||
client-id: ''
|
||||
client-secret: ''
|
||||
registration-fields:
|
||||
-
|
||||
name: company
|
||||
required: true
|
||||
-
|
||||
name: firstname
|
||||
required: true
|
||||
-
|
||||
name: geonameid
|
||||
required: true
|
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Tests\Phrasea\Core\Event\Subscriber;
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Core\Event\Subscriber\MaintenanceSubscriber;
|
||||
use Symfony\Component\HttpKernel\Client;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
class MaintenanceSubscriberTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function tearDown()
|
||||
{
|
||||
if (is_file(__DIR__ . '/Fixtures/configuration-maintenance.php')) {
|
||||
unlink(__DIR__ . '/Fixtures/configuration-maintenance.php');
|
||||
}
|
||||
}
|
||||
|
||||
public function testCheckNegative()
|
||||
{
|
||||
$app = new Application();
|
||||
unset($app['exception_handler']);
|
||||
$app['dispatcher']->addSubscriber(new MaintenanceSubscriber($app));
|
||||
$app->get('/', function () {
|
||||
return 'Hello';
|
||||
});
|
||||
|
||||
$client = new Client($app);
|
||||
$client->request('GET', '/');
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode());
|
||||
$this->assertEquals('Hello', $client->getResponse()->getContent());
|
||||
}
|
||||
|
||||
public function testCheckPositive()
|
||||
{
|
||||
$app = new Application();
|
||||
|
||||
$app['phraseanet.configuration.config-path'] = __DIR__ . '/Fixtures/configuration-maintenance.yml';
|
||||
$app['phraseanet.configuration.config-compiled-path'] = __DIR__ . '/Fixtures/configuration-maintenance.php';
|
||||
|
||||
if (is_file($app['phraseanet.configuration.config-compiled-path'])) {
|
||||
unlink($app['phraseanet.configuration.config-compiled-path']);
|
||||
}
|
||||
|
||||
unset($app['exception_handler']);
|
||||
$app['dispatcher']->addSubscriber(new MaintenanceSubscriber($app));
|
||||
$app->get('/', function () {
|
||||
return 'Hello';
|
||||
});
|
||||
|
||||
$client = new Client($app);
|
||||
try {
|
||||
$client->request('GET', '/');
|
||||
$this->fail('An exception should have been raised');
|
||||
} catch (HttpException $e) {
|
||||
$this->assertEquals(503, $e->getStatusCode());
|
||||
$this->assertEquals(array('Retry-After' => 3600), $e->getHeaders());
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user