From 9833485f62d6e441ca533c9a4d8f8b72a6876e17 Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Thu, 7 Jun 2018 15:19:07 +1000 Subject: [PATCH 1/3] add TLS support This adds the ability to connect to TLS-protected queue brokers, via the 'protocol' option. Update affected unit tests, add functional test (verified against activemq v5.15.0). Also document how to run the functional tests --- README.md | 5 +++++ examples/config/activemq-tls.php | 10 ++++++++++ src/Factory.php | 3 ++- tests/React/Tests/Stomp/FactoryTest.php | 4 ++-- 4 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 examples/config/activemq-tls.php diff --git a/README.md b/README.md index 2a79d86..f305081 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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. diff --git a/examples/config/activemq-tls.php b/examples/config/activemq-tls.php new file mode 100644 index 0000000..e8a561b --- /dev/null +++ b/examples/config/activemq-tls.php @@ -0,0 +1,10 @@ + '127.0.0.1', + 'port' => '61614', + 'login' => 'system', + 'passcode' => 'manager', + 'vhost' => '/', + 'protocol' => 'tls', +); diff --git a/src/Factory.php b/src/Factory.php index d805661..8911159 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -17,6 +17,7 @@ class Factory 'vhost' => '/', 'login' => 'guest', 'passcode' => 'guest', + 'protocol' => 'tcp', ); private $loop; @@ -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"; diff --git a/tests/React/Tests/Stomp/FactoryTest.php b/tests/React/Tests/Stomp/FactoryTest.php index d26b56c..e3fb635 100644 --- a/tests/React/Tests/Stomp/FactoryTest.php +++ b/tests/React/Tests/Stomp/FactoryTest.php @@ -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); } @@ -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) { From 7fcd6f963d598fbab0aa4bd62f81bb058ae37eec Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Fri, 8 Jun 2018 11:43:35 +1000 Subject: [PATCH 2/3] remove tree package for travis build tree dependency is not found in trusty - two options to fix: 'apt update' before installing tree, or don't install it. I chose the latter because it does not look like it is being used --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 130250b..25dfd18 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,7 +25,7 @@ before_script: sudo service rabbitmq-server start; fi - if [ "$STOMP_PROVIDER" = 'activemq' ]; then - sudo apt install activemq tree; + 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; From 562400cb5e0c27d37fb16909740fbea23a0db8a3 Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Fri, 8 Jun 2018 15:34:09 +1000 Subject: [PATCH 3/3] another blind fix for travis build failure I was able to somewhat replicate the activemq install issue with the ubuntu:trusty docker image, and an 'apt update' resolved it --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 25dfd18..0a88ea2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,6 +25,7 @@ before_script: sudo service rabbitmq-server start; fi - if [ "$STOMP_PROVIDER" = 'activemq' ]; then + 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;