Skip to content

Commit 1a7fe42

Browse files
committed
Ensure an exception is thrown when the AMQP connect() does not work
1 parent 3bf7c82 commit 1a7fe42

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

Tests/Transport/AmqpExt/ConnectionTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,27 @@ public function testItDelaysTheMessageWithADifferentRoutingKeyAndTTLs()
335335
$delayExchange->expects($this->once())->method('publish')->with('{}', 'delay_120000', AMQP_NOPARAM, ['headers' => []]);
336336
$connection->publish('{}', [], 120000);
337337
}
338+
339+
/**
340+
* @expectedException \AMQPException
341+
* @expectedExceptionMessage Could not connect to the AMQP server. Please verify the provided DSN. ({"delay":{"routing_key_pattern":"delay_%delay%","exchange_name":"delay","queue_name_pattern":"delay_queue_%delay%"},"host":"localhost","port":5672,"vhost":"\/","login":"user","password":"********"})
342+
*/
343+
public function testObfuscatePasswordInDsn()
344+
{
345+
$factory = new TestAmqpFactory(
346+
$amqpConnection = $this->createMock(\AMQPConnection::class),
347+
$amqpChannel = $this->createMock(\AMQPChannel::class),
348+
$amqpQueue = $this->createMock(\AMQPQueue::class),
349+
$amqpExchange = $this->createMock(\AMQPExchange::class)
350+
);
351+
352+
$amqpConnection->method('connect')->willThrowException(
353+
new \AMQPConnectionException('Oups.')
354+
);
355+
356+
$connection = Connection::fromDsn('amqp://user:secretpassword@localhost/%2f/messages', [], $factory);
357+
$connection->channel();
358+
}
338359
}
339360

340361
class TestAmqpFactory extends AmqpFactory

Transport/AmqpExt/Connection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ public function channel(): \AMQPChannel
317317
try {
318318
$connection->{$connectMethod}();
319319
} catch (\AMQPConnectionException $e) {
320-
$credentials = $this->connectionCredentials;
320+
$credentials = $this->connectionConfiguration;
321321
$credentials['password'] = '********';
322322

323323
throw new \AMQPException(sprintf('Could not connect to the AMQP server. Please verify the provided DSN. (%s)', json_encode($credentials)), 0, $e);

0 commit comments

Comments
 (0)