Skip to content

Commit 12845ab

Browse files
bug symfony#52688 [Cache] Add url decoding of password in RedisTrait DSN (alexandre-daubois)
This PR was merged into the 5.4 branch. Discussion ---------- [Cache] Add url decoding of password in `RedisTrait` DSN | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | Fix symfony#52420 | License | MIT This brings support for `@` char in passwords Commits ------- 1717fca [Cache] Add url decoding of password in `RedisTrait` DSN
2 parents 9780f09 + 1717fca commit 12845ab

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

.github/workflows/integration-tests.yml

+7
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ jobs:
4848
image: redis:6.2.8
4949
ports:
5050
- 16379:6379
51+
redis-authenticated:
52+
image: redis:6.2.8
53+
ports:
54+
- 16380:6379
55+
env:
56+
REDIS_ARGS: "--requirepass p@ssword"
5157
redis-cluster:
5258
image: grokzen/redis-cluster:6.2.8
5359
ports:
@@ -172,6 +178,7 @@ jobs:
172178
run: ./phpunit --group integration -v
173179
env:
174180
REDIS_HOST: 'localhost:16379'
181+
REDIS_AUTHENTICATED_HOST: 'localhost:16380'
175182
REDIS_CLUSTER_HOSTS: 'localhost:7000 localhost:7001 localhost:7002 localhost:7003 localhost:7004 localhost:7005'
176183
REDIS_SENTINEL_HOSTS: 'localhost:26379 localhost:26379 localhost:26379'
177184
REDIS_SENTINEL_SERVICE: redis_sentinel

src/Symfony/Component/Cache/Tests/Traits/RedisTraitTest.php

+16-7
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,11 @@
1515
use PHPUnit\Framework\TestCase;
1616
use Symfony\Component\Cache\Traits\RedisTrait;
1717

18+
/**
19+
* @requires extension redis
20+
*/
1821
class RedisTraitTest extends TestCase
1922
{
20-
public static function setUpBeforeClass(): void
21-
{
22-
if (!getenv('REDIS_CLUSTER_HOSTS')) {
23-
throw new SkippedTestSuiteError('REDIS_CLUSTER_HOSTS env var is not defined.');
24-
}
25-
}
26-
2723
/**
2824
* @dataProvider provideCreateConnection
2925
*/
@@ -42,6 +38,19 @@ public function testCreateConnection(string $dsn, string $expectedClass)
4238
self::assertInstanceOf($expectedClass, $connection);
4339
}
4440

41+
public function testUrlDecodeParameters()
42+
{
43+
if (!getenv('REDIS_AUTHENTICATED_HOST')) {
44+
self::markTestSkipped('REDIS_AUTHENTICATED_HOST env var is not defined.');
45+
}
46+
47+
$mock = self::getObjectForTrait(RedisTrait::class);
48+
$connection = $mock::createConnection('redis://:p%40ssword@'.getenv('REDIS_AUTHENTICATED_HOST'));
49+
50+
self::assertInstanceOf(\Redis::class, $connection);
51+
self::assertSame('p@ssword', $connection->getAuth());
52+
}
53+
4554
public static function provideCreateConnection(): array
4655
{
4756
$hosts = array_map(function ($host) { return sprintf('host[%s]', $host); }, explode(' ', getenv('REDIS_CLUSTER_HOSTS')));

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public static function createConnection(string $dsn, array $options = [])
105105

106106
$params = preg_replace_callback('#^'.$scheme.':(//)?(?:(?:[^:@]*+:)?([^@]*+)@)?#', function ($m) use (&$auth) {
107107
if (isset($m[2])) {
108-
$auth = $m[2];
108+
$auth = rawurldecode($m[2]);
109109

110110
if ('' === $auth) {
111111
$auth = null;

0 commit comments

Comments
 (0)