8000 Merge branch '5.4' into 6.0 · symfony/symfony@8033481 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8033481

Browse files
Merge branch '5.4' into 6.0
* 5.4: [HttpKernel] Fix test sensitivity on xdebug.file_link_format [HttpKernel] Fix non-scalar check in surrogate fragment renderer [Debug][ErrorHandler] fix operator precedence [Cache] Ensured that redis adapter can use multiple redis sentinel hosts [DoctrineBridge] fix tests [Security] Allow redirect after login to absolute URLs
2 parents e354ac5 + 506e4fc commit 8033481

File tree

20 files changed

+77
-53
lines changed

20 files changed

+77
-53
lines changed

.github/workflows/integration-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ jobs:
171171
env:
172172
REDIS_HOST: 'localhost:16379'
173173
REDIS_CLUSTER_HOSTS: 'localhost:7000 localhost:7001 localhost:7002 localhost:7003 localhost:7004 localhost:7005'
174-
REDIS_SENTINEL_HOSTS: 'localhost:26379'
174+
REDIS_SENTINEL_HOSTS: 'localhost:26379 localhost:26379 localhost:26379'
175175
REDIS_SENTINEL_SERVICE: redis_sentinel
176176
MESSENGER_REDIS_DSN: redis://127.0.0.1:7006/messages
177177
MESSENGER_AMQP_DSN: amqp://localhost/%2f/messages

src/Symfony/Bridge/Doctrine/Tests/IdGenerator/EntityManager.php

Lines changed: 0 additions & 21 deletions
Th F438 is file was deleted.

src/Symfony/Bridge/Doctrine/Tests/IdGenerator/UlidGeneratorTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bridge\Doctrine\Tests\IdGenerator;
1313

