Skip to content

Commit 1649444

Browse files
authored
Merge pull request #2 from eugenys/master
Fix auth for redis transport
2 parents cba656f + 6e12f92 commit 1649444

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ services:
99
- ./:/var/www/html
1010
redis:
1111
image: redis
12+
command: redis-server --requirepass password123
1213
environment: { TERM: xterm }
1314
restart: unless-stopped

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<php>
1010
<ini name="error_reporting" value="-1" />
1111
<env name="SHELL_VERBOSITY" value="-1" />
12-
<env name="REDIS_DSN" value="redis://redis:6379?queue=messenger"/>
12+
<env name="REDIS_DSN" value="redis://u:password123@redis:6379?queue=messenger"/>
1313
</php>
1414
<testsuites>
1515
<testsuite name="feature">

src/Transport/RedisTransport.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,15 @@ public static function fromDsn(SerializerInterface $serializer, string $dsn, arr
5454
$options['queue'] ?? $query['queue'],
5555
[$parsedUrl['host'] ?? '127.0.0.1', intval($parsedUrl['port'] ?? 6379)],
5656
function(Redis $conn) use ($query, $parsedUrl, $options) {
57-
$db = $options['db'] ?? $query['db'] ?? null;
58-
if ($db !== null) {
59-
$conn->select($db);
60-
}
6157
$auth = $options['password'] ?? $parsedUrl['pass'] ?? null;
6258
if ($auth) {
6359
$conn->auth($auth);
6460
}
61+
$db = $options['db'] ?? $query['db'] ?? null;
62+
if ($db !== null) {
63+
$db = intval($db);
64+
$conn->select($db);
65+
}
6566
}
6667
);
6768
}

tests/Feature/Fixtures/redis-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ framework:
33
enabled: true
44
messenger:
55
transports:
6-
krak_redis: 'redis://redis:6379?queue=messenger'
6+
krak_redis: 'redis://u:password123@redis:6379?queue=messenger'
77
sf_redis:
8-
dsn: 'redis://redis:6379'
8+
dsn: 'redis://u:password123@redis:6379'
99
options: { use_krak_redis: false }
1010
routing:
1111
'Krak\SymfonyMessengerRedis\Tests\Feature\Fixtures\KrakRedisMessage': krak_redis

tests/Feature/TransportTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,18 @@ protected function setUp() {
2525
$this->transport = RedisTransport::fromDsn(Serializer::create(), getenv('REDIS_DSN'));
2626
$this->redis = new \Redis();
2727
$this->redis->connect('redis');
28+
$this->redis->auth('password123');
2829
$this->redis->flushAll();
2930
}
3031

32+
/** @test */
33+
public function allows_custom_db() {
34+
$this->given_the_redis_transport_contains_db();
35+
$this->given_there_is_a_wrapped_message();
36+
$this->when_the_message_is_sent_received_and_acked();
37+
$this->then_the_queues_are_empty();
38+
}
39+
3140
/** @test */
3241
public function can_send_a_message() {
3342
$this->given_there_is_a_wrapped_message();
@@ -189,4 +198,9 @@ public function then_the_message_is_available_after(int $delayMs) {
189198
$res = $this->transport->get();
190199
$this->assertCount(1, $res);
191200
}
201+
202+
public function given_the_redis_transport_contains_db()
203+
{
204+
$this->transport = RedisTransport::fromDsn(Serializer::create(), getenv('REDIS_DSN'), ['db' => 2]);
205+
}
192206
}

0 commit comments

Comments
 (0)