Skip to content

Commit

Permalink
bug #30658 [Messenger] Ensure an exception is thrown when the AMQP co…
Browse files Browse the repository at this point in the history
…nnect() does not work (sroze)

This PR was merged into the 4.3-dev branch.

Discussion
----------

[Messenger] Ensure an exception is thrown when the AMQP connect() does not work

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #30557
| License       | MIT
| Doc PR        | ø

This `connectionCredentials` instance escaped the renaming in #30557.

Commits
-------

46b9476 Ensure an exception is thrown when the AMQP connect() does not work
  • Loading branch information
sroze committed Mar 23, 2019
2 parents 6ff1185 + 46b9476 commit 521d82a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Expand Up @@ -335,6 +335,27 @@ public function testItDelaysTheMessageWithADifferentRoutingKeyAndTTLs()
$delayExchange->expects($this->once())->method('publish')->with('{}', 'delay_120000', AMQP_NOPARAM, ['headers' => []]);
$connection->publish('{}', [], 120000);
}

/**
* @expectedException \AMQPException
* @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":"********"})
*/
public function testObfuscatePasswordInDsn()
{
$factory = new TestAmqpFactory(
$amqpConnection = $this->createMock(\AMQPConnection::class),
$amqpChannel = $this->createMock(\AMQPChannel::class),
$amqpQueue = $this->createMock(\AMQPQueue::class),
$amqpExchange = $this->createMock(\AMQPExchange::class)
);

$amqpConnection->method('connect')->willThrowException(
new \AMQPConnectionException('Oups.')
);

$connection = Connection::fromDsn('amqp://user:secretpassword@localhost/%2f/messages', [], $factory);
$connection->channel();
}
}

class TestAmqpFactory extends AmqpFactory
Expand Down
Expand Up @@ -317,7 +317,7 @@ public function channel(): \AMQPChannel
try {
$connection->{$connectMethod}();
} catch (\AMQPConnectionException $e) {
$credentials = $this->connectionCredentials;
$credentials = $this->connectionConfiguration;
$credentials['password'] = '********';

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

0 comments on commit 521d82a

Please sign in to comment.