Remove TLS related options when not using TLS

This commit is contained in:
Olivier Dolbeau 2021-06-07 17:25:08 +02:00
parent a7f8180004
commit 37e602dd28
2 changed files with 25 additions and 0 deletions

View File

@ -748,6 +748,27 @@ class ConnectionTest extends TestCase
$connection = Connection::fromDsn('amqp://localhost?confirm_timeout=0.5', [], $factory);
$connection->publish('body');
}
public function testItCanBeConstructedWithTLSOptionsAndNonTLSDsn()
{
$this->assertEquals(
new Connection([
'host' => 'localhost',
'port' => 5672,
'vhost' => '/',
], [
'name' => self::DEFAULT_EXCHANGE_NAME,
], [
self::DEFAULT_EXCHANGE_NAME => [],
]),
Connection::fromDsn('amqp://', [
'cacert' => 'foobar',
'cert' => 'foobar',
'key' => 'foobar',
'verify' => false,
])
);
}
}
class TestAmqpFactory extends AmqpFactory

View File

@ -219,6 +219,10 @@ class Connection
return $queueOptions;
}, $queuesOptions);
if (!$useAmqps) {
unset($amqpOptions['cacert'], $amqpOptions['cert'], $amqpOptions['key'], $amqpOptions['verify']);
}
if ($useAmqps && !self::hasCaCertConfigured($amqpOptions)) {
throw new InvalidArgumentException('No CA certificate has been provided. Set "amqp.cacert" in your php.ini or pass the "cacert" parameter in the DSN to use SSL. Alternatively, you can use amqp:// to use without SSL.');
}