14+
use Doctrine\ORM\EntityManager;
1415
use Doctrine\ORM\Mapping\Entity;
1516
use PHPUnit\Framework\TestCase;
1617
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
@@ -21,7 +22,7 @@ class UlidGeneratorTest extends TestCase
2122
{
2223
public function testUlidCanBeGenerated()
2324
{
24-
$em = new EntityManager();
25+
$em = (new \ReflectionClass(EntityManager::class))->newInstanceWithoutConstructor();
2526
$generator = new UlidGenerator();
2627
$ulid = $generator->generate($em, new Entity());
2728

@@ -32,7 +33,7 @@ public function testUlidCanBeGenerated()
3233
public function testUlidFactory()
3334
{
3435
$ulid = new Ulid('00000000000000000000000000');
35-
$em = new EntityManager();
36+
$em = (new \ReflectionClass(EntityManager::class))->newInstanceWithoutConstructor();
3637
$factory = $this->createMock(UlidFactory::class);
3738
$factory->expects($this->any())
3839
->method('create')

src/Symfony/Bridge/Doctrine/Tests/IdGenerator/UuidGeneratorTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bridge\Doctrine\Tests\IdGenerator;
1313

14+
use Doctrine\ORM\EntityManager;
1415
use PHPUnit\Framework\TestCase;
1516
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
1617
use Symfony\Component\Uid\Factory\UuidFactory;
@@ -22,7 +23,7 @@ class UuidGeneratorTest extends TestCase
2223
{
2324
public function testUuidCanBeGenerated()
2425
{
25-
$em = new EntityManager();
26+
$em = (new \ReflectionClass(EntityManager::class))->newInstanceWithoutConstructor();
2627
$generator = new UuidGenerator();
2728
$uuid = $generator->generate($em, new Entity());
2829

@@ -32,7 +33,7 @@ public function testUuidCanBeGenerated()
3233
public function testCustomUuidfactory()
3334
{
3435
$uuid = new UuidV4();
35-
$em = new EntityManager();
36+
$em = (new \ReflectionClass(EntityManager::class))->newInstanceWithoutConstructor();
3637
$factory = $this->createMock(UuidFactory::class);
3738
$factory->expects($this->any())
3839
->method('create')
@@ -44,7 +45,7 @@ public function testCustomUuidfactory()
4445

4546
public function testUuidfactory()
4647
{
47-
$em = new EntityManager();
48+
$em = (new \ReflectionClass(EntityManager::class))->newInstanceWithoutConstructor();
4849
$generator = new UuidGenerator();
4950
$this->assertInstanceOf(UuidV6::class, $generator->generate($em, new Entity()));
5051

src/Symfony/Component/Cache/Tests/Adapter/RedisAdapterSentinelTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ public function testInvalidDSNHasBothClusterAndSentinel()
4747
public function testExceptionMessageWhenFailingToRetrieveMasterInformation()
4848
{
4949
$hosts = getenv('REDIS_SENTINEL_HOSTS');
50-
$firstHost = explode(' ', $hosts)[0];
50+
$dsn = 'redis:?host['.str_replace(' ', ']&host[', $hosts).']';
5151
$this->expectException(\Symfony\Component\Cache\Exception\InvalidArgumentException::class);
52-
$this->expectExceptionMessage('Failed to retrieve master information from master name "invalid-masterset-name" and address "'.$firstHost.'".');
53-
AbstractAdapter::createConnection('redis:?host['.str_replace(' ', ']&host[', $hosts).']', ['redis_sentinel' => 'invalid-masterset-name']);
52+
$this->expectExceptionMessage('Failed to retrieve master information from sentinel "invalid-masterset-name" and dsn "'.$dsn.'".');
53+
AbstractAdapter::createConnection($dsn, ['redis_sentinel' => 'invalid-masterset-name']);
5454
}
5555
}

src/Symfony/Component/Cache/Traits/RedisTrait.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public static function createConnection(string $dsn, array $options = []): \Redi
170170
}
171171

172172
if (null === $params['class'] && \extension_loaded('redis')) {
173-
$class = $params['redis_cluster'] ? \RedisCluster::class : (1 < \count($hosts) ? \RedisArray::class : \Redis::class);
173+
$class = $params['redis_cluster'] ? \RedisCluster::class : (1 < \count($hosts) && !isset($params['redis_sentinel']) ? \RedisArray::class : \Redis::class);
174174
} else {
175175
$class = $params['class'] ?? \Predis\Client::class;
176176

@@ -184,21 +184,29 @@ public static function createConnection(string $dsn, array $options = []): \Redi
184184
$redis = new $class();
185185

186186
$initializer = static function ($redis) use ($connect, $params, $dsn, $auth, $hosts, $tls) {
187-
$host = $hosts[0]['host'] ?? $hosts[0]['path'];
188-
$port = $hosts[0]['port'] ?? 0;
187+
$hostIndex = 0;
188+
do {
189+
$host = $hosts[$hostIndex]['host'] ?? $hosts[$hostIndex]['path'];
190+
$port = $hosts[$hostIndex]['port'] ?? 0;
191+
$address = false;
192+
193+
if (isset($hosts[$hostIndex]['host']) && $tls) {
194+
$host = 'tls://'.$host;
195+
}
189196

190-
if (isset($hosts[0]['host']) && $tls) {
191-
$host = 'tls://'.$host;
192-
}
197+
if (!isset($params['redis_sentinel'])) {
198+
break;
199+
}
193200

194-
if (isset($params['redis_sentinel'])) {
195201
$sentinel = new \RedisSentinel($host, $port, $params['timeout'], (string) $params['persistent_id'], $params['retry_interval'], $params['read_timeout']);
196202

197-
if (!$address = $sentinel->getMasterAddrByName($params['redis_sentinel'])) {
198-
throw new InvalidArgumentException(sprintf('Failed to retrieve master information from master name "%s" and address "%s:%d".', $params['redis_sentinel'], $host, $port));
203+
if ($address = $sentinel->getMasterAddrByName($params['redis_sentinel'])) {
204+
[$host, $port] = $address;
199205
}
206+
} while (++$hostIndex < \count($hosts) && !$address);
200207

201-
[$host, $port] = $address;
208+
if (isset($params['redis_sentinel']) && !$address) {
209+
throw new InvalidArgumentException(sprintf('Failed to retrieve master information from sentinel "%s" and dsn "%s".', $params['redis_sentinel'], $dsn));
202210
}
203211

204212
try {

src/Symfony/Component/ErrorHandler/ErrorHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ public function screamAt(int $levels, bool $replace = false): int
360360
*/
361361
private function reRegister(int $prev): void
362362
{
363-
if ($prev !== $this->thrownErrors | $this->loggedErrors) {
363+
if ($prev !== ($this->thrownErrors | $this->loggedErrors)) {
364364
$handler = set_error_handler('is_int');
365365
$handler = \is_array($handler) ? $handler[0] : null;
366366
restore_error_handler();

src/Symfony/Component/Finder/Tests/Fixtures/gitignore/search_root/a.txt

Whitespace-only changes.

src/Symfony/Component/Finder/Tests/Fixtures/gitignore/search_root/c.txt

Whitespace-only changes.

src/Symfony/Component/Finder/Tests/Fixtures/gitignore/search_root/dir/b.txt

Whitespace-only changes.

src/Symfony/Component/Finder/Tests/Fixtures/gitignore/search_root/dir/c.txt

Whitespace-only changes.

src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
4545

4646
public function __construct(Stopwatch $stopwatch = null, string|FileLinkFormatter $fileLinkFormat = null, string $charset = null, RequestStack $requestStack = null, DataDumperInterface|Connection $dumper = null)
4747
{
48+
$fileLinkFormat = $fileLinkFormat ?: \ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
4849
$this->stopwatch = $stopwatch;
49-
$this->fileLinkFormat = $fileLinkFormat ?: \ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
50+
$this->fileLinkFormat = $fileLinkFormat instanceof FileLinkFormatter && false === $fileLinkFormat->format('', 0) ? false : $fileLinkFormat;
5051
$this->charset = $charset ?: \ini_get('php.output_encoding') ?: \ini_get('default_charset') ?: 'UTF-8';
5152
$this->requestStack = $requestStack;
5253
$this->dumper = $dumper;

src/Symfony/Component/HttpKernel/Debug/FileLinkFormatter.php

Lines changed: 2 additions & 3 deletions
10000
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,9 @@ class FileLinkFormatter
4242
/**
4343
* @param string|\Closure $urlFormat the URL format, or a closure that returns it on-demand
4444
*/
45-
public function __construct(string $fileLinkFormat = null, RequestStack $requestStack = null, string $baseDir = null, string|\Closure $urlFormat = null)
45+
public function __construct(string|array $fileLinkFormat = null, RequestStack $requestStack = null, string $baseDir = null, string|\Closure $urlFormat = null)
4646
{
47-
$fileLinkFormat = (self::FORMATS[$fileLinkFormat] ?? $fileLinkFormat) ?: \ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format') ?: false;
48-
if ($fileLinkFormat && !\is_array($fileLinkFormat)) {
47+
if (!\is_array($fileLinkFormat) && $fileLinkFormat = (self::FORMATS[$fileLinkFormat] ?? $fileLinkFormat) ?: \ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format') ?: false) {
4948
$i = strpos($f = $fileLinkFormat, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: \strlen($f);
5049
$fileLinkFormat = [substr($f, 0, $i)] + preg_split('/&([^>]++)>/', substr($f, $i), -1, \PREG_SPLIT_DELIM_CAPTURE);
5150
}

src/Symfony/Component/HttpKernel/Fragment/AbstractSurrogateFragmentRenderer.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,11 @@ private function generateSignedFragmentUri(ControllerReference $uri, Request $re
8989
private function containsNonScalars(array $values): bool
9090
{
9191
foreach ($values as $value) {
92-
if (\is_array($value)) {
93-
return $this->containsNonScalars($value);
94-
} elseif (!\is_scalar($value) && null !== $value) {
92+
if (\is_scalar($value) || null === $value) {
93+
continue;
94+
}
95+
96+
if (!\is_array($value) || $this->containsNonScalars($value)) {
9597
return true;
9698
}
9799
}

src/Symfony/Component/HttpKernel/Tests/DataCollector/DumpDataCollectorTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\HttpFoundation\Request;
1616
use Symfony\Component\HttpFoundation\Response;
1717
use Symfony\Component\HttpKernel\DataCollector\DumpDataCollector;
18+
use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
1819
use Symfony\Component\VarDumper\Cloner\Data;
1920
use Symfony\Component\VarDumper\Dumper\CliDumper;
2021
use Symfony\Component\VarDumper\Server\Connection;
@@ -28,7 +29,7 @@ public function testDump()
2829
{
2930
$data = new Data([[123]]);
3031

31-
$collector = new DumpDataCollector();
32+
$collector = new DumpDataCollector(null, new FileLinkFormatter([]));
3233

3334
$this->assertSame('dump', $collector->getName());
3435

src/Symfony/Component/HttpKernel/Tests/Debug/FileLinkFormatterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class FileLinkFormatterTest extends TestCase
2020
{
2121
public function testWhenNoFileLinkFormatAndNoRequest()
2222
{
23-
$sut = new FileLinkFormatter();
23+
$sut = new FileLinkFormatter([]);
2424

2525
$this->assertFalse($sut->format('/kernel/root/src/my/very/best/file.php', 3));
2626
}
@@ -54,7 +54,7 @@ public function testWhenNoFileLinkFormatAndRequest()
5454
$request->server->set('SCRIPT_FILENAME', '/public/index.php');
5555
$request->server->set('REQUEST_URI', '/index.php/example');
5656

57-
$sut = new FileLinkFormatter(null, $requestStack, __DIR__, '/_profiler/open?file=%f&line=%l#line%l');
57+
$sut = new FileLinkFormatter([], $requestStack, __DIR__, '/_profiler/open?file=%f&line=%l#line%l');
5858

5959
$this->assertSame('http://www.example.org/_profiler/open?file=file.php&line=3#line3', $sut->format($file, 3));
6060
}

src/Symfony/Component/Security/Http/Authentication/DefaultAuthenticationFailureHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function onAuthenticationFailure(Request $request, AuthenticationExceptio
7272
$options = $this->options;
7373
$failureUrl = ParameterBagUtils::getRequestParameterValue($request, $options['failure_path_parameter']);
7474

75-
if (\is_string($failureUrl) && str_starts_with($failureUrl, '/')) {
75+
if (\is_string($failureUrl) && (str_starts_with($failureUrl, '/') || str_starts_with($failureUrl, 'http'))) {
7676
$options['failure_path'] = $failureUrl;
7777
} elseif ($this->logger && $failureUrl) {
7878
$this->logger->debug(sprintf('Ignoring query parameter "%s": not a valid URL.', $options['failure_path_parameter']));

src/Symfony/Component/Security/Http/Authentication/DefaultAuthenticationSuccessHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ protected function determineTargetUrl(Request $request): string
9494

9595
$targetUrl = ParameterBagUtils::getRequestParameterValue($request, $this->options['target_path_parameter']);
9696

97-
if (\is_string($targetUrl) && str_starts_with($targetUrl, '/')) {
97+
if (\is_string($targetUrl) && (str_starts_with($targetUrl, '/') || str_starts_with($targetUrl, 'http'))) {
9898
return $targetUrl;
9999
}
100100

src/Symfony/Component/Security/Http/Tests/Authentication/DefaultAuthenticationFailureHandlerTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,21 @@ public function testFailurePathFromRequestWithInvalidUrl()
207207
$handler->onAuthenticationFailure($this->request, $this->exception);
208208
}
209209

210+
public function testAbsoluteUrlRedirectionFromRequest()
211+
{
212+
$options = ['failure_path_parameter' => '_my_failure_path'];
213+
214+
$this->request->expects($this->once())
215+
->method('get')->with('_my_failure_path')
216+
->willReturn('https://localhost/some-path');
217+
218+
$this->httpUtils->expects($this->once())
219+
->method('createRedirectResponse')->with($this->request, 'https://localhost/some-path');
220+
221+
$handler = new DefaultAuthenticationFailureHandler($this->httpKernel, $this->httpUtils, $options, $this->logger);
222+
$handler->onAuthenticationFailure($this->request, $this->exception);
223+
}
224+
210225
private function getRequest()
211226
{
212227
$request = $this->createMock(Request::class);

src/Symfony/Component/Security/Http/Tests/Authentication/DefaultAuthenticationSuccessHandlerTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,21 @@ public function testTargetPathFromRequestWithInvalidUrl()
135135

136136
$handler->onAuthenticationSuccess($request, $token);
137137
}
138+
139+
public function testTargetPathWithAbsoluteUrlFromRequest()
140+
{
141+
$options = ['target_path_parameter' => '_my_target_path'];
142+
143+
$request = $this->createMock(Request::class);
144+
$request->expects($this->once())
145+
->method('get')->with('_my_target_path')
146+
->willReturn('https://localhost/some-path');
147+
148+
$httpUtils = $this->createMock(HttpUtils::class);
149+
$httpUtils->expects($this->once())
150+
->method('createRedirectResponse')->with($request, 'https://localhost/some-path');
151+
152+
$handler = new DefaultAuthenticationSuccessHandler($httpUtils, $options);
153+
$handler->onAuthenticationSuccess($request, $this->createMock(TokenInterface::class));
154+
}
138155
}

0 commit comments

Comments
 (0)
0