Skip to content

Commit 2542290

Browse files
committed
Allow SSL Connections with no peer verification
1 parent 86315a4 commit 2542290

File tree

4 files changed

+64
-4
lines changed

4 files changed

+64
-4
lines changed

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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

tests/Feature/ConnectorTest.php

Lines changed: 45 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,47 @@ public function testSslConnection(): void
138140
$this->assertTrue($connection->getConnection()->isConnected());
139141
$this->assertTrue($connection->getChannel()->is_open());
140142
}
143+
144+
public function testNoVerificationSslConnection(): void
145+
{
146+
$this->app['config']->set('queue.connections.rabbitmq', [
147+
'driver' => 'rabbitmq',
148+
'queue' => env('RABBITMQ_QUEUE', 'default'),
149+
'connection' => TestSSLConnection::class,
150+
'secure' => true,
151+
152+
'hosts' => [
153+
[
154+
'host' => getenv('HOST'),
155+
'port' => getenv('PORT_SSL'),
156+
'user' => 'guest',
157+
'password' => 'guest',
158+
'vhost' => '/',
159+
],
160+
],
161+
162+
'options' => [
163+
'ssl_options' => [
164+
'cafile' => getenv('RABBITMQ_SSL_CAFILE'),
165+
'local_cert' => null,
166+
'local_key' => null,
167+
'verify_peer' => false,
168+
'passphrase' => null,
169+
],
170+
],
171+
172+
'worker' => env('RABBITMQ_WORKER', 'default'),
173+
]);
174+
175+
/** @var QueueManager $queue */
176+
$queue = $this->app['queue'];
177+
178+
/** @var RabbitMQQueue $connection */
179+
$connection = $queue->connection('rabbitmq');
180+
$this->assertInstanceOf(RabbitMQQueue::class, $connection);
181+
$this->assertInstanceOf(AMQPSSLConnection::class, $connection->getConnection());
182+
/** @var AMQPConnectionConfig */
183+
$config = $connection->getConnection()->getConfig();
184+
$this->assertFalse($config->getSslVerify());
185+
}
141186
}

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)