Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Messenger] Remove TLS related options when not using TLS #41616

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -748,6 +748,27 @@ public function testItCanPublishAndWaitForConfirmation()
$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
Expand Down
Expand Up @@ -219,6 +219,10 @@ public static function fromDsn(string $dsn, array $options = [], AmqpFactory $am
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.');
}
Expand Down