Skip to content

Correctly handle Verify Peer option #570

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

Merged
merged 12 commits into from
Jan 10, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"php": "^8.0",
"ext-json": "*",
"illuminate/queue": "^9.0|^10.0",
"php-amqplib/php-amqplib": "^v3.2"
"php-amqplib/php-amqplib": "^v3.5.2"
},
"require-dev": {
"phpunit/phpunit": "^9.3",
Expand Down
3 changes: 2 additions & 1 deletion src/Queue/Connection/ConfigFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ protected static function getSLLOptionsFromConfig(AMQPConnectionConfig $connecti
if ($key = Arr::get($sslConfig, 'local_key')) {
$connectionConfig->setSslKey($key);
}
if ($verifyPeer = Arr::get($sslConfig, 'verify_peer')) {
if (Arr::has($sslConfig, 'verify_peer')) {
$verifyPeer = Arr::get($sslConfig, 'verify_peer');
$connectionConfig->setSslVerify($verifyPeer);
}
if ($passphrase = Arr::get($sslConfig, 'passphrase')) {
Expand Down
8 changes: 4 additions & 4 deletions src/Queue/Connection/ConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ protected static function getSslOptions(AMQPConnectionConfig $config): array
'ciphers' => $config->getSslCiphers(),
'security_level' => $config->getSslSecurityLevel(),
], static function ($value) {
return null !== $value;
return $value !== null;
});
}

Expand Down Expand Up @@ -200,10 +200,10 @@ protected static function assertSSLConnection($connection): void
self::assertExtendedOf($connection, self::CONNECTION_SUB_TYPE_SSL);
}

protected static function assertExtendedOf($connection, string $abstract): void
protected static function assertExtendedOf($connection, string $parent): void
{
if (! is_subclass_of($connection, $abstract)) {
throw new AMQPLogicException(sprintf('The connection must extend: %s', class_basename($abstract)));
if (! is_subclass_of($connection, $parent) && $connection !== $parent) {
throw new AMQPLogicException(sprintf('The connection must extend: %s', class_basename($parent)));
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/Queue/RabbitMQQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,6 @@ public function getJobClass(): string

/**
* Gets a queue/destination, by default the queue option set on the connection.
*
* @param null $queue
*/
public function getQueue($queue = null): string
{
Expand Down
46 changes: 46 additions & 0 deletions tests/Feature/ConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
namespace VladimirYuldashev\LaravelQueueRabbitMQ\Tests\Feature;

use Illuminate\Queue\QueueManager;
use PhpAmqpLib\Connection\AMQPConnectionConfig;
use PhpAmqpLib\Connection\AMQPLazyConnection;
use PhpAmqpLib\Connection\AMQPSSLConnection;
use PhpAmqpLib\Connection\AMQPStreamConnection;
use VladimirYuldashev\LaravelQueueRabbitMQ\Queue\RabbitMQQueue;
use VladimirYuldashev\LaravelQueueRabbitMQ\Tests\Mocks\TestSSLConnection;

class ConnectorTest extends \VladimirYuldashev\LaravelQueueRabbitMQ\Tests\TestCase
{
Expand Down Expand Up @@ -138,4 +140,48 @@ public function testSslConnection(): void
$this->assertTrue($connection->getConnection()->isConnected());
$this->assertTrue($connection->getChannel()->is_open());
}

// Test to validate ssl connection params
public function testNoVerificationSslConnection(): void
{
$this->app['config']->set('queue.connections.rabbitmq', [
'driver' => 'rabbitmq',
'queue' => env('RABBITMQ_QUEUE', 'default'),
'connection' => TestSSLConnection::class,
'secure' => true,

'hosts' => [
[
'host' => getenv('HOST'),
'port' => getenv('PORT_SSL'),
'user' => 'guest',
'password' => 'guest',
'vhost' => '/',
],
],

'options' => [
'ssl_options' => [
'cafile' => getenv('RABBITMQ_SSL_CAFILE'),
'local_cert' => null,
'local_key' => null,
'verify_peer' => false,
'passphrase' => null,
],
],

'worker' => env('RABBITMQ_WORKER', 'default'),
]);

/** @var QueueManager $queue */
$queue = $this->app['queue'];

/** @var RabbitMQQueue $connection */
$connection = $queue->connection('rabbitmq');
$this->assertInstanceOf(RabbitMQQueue::class, $connection);
$this->assertInstanceOf(AMQPSSLConnection::class, $connection->getConnection());
/** @var AMQPConnectionConfig */
$config = $connection->getConnection()->getConfig();
$this->assertFalse($config->getSslVerify());
}
}
14 changes: 14 additions & 0 deletions tests/Mocks/TestSSLConnection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace VladimirYuldashev\LaravelQueueRabbitMQ\Tests\Mocks;

use PhpAmqpLib\Connection\AMQPConnectionConfig;
use PhpAmqpLib\Connection\AMQPSSLConnection;

class TestSSLConnection extends AMQPSSLConnection
{
public function getConfig(): ?AMQPConnectionConfig
{
return $this->config;
}
}