Skip to content

Commit 03e1051

Browse files
authored
Merge pull request #570 from vyuldashev/newverifypeer
Correctly handle Verify Peer option
2 parents 86315a4 + 3669445 commit 03e1051

File tree

6 files changed

+67
-8
lines changed

6 files changed

+67
-8
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"php": "^8.0",
1313
"ext-json": "*",
1414
"illuminate/queue": "^9.0|^10.0",
15-
"php-amqplib/php-amqplib": "^v3.2"
15+
"php-amqplib/php-amqplib": "^v3.5.2"
1616
},
1717
"require-dev": {
1818
"phpunit/phpunit": "^9.3",

src/Queue/Connection/ConfigFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ protected static function getSLLOptionsFromConfig(AMQPConnectionConfig $connecti
7575
if ($key = Arr::get($sslConfig, 'local_key')) {
7676
$connectionConfig->setSslKey($key);
7777
}
78-
if ($verifyPeer = Arr::get($sslConfig, 'verify_peer')) {
78+
if (Arr::has($sslConfig, 'verify_peer')) {
79+
$verifyPeer = Arr::get($sslConfig, 'verify_peer');
7980
$connectionConfig->setSslVerify($verifyPeer);
8081
}
8182
if ($passphrase = Arr::get($sslConfig, 'passphrase')) {

src/Queue/Connection/ConnectionFactory.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ protected static function getSslOptions(AMQPConnectionConfig $config): array
170170
'ciphers' => $config->getSslCiphers(),
171171
'security_level' => $config->getSslSecurityLevel(),
172172
], static function ($value) {
173-
return null !== $value;
173+
return $value !== null;
174174
});
175175
}
176176

@@ -200,10 +200,10 @@ protected static function assertSSLConnection($connection): void
200200
self::assertExtendedOf($connection, self::CONNECTION_SUB_TYPE_SSL);
201201
}
202202

203-
protected static function assertExtendedOf($connection, string $abstract): void
203+
protected static function assertExtendedOf($connection, string $parent): void
204204
{
205-
if (! is_subclass_of($connection, $abstract)) {
206-
throw new AMQPLogicException(sprintf('The connection must extend: %s', class_basename($abstract)));
205+
if (! is_subclass_of($connection, $parent) && $connection !== $parent) {
206+
throw new AMQPLogicException(sprintf('The connection must extend: %s', class_basename($parent)));
207207
}
208208
}
209209

src/Queue/RabbitMQQueue.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,6 @@ public function getJobClass(): string
303303

304304
/**
305305
* Gets a queue/destination, by default the queue option set on the connection.
306-
*
307-
* @param null $queue
308306
*/
309307
public function getQueue($queue = null): string
310308
{

tests/Feature/ConnectorTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
namespace VladimirYuldashev\LaravelQueueRabbitMQ\Tests\Feature;
44

55
use Illuminate\Queue\QueueManager;
6+
use PhpAmqpLib\Connection\AMQPConnectionConfig;
67
use PhpAmqpLib\Connection\AMQPLazyConnection;
78
use PhpAmqpLib\Connection\AMQPSSLConnection;
89
use PhpAmqpLib\Connection\AMQPStreamConnection;
910
use VladimirYuldashev\LaravelQueueRabbitMQ\Queue\RabbitMQQueue;
11+
use VladimirYuldashev\LaravelQueueRabbitMQ\Tests\Mocks\TestSSLConnection;
1012

1113
class ConnectorTest extends \VladimirYuldashev\LaravelQueueRabbitMQ\Tests\TestCase
1214
{
@@ -138,4 +140,48 @@ public function testSslConnection(): void
138140
$this->assertTrue($connection->getConnection()->isConnected());
139141
$this->assertTrue($connection->getChannel()->is_open());
140142
}
143+
144+
// Test to validate ssl connection params
145+
public function testNoVerificationSslConnection(): void
146+
{
147+
$this->app['config']->set('queue.connections.rabbitmq', [
148+
'driver' => 'rabbitmq',
149+
'queue' => env('RABBITMQ_QUEUE', 'default'),
150+
'connection' => TestSSLConnection::class,
151+
'secure' => true,
152+
153+
'hosts' => [
154+
[
155+
'host' => getenv('HOST'),
156+
'port' => getenv('PORT_SSL'),
157+
'user' => 'guest',
158+
'password' => 'guest',
159+
'vhost' => '/',
160+
],
161+
],
162+
163+
'options' => [
164+
'ssl_options' => [
165+
'cafile' => getenv('RABBITMQ_SSL_CAFILE'),
166+
'local_cert' => null,
167+
'local_key' => null,
168+
'verify_peer' => false,
169+
'passphrase' => null,
170+
],
171+
],
172+
173+
'worker' => env('RABBITMQ_WORKER', 'default'),
174+
]);
175+
176+
/** @var QueueManager $queue */
177+
$queue = $this->app['queue'];
178+
179+
/** @var RabbitMQQueue $connection */
180+
$connection = $queue->connection('rabbitmq');
181+
$this->assertInstanceOf(RabbitMQQueue::class, $connection);
182+
$this->assertInstanceOf(AMQPSSLConnection::class, $connection->getConnection());
183+
/** @var AMQPConnectionConfig */
184+
$config = $connection->getConnection()->getConfig();
185+
$this->assertFalse($config->getSslVerify());
186+
}
141187
}

tests/Mocks/TestSSLConnection.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace VladimirYuldashev\LaravelQueueRabbitMQ\Tests\Mocks;
4+
5+
use PhpAmqpLib\Connection\AMQPConnectionConfig;
6+
use PhpAmqpLib\Connection\AMQPSSLConnection;
7+
8+
class TestSSLConnection extends AMQPSSLConnection
9+
{
10+
public function getConfig(): ?AMQPConnectionConfig
11+
{
12+
return $this->config;
13+
}
14+
}

0 commit comments

Comments
 (0)