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

Add SSL support #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
21 changes: 18 additions & 3 deletions src/Codeception/Module/AMQP.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Exception;
use PhpAmqpLib\Channel\AMQPChannel;
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Connection\AMQPSSLConnection;
use PhpAmqpLib\Exception\AMQPProtocolChannelException;
use PhpAmqpLib\Message\AMQPMessage;

Expand Down Expand Up @@ -59,10 +60,17 @@ class AMQP extends Module implements RequiresPackage
'vhost' => '/',
'cleanup' => true,
'single_channel' => false,
'ssl_enabled' => false,
'ssl_options' => [
'capath' => '/etc/ssl/certs',
'cafile' => '/etc/ssl/certs/ca-certificates.crt',
'verify_peer' => true,
'verify_peer_name' => true,
],
'queues' => []
];

public ?AMQPStreamConnection $connection = null;
public AMQPStreamConnection | AMQPSSLConnection | null $connection = null;

protected ?int $channelId = null;

Expand All @@ -73,7 +81,10 @@ class AMQP extends Module implements RequiresPackage

public function _requires(): array
{
return [AMQPStreamConnection::class => '"php-amqplib/php-amqplib": "~2.4"'];
return [
AMQPStreamConnection::class => '"php-amqplib/php-amqplib": "~2.4"',
AMQPSSLConnection::class => '"php-amqplib/php-amqplib": "~2.4"'
];
}

public function _initialize(): void
Expand All @@ -83,9 +94,13 @@ public function _initialize(): void
$username = $this->config['username'];
$password = $this->config['password'];
$vhost = $this->config['vhost'];
$ssl_enabled = $this->config['ssl_enabled'];
$ssl_options = $this->config['ssl_options'];

try {
$this->connection = new AMQPStreamConnection($host, $port, $username, $password, $vhost);
$this->connection = $ssl_enabled
? new AMQPSSLConnection($host, $port, $username, $password, $vhost, $ssl_options)
: new AMQPStreamConnection($host, $port, $username, $password, $vhost);
} catch (Exception $exception) {
throw new ModuleException(__CLASS__, $exception->getMessage() . ' while establishing connection to MQ server');
}
Expand Down