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 TLS support #48

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ before_script:
sudo service rabbitmq-server start;
fi
- if [ "$STOMP_PROVIDER" = 'activemq' ]; then
sudo apt install activemq tree;
sudo apt update;
sudo apt install activemq;
sudo cp tests/utils/activemq.xml /etc/activemq/instances-available/main/;
sudo ln -s /etc/activemq/instances-available/main /etc/activemq/instances-enabled/main;
sudo service activemq start;
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ $loop->run();
* `vhost`: Virtual host, defaults to `/`.
* `login`: Login user name, defaults to `guest`.
* `passcode`: Login passcode, defaults to `guest`.
* `protocol`: Protocol to connect with, defaults to `tcp` (use `tls` for TLS-enabled connections).

## Acknowledgement

Expand Down Expand Up @@ -95,6 +96,10 @@ To run the test suite, you need PHPUnit.

$ phpunit

Or, to run the functional tests against a local message queue:

$ STOMP_PROVIDER=rabbitmq phpunit -c phpunit-functional.xml.dist

## License

MIT, see LICENSE.
Expand Down
10 changes: 10 additions & 0 deletions examples/config/activemq-tls.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

return array(
'host' => '127.0.0.1',
'port' => '61614',
'login' => 'system',
'passcode' => 'manager',
'vhost' => '/',
'protocol' => 'tls',
);
3 changes: 2 additions & 1 deletion src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Factory
'vhost' => '/',
'login' => 'guest',
'passcode' => 'guest',
'protocol' => 'tcp',
);

private $loop;
Expand Down Expand Up @@ -51,7 +52,7 @@ public function createClient(array $options = array())

public function createConnection($options)
{
$address = 'tcp://'.$options['host'].':'.$options['port'];
$address = $options['protocol'].'://'.$options['host'].':'.$options['port'];

if (false === $fd = @stream_socket_client($address, $errno, $errstr)) {
$message = "Could not bind to $address: $errstr";
Expand Down
4 changes: 2 additions & 2 deletions tests/React/Tests/Stomp/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function testCreateConnection()

$loop = $this->createMock('React\EventLoop\LoopInterface');
$factory = new Factory($loop);
$conn = $factory->createConnection(array('host' => 'localhost', 'port' => 37234));
$conn = $factory->createConnection(array('host' => 'localhost', 'port' => 37234, 'protocol' => 'tcp'));

$this->assertInstanceOf('React\Socket\Connection', $conn);
}
Expand All @@ -25,7 +25,7 @@ public function itShouldThrowAnExceptionInCaseSocketCreationFails()
$factory = new Factory($loop);

try {
$factory->createConnection(array('host' => 'localhost', 'port' => 37235));
$factory->createConnection(array('host' => 'localhost', 'port' => 37235, 'protocol' => 'tcp'));
$this->fail('This should have raised an exception');
} catch (ConnectionException $e) {

Expand Down