8000 Remove TLS related options when not using TLS · symfony/symfony@37e602d · GitHub
[go: up one dir, main page]

Skip to content

Commit 37e602d

Browse files
author
Olivier Dolbeau
committed
Remove TLS related options when not using TLS
1 parent a7f8180 commit 37e602d

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/Symfony/Component/Messenger/Bridge/Amqp/Tests/Transport/ConnectionTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,27 @@ public function testItCanPublishAndWaitForConfirmation()
748748
$connection = Connection::fromDsn('amqp://localhost?confirm_timeout=0.5', [], $factory);
749749
$connection->publish('body');
750750
}
751+
752+
public function testItCanBeConstructedWithTLSOptionsAndNonTLSDsn()
753+
{
754+
$this->assertEquals(
755+
new Connection([
756+
'host' => 'localhost',
757+
'port' => 5672,
758+
'vhost' => '/',
759+
], [
760+
'name' => self::DEFAULT_EXCHANGE_NAME,
761+
], [
762+
self::DEFAULT_EXCHANGE_NAME => [],
763+
]),
764+
Connection::fromDsn('amqp://', [
765+
'cacert' => 'foobar',
766+
'cert' => 'foobar',
767+
'key' => 'foobar',
768+
'verify' => false,
769+
])
770+
);
771+
}
751772
}
752773

753774
class TestAmqpFactory extends AmqpFactory

src/Symfony/Component/Messenger/Bridge/Amqp/Transport/Connection.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ public static function fromDsn(string $dsn, array $options = [], AmqpFactory $am
219219
return $queueOptions;
220220
}, $queuesOptions);
221221

222+
if (!$useAmqps) {
223+
unset($amqpOptions['cacert'], $amqpOptions['cert'], $amqpOptions['key'], $amqpOptions['verify']);
224+
}
225+
222226
if ($useAmqps && !self::hasCaCertConfigured($amqpOptions)) {
223227
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.');
224228
}

0 commit comments

Comments
 (0)
0