Merge branch '2.3' into 2.7

* 2.3:
  [SecurityBundle] Removing test insulations for a huge perf win
  [Filesystem] fix tests on 2.3
  [Filesystem] Recursivly widen non-executable directories
This commit is contained in:
Nicolas Grekas 2015-12-22 10:47:32 +01:00
commit b7f998f744
11 changed files with 56 additions and 71 deletions

View File

@ -16,7 +16,6 @@ class AuthenticationCommencingTest extends WebTestCase
public function testAuthenticationIsCommencingIfAccessDeniedExceptionIsWrapped()
{
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => 'config.yml'));
$client->insulate();
$client->request('GET', '/secure-but-not-covered-by-access-control');
$this->assertRedirect($client->getResponse(), '/login');

View File

@ -19,7 +19,6 @@ class CsrfFormLoginTest extends WebTestCase
public function testFormLoginAndLogoutWithCsrfTokens($config)
{
$client = $this->createClient(array('test_case' => 'CsrfFormLogin', 'root_config' => $config));
$client->insulate();
$form = $client->request('GET', '/login')->selectButton('login')->form();
$form['user_login[username]'] = 'johannes';
@ -50,7 +49,6 @@ class CsrfFormLoginTest extends WebTestCase
public function testFormLoginWithInvalidCsrfToken($config)
{
$client = $this->createClient(array('test_case' => 'CsrfFormLogin', 'root_config' => $config));
$client->insulate();
$form = $client->request('GET', '/login')->selectButton('login')->form();
$form['user_login[_token]'] = '';
@ -68,7 +66,6 @@ class CsrfFormLoginTest extends WebTestCase
public function testFormLoginWithCustomTargetPath($config)
{
$client = $this->createClient(array('test_case' => 'CsrfFormLogin', 'root_config' => $config));
$client->insulate();
$form = $client->request('GET', '/login')->selectButton('login')->form();
$form['user_login[username]'] = 'johannes';
@ -89,7 +86,6 @@ class CsrfFormLoginTest extends WebTestCase
public function testFormLoginRedirectsToProtectedResourceAfterLogin($config)
{
$client = $this->createClient(array('test_case' => 'CsrfFormLogin', 'root_config' => $config));
$client->insulate();
$client->request('GET', '/protected-resource');
$this->assertRedirect($client->getResponse(), '/login');
@ -113,17 +109,13 @@ class CsrfFormLoginTest extends WebTestCase
);
}
protected function setUp()
public static function setUpBeforeClass()
{
parent::setUp();
$this->deleteTmpDir('CsrfFormLogin');
parent::deleteTmpDir('CsrfFormLogin');
}
protected function tearDown()
public static function tearDownAfterClass()
{
parent::tearDown();
$this->deleteTmpDir('CsrfFormLogin');
parent::deleteTmpDir('CsrfFormLogin');
}
}

View File

@ -18,7 +18,6 @@ class FirewallEntryPointTest extends WebTestCase
public function testItUsesTheConfiguredEntryPointWhenUsingUnknownCredentials()
{
$client = $this->createClient(array('test_case' => 'FirewallEntryPoint'));
$client->insulate();
$client->request('GET', '/secure/resource', array(), array(), array(
'PHP_AUTH_USER' => 'unknown',
@ -35,7 +34,6 @@ class FirewallEntryPointTest extends WebTestCase
public function testItUsesTheConfiguredEntryPointFromTheExceptionListenerWithFormLoginAndNoCredentials()
{
$client = $this->createClient(array('test_case' => 'FirewallEntryPoint', 'root_config' => 'config_form_login.yml'));
$client->insulate();
$client->request('GET', '/secure/resource');
@ -46,17 +44,13 @@ class FirewallEntryPointTest extends WebTestCase
);
}
protected function setUp()
public static function setUpBeforeClass()
{
parent::setUp();
$this->deleteTmpDir('FirewallEntryPoint');
parent::deleteTmpDir('FirewallEntryPoint');
}
protected function tearDown()
public static function tearDownAfterClass()
{
parent::tearDown();
$this->deleteTmpDir('FirewallEntryPoint');
parent::deleteTmpDir('FirewallEntryPoint');
}
}

View File

@ -19,7 +19,6 @@ class FormLoginTest extends WebTestCase
public function testFormLogin($config)
{
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => $config));
$client->insulate();
$form = $client->request('GET', '/login')->selectButton('login')->form();
$form['_username'] = 'johannes';
@ -39,7 +38,6 @@ class FormLoginTest extends WebTestCase
public function testFormLogout($config)
{
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => $config));
$client->insulate();
$form = $client->request('GET', '/login')->selectButton('login')->form();
$form['_username'] = 'johannes';
@ -73,7 +71,6 @@ class FormLoginTest extends WebTestCase
public function testFormLoginWithCustomTargetPath($config)
{
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => $config));
$client->insulate();
$form = $client->request('GET', '/login')->selectButton('login')->form();
$form['_username'] = 'johannes';
@ -94,7 +91,6 @@ class FormLoginTest extends WebTestCase
public function testFormLoginRedirectsToProtectedResourceAfterLogin($config)
{
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => $config));
$client->insulate();
$client->request('GET', '/protected_resource');
$this->assertRedirect($client->getResponse(), '/login');
@ -118,17 +114,13 @@ class FormLoginTest extends WebTestCase
);
}
protected function setUp()
public static function setUpBeforeClass()
{
parent::setUp();
$this->deleteTmpDir('StandardFormLogin');
parent::deleteTmpDir('StandardFormLogin');
}
protected function tearDown()
public static function tearDownAfterClass()
{
parent::tearDown();
$this->deleteTmpDir('StandardFormLogin');
parent::deleteTmpDir('StandardFormLogin');
}
}

