Skip to content

[Cache] Add url decoding of password in RedisTrait DSN #52688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
23 changes: 16 additions & 7 deletions src/Symfony/Component/Cache/Tests/Traits/RedisTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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')));
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Traits/RedisTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down