From b352ff08ad2cf40d607ad5b787fb3bb1971a3516 Mon Sep 17 00:00:00 2001 From: Thomas Calvet Date: Thu, 16 Jul 2020 11:17:05 +0200 Subject: [PATCH 1/7] [SCA] Minor fixes on tests --- .../UserPasswordEncoderCommandTest.php | 2 +- .../Tests/Exception/FlattenExceptionTest.php | 8 +++--- .../Tests/ContainerBuilderTest.php | 4 +-- .../Tests/DefinitionTest.php | 4 +-- .../Component/DomCrawler/Tests/FormTest.php | 25 +++++++++++-------- .../ParserCache/ParserCacheAdapterTest.php | 4 +-- .../HttpFoundation/Tests/ResponseTest.php | 8 +++--- .../Handler/MongoDbSessionHandlerTest.php | 2 +- .../Storage/PhpBridgeSessionStorageTest.php | 8 +++--- .../FilterControllerArgumentsEventTest.php | 2 +- .../Profiler/FileProfilerStorageTest.php | 6 ++--- .../Tests/Adapter/ExtLdap/AdapterTest.php | 8 +++--- .../Tests/Adapter/ExtLdap/LdapManagerTest.php | 2 +- .../Process/Tests/PhpExecutableFinderTest.php | 6 ++--- .../Templating/Tests/PhpEngineTest.php | 4 +-- .../Tests/PluralizationRulesTest.php | 4 +-- 16 files changed, 50 insertions(+), 47 deletions(-) diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/UserPasswordEncoderCommandTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/UserPasswordEncoderCommandTest.php index be643c3c34..0e69963922 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/UserPasswordEncoderCommandTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/UserPasswordEncoderCommandTest.php @@ -50,7 +50,7 @@ class UserPasswordEncoderCommandTest extends AbstractWebTestCase ], ['interactive' => false]); $this->assertStringContainsString('[ERROR] The password must not be empty.', $this->passwordEncoderCommandTester->getDisplay()); - $this->assertEquals($statusCode, 1); + $this->assertEquals(1, $statusCode); } public function testEncodePasswordBcrypt() diff --git a/src/Symfony/Component/Debug/Tests/Exception/FlattenExceptionTest.php b/src/Symfony/Component/Debug/Tests/Exception/FlattenExceptionTest.php index 3d163eec77..431edb147b 100644 --- a/src/Symfony/Component/Debug/Tests/Exception/FlattenExceptionTest.php +++ b/src/Symfony/Component/Debug/Tests/Exception/FlattenExceptionTest.php @@ -147,9 +147,9 @@ class FlattenExceptionTest extends TestCase $flattened = FlattenException::create($exception)->getPrevious(); - $this->assertEquals($flattened->getMessage(), 'Parse error: Oh noes!', 'The message is copied from the original exception.'); - $this->assertEquals($flattened->getCode(), 42, 'The code is copied from the original exception.'); - $this->assertEquals($flattened->getClass(), 'Symfony\Component\Debug\Exception\FatalThrowableError', 'The class is set to the class of the original exception'); + $this->assertEquals('Parse error: Oh noes!', $flattened->getMessage(), 'The message is copied from the original exception.'); + $this->assertEquals(42, $flattened->getCode(), 'The code is copied from the original exception.'); + $this->assertEquals('Symfony\Component\Debug\Exception\FatalThrowableError', $flattened->getClass(), 'The class is set to the class of the original exception'); } /** @@ -259,7 +259,7 @@ class FlattenExceptionTest extends TestCase $this->assertSame(['float', INF], $array[$i++]); // assertEquals() does not like NAN values. - $this->assertEquals($array[$i][0], 'float'); + $this->assertEquals('float', $array[$i][0]); $this->assertNan($array[$i][1]); } diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php index 4ccab66339..fd33ce12b6 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php @@ -846,12 +846,12 @@ class ContainerBuilderTest extends TestCase ->addTag('bar', ['bar' => 'bar']) ->addTag('foo', ['foofoo' => 'foofoo']) ; - $this->assertEquals($builder->findTaggedServiceIds('foo'), [ + $this->assertEquals([ 'foo' => [ ['foo' => 'foo'], ['foofoo' => 'foofoo'], ], - ], '->findTaggedServiceIds() returns an array of service ids and its tag attributes'); + ], $builder->findTaggedServiceIds('foo'), '->findTaggedServiceIds() returns an array of service ids and its tag attributes'); $this->assertEquals([], $builder->findTaggedServiceIds('foobar'), '->findTaggedServiceIds() returns an empty array if there is annotated services'); } diff --git a/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php b/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php index 1f1cd380f9..63ca748eb0 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php @@ -224,10 +224,10 @@ class DefinitionTest extends TestCase $def->addTag('foo', ['foo' => 'bar']); $this->assertEquals([[], ['foo' => 'bar']], $def->getTag('foo'), '->addTag() can adds the same tag several times'); $def->addTag('bar', ['bar' => 'bar']); - $this->assertEquals($def->getTags(), [ + $this->assertEquals([ 'foo' => [[], ['foo' => 'bar']], 'bar' => [['bar' => 'bar']], - ], '->getTags() returns all tags'); + ], $def->getTags(), '->getTags() returns all tags'); } public function testSetArgument() diff --git a/src/Symfony/Component/DomCrawler/Tests/FormTest.php b/src/Symfony/Component/DomCrawler/Tests/FormTest.php index f042513f8d..19f704e5fd 100644 --- a/src/Symfony/Component/DomCrawler/Tests/FormTest.php +++ b/src/Symfony/Component/DomCrawler/Tests/FormTest.php @@ -170,25 +170,28 @@ class FormTest extends TestCase '); $this->assertEquals( - array_keys($form->all()), - ['foo[2]', 'foo[3]', 'bar[foo][0]', 'bar[foo][foobar]'] + ['foo[2]', 'foo[3]', 'bar[foo][0]', 'bar[foo][foobar]'], + array_keys($form->all()) ); - $this->assertEquals($form->get('foo[2]')->getValue(), 'foo'); - $this->assertEquals($form->get('foo[3]')->getValue(), 'foo'); - $this->assertEquals($form->get('bar[foo][0]')->getValue(), 'foo'); - $this->assertEquals($form->get('bar[foo][foobar]')->getValue(), 'foo'); + $this->assertEquals('foo', $form->get('foo[2]')->getValue()); + $this->assertEquals('foo', $form->get('foo[3]')->getValue()); + $this->assertEquals('foo', $form->get('bar[foo][0]')->getValue()); + $this->assertEquals('foo', $form->get('bar[foo][foobar]')->getValue()); $form['foo[2]'] = 'bar'; $form['foo[3]'] = 'bar'; - $this->assertEquals($form->get('foo[2]')->getValue(), 'bar'); - $this->assertEquals($form->get('foo[3]')->getValue(), 'bar'); + $this->assertEquals('bar', $form->get('foo[2]')->getValue()); + $this->assertEquals('bar', $form->get('foo[3]')->getValue()); $form['bar'] = ['foo' => ['0' => 'bar', 'foobar' => 'foobar']]; - $this->assertEquals($form->get('bar[foo][0]')->getValue(), 'bar'); - $this->assertEquals($form->get('bar[foo][foobar]')->getValue(), 'foobar'); + $this->assertEquals('bar', $form->get('bar[foo][0]')->getValue()); + $this->assertEquals( + 'foobar', + $form->get('bar[foo][foobar]')->getValue() + ); } /** @@ -967,7 +970,7 @@ class FormTest extends TestCase $nodes = $dom->getElementsByTagName('form'); $form = new Form($nodes->item(0), 'http://example.com'); - $this->assertEquals($form->getPhpValues(), ['example' => '']); + $this->assertEquals(['example' => ''], $form->getPhpValues()); } public function testGetReturnTypes() diff --git a/src/Symfony/Component/ExpressionLanguage/Tests/ParserCache/ParserCacheAdapterTest.php b/src/Symfony/Component/ExpressionLanguage/Tests/ParserCache/ParserCacheAdapterTest.php index 2e9263307f..f82af92e18 100644 --- a/src/Symfony/Component/ExpressionLanguage/Tests/ParserCache/ParserCacheAdapterTest.php +++ b/src/Symfony/Component/ExpressionLanguage/Tests/ParserCache/ParserCacheAdapterTest.php @@ -38,8 +38,8 @@ class ParserCacheAdapterTest extends TestCase $cacheItem = $parserCacheAdapter->getItem($key); - $this->assertEquals($cacheItem->get(), $value); - $this->assertEquals($cacheItem->isHit(), true); + $this->assertEquals($value, $cacheItem->get()); + $this->assertTrue($cacheItem->isHit()); } public function testSave() diff --git a/src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php b/src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php index b846cdad3c..43dfa8a8b3 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php @@ -592,20 +592,20 @@ class ResponseTest extends ResponseTestCase $options = ['etag' => '"whatever"']; $response->setCache($options); - $this->assertEquals($response->getEtag(), '"whatever"'); + $this->assertEquals('"whatever"', $response->getEtag()); $now = $this->createDateTimeNow(); $options = ['last_modified' => $now]; $response->setCache($options); - $this->assertEquals($response->getLastModified()->getTimestamp(), $now->getTimestamp()); + $this->assertEquals($now->getTimestamp(), $response->getLastModified()->getTimestamp()); $options = ['max_age' => 100]; $response->setCache($options); - $this->assertEquals($response->getMaxAge(), 100); + $this->assertEquals(100, $response->getMaxAge()); $options = ['s_maxage' => 200]; $response->setCache($options); - $this->assertEquals($response->getMaxAge(), 200); + $this->assertEquals(200, $response->getMaxAge()); $this->assertTrue($response->headers->hasCacheControlDirective('public')); $this->assertFalse($response->headers->hasCacheControlDirective('private')); diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php index f0f43d05b4..cbfda8e748 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php @@ -102,7 +102,7 @@ class MongoDbSessionHandlerTest extends TestCase ->method('findOne') ->willReturnCallback(function ($criteria) use ($testTimeout) { $this->assertArrayHasKey($this->options['id_field'], $criteria); - $this->assertEquals($criteria[$this->options['id_field']], 'foo'); + $this->assertEquals('foo', $criteria[$this->options['id_field']]); $this->assertArrayHasKey($this->options['expiry_field'], $criteria); $this->assertArrayHasKey('$gte', $criteria[$this->options['expiry_field']]); diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/PhpBridgeSessionStorageTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/PhpBridgeSessionStorageTest.php index 752be618bc..700764840d 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/PhpBridgeSessionStorageTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/PhpBridgeSessionStorageTest.php @@ -87,10 +87,10 @@ class PhpBridgeSessionStorageTest extends TestCase $_SESSION['drak'] = 'loves symfony'; $storage->getBag('attributes')->set('symfony', 'greatness'); $key = $storage->getBag('attributes')->getStorageKey(); - $this->assertEquals($_SESSION[$key], ['symfony' => 'greatness']); - $this->assertEquals($_SESSION['drak'], 'loves symfony'); + $this->assertEquals(['symfony' => 'greatness'], $_SESSION[$key]); + $this->assertEquals('loves symfony', $_SESSION['drak']); $storage->clear(); - $this->assertEquals($_SESSION[$key], []); - $this->assertEquals($_SESSION['drak'], 'loves symfony'); + $this->assertEquals([], $_SESSION[$key]); + $this->assertEquals('loves symfony', $_SESSION['drak']); } } diff --git a/src/Symfony/Component/HttpKernel/Tests/Event/FilterControllerArgumentsEventTest.php b/src/Symfony/Component/HttpKernel/Tests/Event/FilterControllerArgumentsEventTest.php index abc51ac51e..53962347d0 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Event/FilterControllerArgumentsEventTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Event/FilterControllerArgumentsEventTest.php @@ -12,6 +12,6 @@ class FilterControllerArgumentsEventTest extends TestCase public function testFilterControllerArgumentsEvent() { $filterController = new FilterControllerArgumentsEvent(new TestHttpKernel(), function () {}, ['test'], new Request(), 1); - $this->assertEquals($filterController->getArguments(), ['test']); + $this->assertEquals(['test'], $filterController->getArguments()); } } diff --git a/src/Symfony/Component/HttpKernel/Tests/Profiler/FileProfilerStorageTest.php b/src/Symfony/Component/HttpKernel/Tests/Profiler/FileProfilerStorageTest.php index 1cc05e41ec..7100659c4d 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Profiler/FileProfilerStorageTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Profiler/FileProfilerStorageTest.php @@ -205,9 +205,9 @@ class FileProfilerStorageTest extends TestCase $records = $this->storage->find('', '', 3, 'GET', $start, time() + 3 * 60); $this->assertCount(3, $records, '->find() returns all previously added records'); - $this->assertEquals($records[0]['token'], 'time_2', '->find() returns records ordered by time in descendant order'); - $this->assertEquals($records[1]['token'], 'time_1', '->find() returns records ordered by time in descendant order'); - $this->assertEquals($records[2]['token'], 'time_0', '->find() returns records ordered by time in descendant order'); + $this->assertEquals('time_2', $records[0]['token'], '->find() returns records ordered by time in descendant order'); + $this->assertEquals('time_1', $records[1]['token'], '->find() returns records ordered by time in descendant order'); + $this->assertEquals('time_0', $records[2]['token'], '->find() returns records ordered by time in descendant order'); $records = $this->storage->find('', '', 3, 'GET', $start, time() + 2 * 60); $this->assertCount(2, $records, '->find() should return only first two of the previously added records'); diff --git a/src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/AdapterTest.php b/src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/AdapterTest.php index 4a4fcfb0ad..ed7fdecc40 100644 --- a/src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/AdapterTest.php +++ b/src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/AdapterTest.php @@ -87,12 +87,12 @@ class AdapterTest extends LdapTestCase $ldap->getConnection()->bind('cn=admin,dc=symfony,dc=com', 'symfony'); $query = $ldap->createQuery('cn=Fabien Potencier,dc=symfony,dc=com', '(objectclass=*)', [ - 'scope' => Query::SCOPE_BASE, + 'scope' => Query::SCOPE_BASE, ]); $result = $query->execute(); $entry = $result[0]; - $this->assertEquals($result->count(), 1); + $this->assertEquals(1, $result->count()); $this->assertEquals(['Fabien Potencier'], $entry->getAttribute('cn')); } @@ -109,7 +109,7 @@ class AdapterTest extends LdapTestCase $subtree_count = $ldap->createQuery('ou=Components,dc=symfony,dc=com', '(objectclass=*)')->execute()->count(); $this->assertNotEquals($one_level_result->count(), $subtree_count); - $this->assertEquals($one_level_result->count(), 1); - $this->assertEquals($one_level_result[0]->getAttribute('ou'), ['Ldap']); + $this->assertEquals(1, $one_level_result->count()); + $this->assertEquals(['Ldap'], $one_level_result[0]->getAttribute('ou')); } } diff --git a/src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/LdapManagerTest.php b/src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/LdapManagerTest.php index 48719a46b4..07b8a92a11 100644 --- a/src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/LdapManagerTest.php +++ b/src/Symfony/Component/Ldap/Tests/Adapter/ExtLdap/LdapManagerTest.php @@ -163,7 +163,7 @@ class LdapManagerTest extends LdapTestCase $result = $this->executeSearchQuery(1); $renamedEntry = $result[0]; - $this->assertEquals($renamedEntry->getAttribute('cn')[0], 'Kevin'); + $this->assertEquals('Kevin', $renamedEntry->getAttribute('cn')[0]); $oldRdn = $entry->getAttribute('cn')[0]; $entryManager->rename($renamedEntry, 'cn='.$oldRdn); diff --git a/src/Symfony/Component/Process/Tests/PhpExecutableFinderTest.php b/src/Symfony/Component/Process/Tests/PhpExecutableFinderTest.php index 795be8fa24..bf4d81a41b 100644 --- a/src/Symfony/Component/Process/Tests/PhpExecutableFinderTest.php +++ b/src/Symfony/Component/Process/Tests/PhpExecutableFinderTest.php @@ -62,11 +62,11 @@ class PhpExecutableFinderTest extends TestCase $f = new PhpExecutableFinder(); if (\defined('HHVM_VERSION')) { - $this->assertEquals($f->findArguments(), ['--php'], '::findArguments() returns HHVM arguments'); + $this->assertEquals(['--php'], $f->findArguments(), '::findArguments() returns HHVM arguments'); } elseif ('phpdbg' === \PHP_SAPI) { - $this->assertEquals($f->findArguments(), ['-qrr'], '::findArguments() returns phpdbg arguments'); + $this->assertEquals(['-qrr'], $f->findArguments(), '::findArguments() returns phpdbg arguments'); } else { - $this->assertEquals($f->findArguments(), [], '::findArguments() returns no arguments'); + $this->assertEquals([], $f->findArguments(), '::findArguments() returns no arguments'); } } } diff --git a/src/Symfony/Component/Templating/Tests/PhpEngineTest.php b/src/Symfony/Component/Templating/Tests/PhpEngineTest.php index 5f43cb5f24..e99ccf4d14 100644 --- a/src/Symfony/Component/Templating/Tests/PhpEngineTest.php +++ b/src/Symfony/Component/Templating/Tests/PhpEngineTest.php @@ -179,9 +179,9 @@ class PhpEngineTest extends TestCase $this->loader->setTemplate('global.php', ''); - $this->assertEquals($engine->render('global.php'), 'global variable'); + $this->assertEquals('global variable', $engine->render('global.php')); - $this->assertEquals($engine->render('global.php', ['global' => 'overwritten']), 'overwritten'); + $this->assertEquals('overwritten', $engine->render('global.php', ['global' => 'overwritten'])); } public function testGetLoader() diff --git a/src/Symfony/Component/Translation/Tests/PluralizationRulesTest.php b/src/Symfony/Component/Translation/Tests/PluralizationRulesTest.php index 287764327a..d93fab804e 100644 --- a/src/Symfony/Component/Translation/Tests/PluralizationRulesTest.php +++ b/src/Symfony/Component/Translation/Tests/PluralizationRulesTest.php @@ -100,9 +100,9 @@ class PluralizationRulesTest extends TestCase foreach ($matrix as $langCode => $data) { $indexes = array_flip($data); if ($expectSuccess) { - $this->assertEquals($nplural, \count($indexes), "Langcode '$langCode' has '$nplural' plural forms."); + $this->assertCount((int) $nplural, $indexes, "Langcode '$langCode' has '$nplural' plural forms."); } else { - $this->assertNotEquals((int) $nplural, \count($indexes), "Langcode '$langCode' has '$nplural' plural forms."); + $this->assertNotCount((int) $nplural, $indexes, "Langcode '$langCode' has '$nplural' plural forms."); } } } From 2bb3f08fba5617527e4ea2da476d58f708e009bc Mon Sep 17 00:00:00 2001 From: Colin O'Dell Date: Sun, 19 Jul 2020 09:57:33 -0400 Subject: [PATCH 2/7] Fix checks for phpunit releases on Composer 2 (resolves #37601) --- src/Symfony/Bridge/PhpUnit/bin/simple-phpunit | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit b/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit index 27ea603711..7b5e3b1675 100755 --- a/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit +++ b/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit @@ -117,7 +117,11 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__ 'requires' => array('php' => '*'), ); - if (1 === count($info['versions'])) { + $stableVersions = array_filter($info['versions'], function($v) { + return !preg_match('/-dev$|^dev-/', $v); + }); + + if (!$stableVersions) { $passthruOrFail("$COMPOSER create-project --ignore-platform-reqs --no-install --prefer-dist --no-scripts --no-plugins --no-progress -s dev phpunit/phpunit phpunit-$PHPUNIT_VERSION \"$PHPUNIT_VERSION.*\""); } else { $passthruOrFail("$COMPOSER create-project --ignore-platform-reqs --no-install --prefer-dist --no-scripts --no-plugins --no-progress phpunit/phpunit phpunit-$PHPUNIT_VERSION \"$PHPUNIT_VERSION.*\""); From 6a7685f3153cffc44dfecd3e4f1b9a292ac5b7d2 Mon Sep 17 00:00:00 2001 From: shreypuranik Date: Wed, 15 Jul 2020 17:19:14 +0100 Subject: [PATCH 3/7] Readability update --- .../Csp/ContentSecurityPolicyHandler.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Csp/ContentSecurityPolicyHandler.php b/src/Symfony/Bundle/WebProfilerBundle/Csp/ContentSecurityPolicyHandler.php index f75d29aea7..d27db85c9c 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Csp/ContentSecurityPolicyHandler.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Csp/ContentSecurityPolicyHandler.php @@ -127,8 +127,15 @@ class ContentSecurityPolicyHandler $headers = $this->getCspHeaders($response); + $types = [ + 'script-src' => 'csp_script_nonce', + 'script-src-elem' => 'csp_script_nonce', + 'style-src' => 'csp_style_nonce', + 'style-src-elem' => 'csp_style_nonce' + ]; + foreach ($headers as $header => $directives) { - foreach (['script-src' => 'csp_script_nonce', 'script-src-elem' => 'csp_script_nonce', 'style-src' => 'csp_style_nonce', 'style-src-elem' => 'csp_style_nonce'] as $type => $tokenName) { + foreach ($types as $type => $tokenName) { if ($this->authorizesInline($directives, $type)) { continue; } From 87a51353062621e28011ba27dd1a97ccd6ae9dba Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 23 Jul 2020 08:37:54 +0200 Subject: [PATCH 4/7] Fix CS --- .../WebProfilerBundle/Csp/ContentSecurityPolicyHandler.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Csp/ContentSecurityPolicyHandler.php b/src/Symfony/Bundle/WebProfilerBundle/Csp/ContentSecurityPolicyHandler.php index d27db85c9c..1742b32d12 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Csp/ContentSecurityPolicyHandler.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Csp/ContentSecurityPolicyHandler.php @@ -128,10 +128,10 @@ class ContentSecurityPolicyHandler $headers = $this->getCspHeaders($response); $types = [ - 'script-src' => 'csp_script_nonce', + 'script-src' => 'csp_script_nonce', 'script-src-elem' => 'csp_script_nonce', - 'style-src' => 'csp_style_nonce', - 'style-src-elem' => 'csp_style_nonce' + 'style-src' => 'csp_style_nonce', + 'style-src-elem' => 'csp_style_nonce', ]; foreach ($headers as $header => $directives) { From 46c8c3791b45ed595d6db3f0bee5de49b32b9771 Mon Sep 17 00:00:00 2001 From: Youssef BENHSSAIEN Date: Tue, 14 Jul 2020 10:49:26 +0200 Subject: [PATCH 5/7] [FrameworkBundle] set default session.handler alias if handler_id is not provided --- .../FrameworkBundle/DependencyInjection/FrameworkExtension.php | 1 + .../Tests/DependencyInjection/FrameworkExtensionTest.php | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 09d06e4145..6c2bd1e112 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -880,6 +880,7 @@ class FrameworkExtension extends Extension // Set the handler class to be null $container->getDefinition('session.storage.native')->replaceArgument(1, null); $container->getDefinition('session.storage.php_bridge')->replaceArgument(0, null); + $container->setAlias('session.handler', 'session.handler.native_file')->setPrivate(true); } else { $container->setAlias('session.handler', $config['handler_id'])->setPrivate(true); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index bdbb8ba402..2a9ab26696 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -463,6 +463,7 @@ abstract class FrameworkExtensionTest extends TestCase $this->assertTrue($container->hasDefinition('session'), '->registerSessionConfiguration() loads session.xml'); $this->assertNull($container->getDefinition('session.storage.native')->getArgument(1)); $this->assertNull($container->getDefinition('session.storage.php_bridge')->getArgument(0)); + $this->assertEquals('session.handler.native_file', (string) $container->getAlias('session.handler')); } public function testRequest() From e5543dc72dcb990c83614deaf5b01f3365fd008d Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 23 Jul 2020 08:46:18 +0200 Subject: [PATCH 6/7] Fix CS --- .../Tests/DependencyInjection/FrameworkExtensionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 2a9ab26696..2ecd0bad3e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -463,7 +463,7 @@ abstract class FrameworkExtensionTest extends TestCase $this->assertTrue($container->hasDefinition('session'), '->registerSessionConfiguration() loads session.xml'); $this->assertNull($container->getDefinition('session.storage.native')->getArgument(1)); $this->assertNull($container->getDefinition('session.storage.php_bridge')->getArgument(0)); - $this->assertEquals('session.handler.native_file', (string) $container->getAlias('session.handler')); + $this->assertSame('session.handler.native_file', (string) $container->getAlias('session.handler')); } public function testRequest() From ee6b5145bfe1bb83733c29f50dc1d3c38eba6dac Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 23 Jul 2020 10:10:45 +0200 Subject: [PATCH 7/7] [Cache] fix catching auth errors --- .../Component/Cache/Traits/RedisTrait.php | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Symfony/Component/Cache/Traits/RedisTrait.php b/src/Symfony/Component/Cache/Traits/RedisTrait.php index 08aea83e78..a30d6d3fa5 100644 --- a/src/Symfony/Component/Cache/Traits/RedisTrait.php +++ b/src/Symfony/Component/Cache/Traits/RedisTrait.php @@ -119,26 +119,26 @@ trait RedisTrait $initializer = function ($redis) use ($connect, $params, $dsn, $auth) { try { @$redis->{$connect}($params['host'], $params['port'], $params['timeout'], $params['persistent_id'], $params['retry_interval']); + + set_error_handler(function ($type, $msg) use (&$error) { $error = $msg; }); + $isConnected = $redis->isConnected(); + restore_error_handler(); + if (!$isConnected) { + $error = preg_match('/^Redis::p?connect\(\): (.*)/', $error, $error) ? sprintf(' (%s)', $error[1]) : ''; + throw new InvalidArgumentException(sprintf('Redis connection "%s" failed: ', $dsn).$error.'.'); + } + + if ((null !== $auth && !$redis->auth($auth)) + || ($params['dbindex'] && !$redis->select($params['dbindex'])) + || ($params['read_timeout'] && !$redis->setOption(\Redis::OPT_READ_TIMEOUT, $params['read_timeout'])) + ) { + $e = preg_replace('/^ERR /', '', $redis->getLastError()); + throw new InvalidArgumentException(sprintf('Redis connection "%s" failed: ', $dsn).$e.'.'); + } } catch (\RedisException $e) { throw new InvalidArgumentException(sprintf('Redis connection "%s" failed: ', $dsn).$e->getMessage()); } - set_error_handler(function ($type, $msg) use (&$error) { $error = $msg; }); - $isConnected = $redis->isConnected(); - restore_error_handler(); - if (!$isConnected) { - $error = preg_match('/^Redis::p?connect\(\): (.*)/', $error, $error) ? sprintf(' (%s)', $error[1]) : ''; - throw new InvalidArgumentException(sprintf('Redis connection "%s" failed: ', $dsn).$error.'.'); - } - - if ((null !== $auth && !$redis->auth($auth)) - || ($params['dbindex'] && !$redis->select($params['dbindex'])) - || ($params['read_timeout'] && !$redis->setOption(\Redis::OPT_READ_TIMEOUT, $params['read_timeout'])) - ) { - $e = preg_replace('/^ERR /', '', $redis->getLastError()); - throw new InvalidArgumentException(sprintf('Redis connection "%s" failed: ', $dsn).$e.'.'); - } - return true; };