diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 6e785c383a0f1..1b72f86a75159 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -48,6 +48,12 @@ jobs: image: redis:6.2.8 ports: - 16379:6379 + redis-authenticated: + image: redis:6.2.8 + ports: + - 16380:6379 + env: + REDIS_ARGS: "--requirepass p@ssword" redis-cluster: image: grokzen/redis-cluster:6.2.8 ports: @@ -172,6 +178,7 @@ jobs: run: ./phpunit --group integration -v env: REDIS_HOST: 'localhost:16379' + REDIS_AUTHENTICATED_HOST: 'localhost:16380' REDIS_CLUSTER_HOSTS: 'localhost:7000 localhost:7001 localhost:7002 localhost:7003 localhost:7004 localhost:7005' REDIS_SENTINEL_HOSTS: 'localhost:26379 localhost:26379 localhost:26379' REDIS_SENTINEL_SERVICE: redis_sentinel diff --git a/src/Symfony/Component/Cache/Tests/Traits/RedisTraitTest.php b/src/Symfony/Component/Cache/Tests/Traits/RedisTraitTest.php index e7e368b3e829d..623e1582eabf7 100644 --- a/src/Symfony/Component/Cache/Tests/Traits/RedisTraitTest.php +++ b/src/Symfony/Component/Cache/Tests/Traits/RedisTraitTest.php @@ -15,15 +15,11 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Cache\Traits\RedisTrait; +/** + * @requires extension redis + */ class RedisTraitTest extends TestCase { - public static function setUpBeforeClass(): void - { - if (!getenv('REDIS_CLUSTER_HOSTS')) { - throw new SkippedTestSuiteError('REDIS_CLUSTER_HOSTS env var is not defined.'); - } - } - /** * @dataProvider provideCreateConnection */ @@ -42,6 +38,19 @@ public function testCreateConnection(string $dsn, string $expectedClass) self::assertInstanceOf($expectedClass, $connection); } + public function testUrlDecodeParameters() + { + if (!getenv('REDIS_AUTHENTICATED_HOST')) { + self::markTestSkipped('REDIS_AUTHENTICATED_HOST env var is not defined.'); + } + + $mock = self::getObjectForTrait(RedisTrait::class); + $connection = $mock::createConnection('redis://:p%40ssword@'.getenv('REDIS_AUTHENTICATED_HOST')); + + self::assertInstanceOf(\Redis::class, $connection); + self::assertSame('p@ssword', $connection->getAuth()); + } + public static function provideCreateConnection(): array { $hosts = array_map(function ($host) { return sprintf('host[%s]', $host); }, explode(' ', getenv('REDIS_CLUSTER_HOSTS'))); diff --git a/src/Symfony/Component/Cache/Traits/RedisTrait.php b/src/Symfony/Component/Cache/Traits/RedisTrait.php index eb97957320f65..352d142c9e5b4 100644 --- a/src/Symfony/Component/Cache/Traits/RedisTrait.php +++ b/src/Symfony/Component/Cache/Traits/RedisTrait.php @@ -105,7 +105,7 @@ public static function createConnection(string $dsn, array $options = []) $params = preg_replace_callback('#^'.$scheme.':(//)?(?:(?:[^:@]*+:)?([^@]*+)@)?#', function ($m) use (&$auth) { if (isset($m[2])) { - $auth = $m[2]; + $auth = rawurldecode($m[2]); if ('' === $auth) { $auth = null;