View File

@ -19,7 +19,6 @@ class LocalizedRoutesAsPathTest extends WebTestCase
public function testLoginLogoutProcedure($locale)
{
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => 'localized_routes.yml'));
$client->insulate();
$crawler = $client->request('GET', '/'.$locale.'/login');
$form = $crawler->selectButton('login')->form();
@ -41,7 +40,6 @@ class LocalizedRoutesAsPathTest extends WebTestCase
public function testLoginFailureWithLocalizedFailurePath($locale)
{
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => 'localized_form_failure_handler.yml'));
$client->insulate();
$crawler = $client->request('GET', '/'.$locale.'/login');
$form = $crawler->selectButton('login')->form();
@ -58,7 +56,6 @@ class LocalizedRoutesAsPathTest extends WebTestCase
public function testAccessRestrictedResource($locale)
{
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => 'localized_routes.yml'));
$client->insulate();
$client->request('GET', '/'.$locale.'/secure/');
$this->assertRedirect($client->getResponse(), '/'.$locale.'/login');
@ -70,7 +67,6 @@ class LocalizedRoutesAsPathTest extends WebTestCase
public function testAccessRestrictedResourceWithForward($locale)
{
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => 'localized_routes_with_forward.yml'));
$client->insulate();
$crawler = $client->request('GET', '/'.$locale.'/secure/');
$this->assertCount(1, $crawler->selectButton('login'), (string) $client->getResponse());
@ -81,17 +77,13 @@ class LocalizedRoutesAsPathTest extends WebTestCase
return array(array('en'), array('de'));
}
protected function setUp()
public static function setUpBeforeClass()
{
parent::setUp();
$this->deleteTmpDir('StandardFormLogin');
parent::deleteTmpDir('StandardFormLogin');
}
protected function tearDown()
public static function tearDownAfterClass()
{
parent::tearDown();
$this->deleteTmpDir('StandardFormLogin');
parent::deleteTmpDir('StandardFormLogin');
}
}

View File

