From fb75651a8179d1812f3508bb6434bf7a9012d770 Mon Sep 17 00:00:00 2001 From: Filippo Tessarotto Date: Wed, 2 Dec 2015 10:12:52 +0100 Subject: [PATCH 1/3] [Filesystem] Recursivly widen non-executable directories --- src/Symfony/Component/Filesystem/Filesystem.php | 6 +++--- .../Filesystem/Tests/FilesystemTest.php | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index 1b6eaa68cd..201d2f7457 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -177,12 +177,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)); } + if ($recursive && is_dir($file) && !is_link($file)) { + $this->chmod(new \FilesystemIterator($file), $mode, $umask, true); + } } } diff --git a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php index b57610cb81..06b99a25cc 100644 --- a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php +++ b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php @@ -479,6 +479,22 @@ class FilesystemTest extends \PHPUnit_Framework_TestCase $this->assertEquals(753, $this->getFilePermissions($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->assertFilePermissions(753, $subdirectory); + } + public function testChown() { $this->markAsSkippedIfPosixIsMissing(); From 9050f676af5f401e0b7468a3645943d95b8a91ff Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sat, 19 Dec 2015 12:10:24 +0100 Subject: [PATCH 2/3] [Filesystem] fix tests on 2.3 The test introduced in #16797 used the `assertFilePermissions()` method to test for the expected result. This worked quite well for the PR as it was submitted for the `master` branch. However, the tests now fail on 2.3 as the `FilesystemTestCase` class which contains this method was introduced with Symfony 2.4. --- src/Symfony/Component/Filesystem/Tests/FilesystemTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php index 06b99a25cc..11f453cc8c 100644 --- a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php +++ b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php @@ -492,7 +492,7 @@ class FilesystemTest extends \PHPUnit_Framework_TestCase $this->filesystem->chmod($directory, 0753, 0000, true); - $this->assertFilePermissions(753, $subdirectory); + $this->assertEquals(753, $this->getFilePermissions($subdirectory)); } public function testChown() From b8fa471f8a7d075b78487b5933bee64cd7ee27c0 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 14 Dec 2015 08:29:40 +0100 Subject: [PATCH 3/3] [SecurityBundle] Removing test insulations for a huge perf win --- .../Functional/AuthenticationCommencingTest.php | 1 - .../Tests/Functional/CsrfFormLoginTest.php | 16 ++++------------ .../Tests/Functional/FirewallEntryPointTest.php | 14 ++++---------- .../Tests/Functional/FormLoginTest.php | 15 ++++----------- .../Functional/LocalizedRoutesAsPathTest.php | 16 ++++------------ .../SecurityRoutingIntegrationTest.php | 15 ++++----------- .../Tests/Functional/SwitchUserTest.php | 13 ++++--------- .../Tests/Functional/WebTestCase.php | 2 +- .../Tests/Functional/app/AppKernel.php | 12 ++++++++++++ 9 files changed, 37 insertions(+), 67 deletions(-) diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/AuthenticationCommencingTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/AuthenticationCommencingTest.php index e94a21e5ba..6ac0e6a3af 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/AuthenticationCommencingTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/AuthenticationCommencingTest.php @@ -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'); diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/CsrfFormLoginTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/CsrfFormLoginTest.php index c2299c9a51..80211f5251 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/CsrfFormLoginTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/CsrfFormLoginTest.php @@ -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'); } } diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/FirewallEntryPointTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/FirewallEntryPointTest.php index aab98f273f..30d0935ffd 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/FirewallEntryPointTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/FirewallEntryPointTest.php @@ -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'); } } diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/FormLoginTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/FormLoginTest.php index 1b8415ad2a..520eee6489 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/FormLoginTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/FormLoginTest.php @@ -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 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'; @@ -60,7 +58,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'); @@ -84,17 +81,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'); } } diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/LocalizedRoutesAsPathTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/LocalizedRoutesAsPathTest.php index 84c79055a9..14c317966e 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/LocalizedRoutesAsPathTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/LocalizedRoutesAsPathTest.php @@ -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'); } } diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityRoutingIntegrationTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityRoutingIntegrationTest.php index 5beec6f927..52a31f5397 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityRoutingIntegrationTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityRoutingIntegrationTest.php @@ -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'); @@ -35,7 +34,6 @@ class SecurityRoutingIntegrationTest extends WebTestCase } $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()); @@ -51,7 +49,6 @@ class SecurityRoutingIntegrationTest extends WebTestCase } $client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => $config)); - $client->insulate(); $form = $client->request('GET', '/login')->selectButton('login')->form(); $form['_username'] = 'johannes'; @@ -106,17 +103,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'); } } diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SwitchUserTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SwitchUserTest.php index f4b3d27f21..e5079c3283 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SwitchUserTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SwitchUserTest.php @@ -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'); } } diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/WebTestCase.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/WebTestCase.php index 731c32073c..33da9028a3 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/WebTestCase.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/WebTestCase.php @@ -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; diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AppKernel.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AppKernel.php index 977be9162c..b828c5acfd 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AppKernel.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AppKernel.php @@ -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')) {