@ -19,7 +19,6 @@ class SecurityRoutingIntegrationTest extends WebTestCase
public function testRoutingErrorIsNotExposedForProtectedResourceWhenAnonymous($config)
{
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => $config));
$client->insulate();
$client->request('GET', '/protected_resource');
$this->assertRedirect($client->getResponse(), '/login');
@ -31,7 +30,6 @@ class SecurityRoutingIntegrationTest extends WebTestCase
public function testRoutingErrorIsExposedWhenNotProtected($config)
{
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => $config));
$client->insulate();
$client->request('GET', '/unprotected_resource');
$this->assertEquals(404, $client->getResponse()->getStatusCode(), (string) $client->getResponse());
@ -43,7 +41,6 @@ class SecurityRoutingIntegrationTest extends WebTestCase
public function testRoutingErrorIsNotExposedForProtectedResourceWhenLoggedInWithInsufficientRights($config)
{
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => $config));
$client->insulate();
$form = $client->request('GET', '/login')->selectButton('login')->form();
$form['_username'] = 'johannes';
@ -120,17 +117,13 @@ class SecurityRoutingIntegrationTest extends WebTestCase
return array(array('config.yml'), array('routes_as_path.yml'));
}
protected function setUp()
public static function setUpBeforeClass()
{
parent::setUp();
$this->deleteTmpDir('StandardFormLogin');
parent::deleteTmpDir('StandardFormLogin');
}
protected function tearDown()
public static function tearDownAfterClass()
{
parent::tearDown();
$this->deleteTmpDir('StandardFormLogin');
parent::deleteTmpDir('StandardFormLogin');
}
}

View File

@ -62,7 +62,6 @@ class SwitchUserTest extends WebTestCase
{
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => 'switchuser.yml'));
$client->followRedirects(true);
$client->insulate();
$form = $client->request('GET', '/login')->selectButton('login')->form();
$form['_username'] = $username;
@ -72,17 +71,13 @@ class SwitchUserTest extends WebTestCase
return $client;
}
protected function setUp()
public static function setUpBeforeClass()
{
parent::setUp();
$this->deleteTmpDir('StandardFormLogin');
parent::deleteTmpDir('StandardFormLogin');
}
protected function tearDown()
public static function tearDownAfterClass()
{
parent::tearDown();
$this->deleteTmpDir('StandardFormLogin');
parent::deleteTmpDir('StandardFormLogin');
}
}

View File

@ -23,7 +23,7 @@ class WebTestCase extends BaseWebTestCase
self::assertEquals('http://localhost'.$location, $response->headers->get('Location'));
}
protected function deleteTmpDir($testCase)
protected static function deleteTmpDir($testCase)
{
if (!file_exists($dir = sys_get_temp_dir().'/'.Kernel::VERSION.'/'.$testCase)) {
return;

View File

@ -65,6 +65,18 @@ class AppKernel extends Kernel
parent::__construct($environment, $debug);
}
/**
* {@inheritdoc}
*/
public function getName()
{
if (null === $this->name) {
$this->name = parent::getName().md5($this->rootConfig);
}
return $this->name;
}
public function registerBundles()
{
if (!is_file($filename = $this->getRootDir().'/'.$this->testCase.'/bundles.php')) {

View File

@ -192,12 +192,12 @@ class Filesystem
public function chmod($files, $mode, $umask = 0000, $recursive = false)
{
foreach ($this->toIterator($files) as $file) {
if ($recursive && is_dir($file) && !is_link($file)) {
$this->chmod(new \FilesystemIterator($file), $mode, $umask, true);
}
if (true !== @chmod($file, $mode & ~$umask)) {
throw new IOException(sprintf('Failed to chmod file "%s".', $file), 0, null, $file);
}
if ($recursive && is_dir($file) && !is_link($file)) {
$this->chmod(new \FilesystemIterator($file), $mode, $umask, true);
}
}
}

View File

@ -483,6 +483,22 @@ class FilesystemTest extends FilesystemTestCase
$this->assertFilePermissions(753, $directory);
}
public function testChmodChangesZeroModeOnSubdirectoriesOnRecursive()
{
$this->markAsSkippedIfChmodIsMissing();
$directory = $this->workspace.DIRECTORY_SEPARATOR.'directory';
$subdirectory = $directory.DIRECTORY_SEPARATOR.'subdirectory';
mkdir($directory);
mkdir($subdirectory);
chmod($subdirectory, 0000);
$this->filesystem->chmod($directory, 0753, 0000, true);
$this->assertEquals(753, $this->getFilePermissions($subdirectory));
}
public function testChown()
{
$this->markAsSkippedIfPosixIsMissing();