From d720933588e03f36646081f2b976082b321a7663 Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Sun, 15 Jun 2014 10:35:59 -0400 Subject: [PATCH 01/31] Repo move --- README.md | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e1ed87e..72aec64 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ #Ratchet [![Build Status](https://secure.travis-ci.org/cboden/Ratchet.png?branch=master)](http://travis-ci.org/cboden/Ratchet) -[![Latest Stable Version](https://poser.pugx.org/cboden/Ratchet/v/stable.png)](https://packagist.org/packages/cboden/Ratchet) +[![Latest Stable Version](https://poser.pugx.org/ratchetphp/Ratchet/v/stable.png)](https://packagist.org/packages/cboden/ratchet) A PHP 5.3 library for asynchronously serving WebSockets. Build up your application through simple interfaces and re-use your application without changing any of its code just by combining different components. diff --git a/composer.json b/composer.json index c785ce0..2092cc1 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ ] , "support": { "forum": "https://groups.google.com/forum/#!forum/ratchet-php" - , "issues": "https://github.com/cboden/Ratchet/issues" + , "issues": "https://github.com/ratchetphp/Ratchet/issues" , "irc": "irc://irc.freenode.org/reactphp" } , "autoload": { From 0a43d84a9eea78a0c42fd731f30ab1f57c5b1954 Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Sun, 15 Jun 2014 10:44:06 -0400 Subject: [PATCH 02/31] repo move updates --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 72aec64..67f307d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ #Ratchet -[![Build Status](https://secure.travis-ci.org/cboden/Ratchet.png?branch=master)](http://travis-ci.org/cboden/Ratchet) +[![Build Status](https://secure.travis-ci.org/ratchetphp/Ratchet.png?branch=master)](http://travis-ci.org/ratchetphp/Ratchet) [![Latest Stable Version](https://poser.pugx.org/ratchetphp/Ratchet/v/stable.png)](https://packagist.org/packages/cboden/ratchet) A PHP 5.3 library for asynchronously serving WebSockets. From d00102cb3926a5731b73c5878ec7beafb9dc4a93 Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Sun, 15 Jun 2014 11:27:15 -0400 Subject: [PATCH 03/31] Fix version badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 67f307d..5cc5976 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ #Ratchet [![Build Status](https://secure.travis-ci.org/ratchetphp/Ratchet.png?branch=master)](http://travis-ci.org/ratchetphp/Ratchet) -[![Latest Stable Version](https://poser.pugx.org/ratchetphp/Ratchet/v/stable.png)](https://packagist.org/packages/cboden/ratchet) +[![Latest Stable Version](https://poser.pugx.org/cboden/ratchet/v/stable.png)](https://packagist.org/packages/cboden/ratchet) A PHP 5.3 library for asynchronously serving WebSockets. Build up your application through simple interfaces and re-use your application without changing any of its code just by combining different components. From d16779e24fa1d386b062774d57bdd94550ef76a2 Mon Sep 17 00:00:00 2001 From: bobvandevijver Date: Wed, 9 Jul 2014 22:24:53 +0200 Subject: [PATCH 04/31] Change private into protected This is handy if you want to overwrite the class. --- src/Ratchet/Wamp/WampServer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ratchet/Wamp/WampServer.php b/src/Ratchet/Wamp/WampServer.php index d839fb8..8fb9e65 100644 --- a/src/Ratchet/Wamp/WampServer.php +++ b/src/Ratchet/Wamp/WampServer.php @@ -15,7 +15,7 @@ class WampServer implements MessageComponentInterface, WsServerInterface { /** * @var ServerProtocol */ - private $wampProtocol; + protected $wampProtocol; /** * This class just makes it 1 step easier to use Topic objects in WAMP From 72b1a44e382f8cd263e388e6be71fbdbd82acc7f Mon Sep 17 00:00:00 2001 From: Ben Connito Date: Thu, 7 Aug 2014 11:56:13 -0400 Subject: [PATCH 05/31] add port property to App allow origins in flash policy server dont start a flash policy server if one is already running better CURIE support on CALL URI should be un prefixed WampConnection callResult should allow an object to be encoded and sent --- .gitignore | 12 ++++++----- src/Ratchet/App.php | 32 +++++++++++++++++++++++++---- src/Ratchet/Wamp/ServerProtocol.php | 3 ++- src/Ratchet/Wamp/WampConnection.php | 18 +++++++++++++--- 4 files changed, 52 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 2e580df..32db066 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ -phpunit.xml -reports -sandbox -vendor -composer.lock +phpunit.xml +reports +sandbox +vendor +composer.lock +/nbproject/private/ +/nbproject/ \ No newline at end of file diff --git a/src/Ratchet/App.php b/src/Ratchet/App.php index c6d9ceb..f7d5e52 100644 --- a/src/Ratchet/App.php +++ b/src/Ratchet/App.php @@ -42,6 +42,12 @@ class App { * @var string */ protected $httpHost; + + /*** + * The port the socket is listening + * @var int + */ + protected $port; /** * @var int @@ -68,6 +74,7 @@ class App { } $this->httpHost = $httpHost; + $this->port = $port; $socket = new Reactor($loop); $socket->listen($port, $address); @@ -81,10 +88,20 @@ class App { $flashSock = new Reactor($loop); $this->flashServer = new IoServer($policy, $flashSock); - if (80 == $port) { - $flashSock->listen(843, '0.0.0.0'); - } else { - $flashSock->listen(8843); + //check if another App is already running a flash policy server on 843 + $test = @fsockopen('127.0.0.1', 843, $errno, $errstr, 5); + + //if not start a flash policy serever + if(is_resource($test) === false){ + $policy = new FlashPolicy; + $policy->addAllowedAccess($httpHost, 80); + $policy->addAllowedAccess($httpHost, $port); + $flashSock = new Reactor($loop); + $this->flashServer = new IoServer($policy, $flashSock); + + $flashSock->listen(843, '0.0.0.0'); + }else{ + fclose($test); } } @@ -118,6 +135,13 @@ class App { if ('*' !== $allowedOrigins[0]) { $decorated = new OriginCheck($decorated, $allowedOrigins); } + + //allow origins in flash policy server + if(empty($this->flashServer) === false){ + foreach($allowedOrigins as $allowedOrgin){ + $this->flashServer->app->addAllowedAccess($allowedOrgin, $this->port); + } + } $this->routes->add('rr-' . ++$this->_routeCounter, new Route($path, array('_controller' => $decorated), array('Origin' => $this->httpHost), array(), $httpHost)); diff --git a/src/Ratchet/Wamp/ServerProtocol.php b/src/Ratchet/Wamp/ServerProtocol.php index 92dbd85..0bddc83 100644 --- a/src/Ratchet/Wamp/ServerProtocol.php +++ b/src/Ratchet/Wamp/ServerProtocol.php @@ -107,7 +107,8 @@ class ServerProtocol implements MessageComponentInterface, WsServerInterface { $json = $json[0]; } - $this->_decorating->onCall($from, $callID, $procURI, $json); + //procURI should be un prefixed + $this->_decorating->onCall($from, $callID, $from->getUri($procURI), $json); break; case static::MSG_SUBSCRIBE: diff --git a/src/Ratchet/Wamp/WampConnection.php b/src/Ratchet/Wamp/WampConnection.php index 95e1969..6e46eba 100644 --- a/src/Ratchet/Wamp/WampConnection.php +++ b/src/Ratchet/Wamp/WampConnection.php @@ -26,10 +26,10 @@ class WampConnection extends AbstractConnectionDecorator { /** * Successfully respond to a call made by the client * @param string $id The unique ID given by the client to respond to - * @param array $data An array of data to return to the client + * @param array $data an object or array * @return WampConnection */ - public function callResult($id, array $data = array()) { + public function callResult($id, $data = array()) { return $this->send(json_encode(array(WAMP::MSG_CALL_RESULT, $id, $data))); } @@ -77,11 +77,23 @@ class WampConnection extends AbstractConnectionDecorator { /** * Get the full request URI from the connection object if a prefix has been established for it + * Compliant with WAMP Spec for curie URIs * @param string $uri * @return string */ public function getUri($uri) { - return (array_key_exists($uri, $this->WAMP->prefixes) ? $this->WAMP->prefixes[$uri] : $uri); + $seperator = ':'; + + if(preg_match('/http(s*)\:\/\//', $uri) === false){ + if(strpos($uri, $seperator) !== false){ + list($prefix, $action) = explode(':', $uri); + $expandedPrefix = isset($this->WAMP->prefixes[$prefix]) ? $this->WAMP->prefixes[$prefix] : $prefix; + + return $expandedPrefix . '#' . $action; + } + } + + return $uri; } /** From 29e22a0a2e5d6a73990e4e5393e264dc2856d0b7 Mon Sep 17 00:00:00 2001 From: Ben Connito Date: Thu, 7 Aug 2014 12:34:00 -0400 Subject: [PATCH 06/31] testPrefix passing --- src/Ratchet/Wamp/WampConnection.php | 11 ++++++----- tests/unit/Wamp/ServerProtocolTest.php | 11 ++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Ratchet/Wamp/WampConnection.php b/src/Ratchet/Wamp/WampConnection.php index 6e46eba..a0bf523 100644 --- a/src/Ratchet/Wamp/WampConnection.php +++ b/src/Ratchet/Wamp/WampConnection.php @@ -82,14 +82,15 @@ class WampConnection extends AbstractConnectionDecorator { * @return string */ public function getUri($uri) { - $seperator = ':'; + $curieSeperator = ':'; + $fullSeperator = '#'; - if(preg_match('/http(s*)\:\/\//', $uri) === false){ - if(strpos($uri, $seperator) !== false){ - list($prefix, $action) = explode(':', $uri); + if(preg_match('/http(s*)\:\/\//', $uri) == false){ + if(strpos($uri, $curieSeperator) !== false){ + list($prefix, $action) = explode($curieSeperator, $uri); $expandedPrefix = isset($this->WAMP->prefixes[$prefix]) ? $this->WAMP->prefixes[$prefix] : $prefix; - return $expandedPrefix . '#' . $action; + return $expandedPrefix . $fullSeperator . $action; } } diff --git a/tests/unit/Wamp/ServerProtocolTest.php b/tests/unit/Wamp/ServerProtocolTest.php index 1b423d2..082a3f5 100644 --- a/tests/unit/Wamp/ServerProtocolTest.php +++ b/tests/unit/Wamp/ServerProtocolTest.php @@ -211,13 +211,14 @@ class ServerProtocolTest extends \PHPUnit_Framework_TestCase { $conn = new WampConnection($this->newConn()); $this->_comp->onOpen($conn); - $shortIn = 'incoming'; - $longIn = 'http://example.com/incoming/'; + $prefix = 'incoming'; + $fullURI = "http://example.com/$prefix"; + $method = 'call'; - $this->_comp->onMessage($conn, json_encode(array(1, $shortIn, $longIn))); + $this->_comp->onMessage($conn, json_encode(array(1, $prefix, $fullURI))); - $this->assertEquals($longIn, $conn->WAMP->prefixes[$shortIn]); - $this->assertEquals($longIn, $conn->getUri($shortIn)); + $this->assertEquals($fullURI, $conn->WAMP->prefixes[$prefix]); + $this->assertEquals("$fullURI#$method", $conn->getUri("$prefix:$method")); } public function testMessageMustBeJson() { From 705423e0b3beabf9628206ffb0c1c828fcdb11ef Mon Sep 17 00:00:00 2001 From: Ben Connito Date: Thu, 7 Aug 2014 13:35:01 -0400 Subject: [PATCH 07/31] more entropy on session id all tests passing --- src/Ratchet/Wamp/WampConnection.php | 2 +- tests/unit/Wamp/TopicTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Ratchet/Wamp/WampConnection.php b/src/Ratchet/Wamp/WampConnection.php index a0bf523..a12b162 100644 --- a/src/Ratchet/Wamp/WampConnection.php +++ b/src/Ratchet/Wamp/WampConnection.php @@ -17,7 +17,7 @@ class WampConnection extends AbstractConnectionDecorator { parent::__construct($conn); $this->WAMP = new \StdClass; - $this->WAMP->sessionId = uniqid(); + $this->WAMP->sessionId = md5(uniqid(mt_rand(), true)); $this->WAMP->prefixes = array(); $this->send(json_encode(array(WAMP::MSG_WELCOME, $this->WAMP->sessionId, 1, \Ratchet\VERSION))); diff --git a/tests/unit/Wamp/TopicTest.php b/tests/unit/Wamp/TopicTest.php index b8685b7..26db0d3 100644 --- a/tests/unit/Wamp/TopicTest.php +++ b/tests/unit/Wamp/TopicTest.php @@ -81,7 +81,7 @@ class TopicTest extends \PHPUnit_Framework_TestCase { $topic->add($first); $topic->add($second); $topic->add($third); - + $topic->broadcast($msg, array($second->WAMP->sessionId)); } From dbb99058421e39ef3cee795088156421ff4fdaa0 Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Fri, 29 Aug 2014 06:02:01 -0400 Subject: [PATCH 08/31] Added PHP 5.6 to TravisCI build --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 1113aa6..a9dea98 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ php: - 5.3 - 5.4 - 5.5 + - 5.6 - hhvm before_script: From 417017b66735c43b96710cddf22f2e7ce7ce526a Mon Sep 17 00:00:00 2001 From: Ben Connito Date: Fri, 12 Sep 2014 11:46:33 -0400 Subject: [PATCH 09/31] remove local project folder from gitignore in App::__construct use echo instead of trigger_error --- .gitignore | 4 +--- src/Ratchet/App.php | 3 ++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 32db066..793ef58 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,4 @@ phpunit.xml reports sandbox vendor -composer.lock -/nbproject/private/ -/nbproject/ \ No newline at end of file +composer.lock \ No newline at end of file diff --git a/src/Ratchet/App.php b/src/Ratchet/App.php index f7d5e52..484129a 100644 --- a/src/Ratchet/App.php +++ b/src/Ratchet/App.php @@ -62,7 +62,7 @@ class App { */ public function __construct($httpHost = 'localhost', $port = 8080, $address = '127.0.0.1', LoopInterface $loop = null) { if (extension_loaded('xdebug')) { - trigger_error("XDebug extension detected. Remember to disable this if performance testing or going live!", E_USER_WARNING); + echo("XDebug extension detected. Remember to disable this if performance testing or going live!" . PHP_EOL); } if (3 !== strlen('✓')) { @@ -102,6 +102,7 @@ class App { $flashSock->listen(843, '0.0.0.0'); }else{ fclose($test); + echo('flash socket server already running on 843' . PHP_EOL); } } From 1a47d4f5e45bd2e60a128dd9fb115bbbd8edb3ee Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Sat, 13 Sep 2014 19:14:18 -0400 Subject: [PATCH 10/31] Fix loss of query params in Router and unit test --- src/Ratchet/Http/Router.php | 2 ++ tests/unit/Http/RouterTest.php | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/Ratchet/Http/Router.php b/src/Ratchet/Http/Router.php index 817f6a8..bfc8193 100644 --- a/src/Ratchet/Http/Router.php +++ b/src/Ratchet/Http/Router.php @@ -53,6 +53,8 @@ class Router implements HttpServerInterface { $parameters[$key] = $value; } } + $parameters = array_merge($parameters, $request->getQuery()->getAll()); + $url = Url::factory($request->getPath()); $url->setQuery($parameters); $request->setUrl($url); diff --git a/tests/unit/Http/RouterTest.php b/tests/unit/Http/RouterTest.php index 412e774..3615be0 100644 --- a/tests/unit/Http/RouterTest.php +++ b/tests/unit/Http/RouterTest.php @@ -15,8 +15,18 @@ class RouterTest extends \PHPUnit_Framework_TestCase { protected $_req; public function setUp() { + $queryMock = $this->getMock('Guzzle\Http\QueryString'); + $queryMock + ->expects($this->any()) + ->method('getAll') + ->will($this->returnValue(array())); + $this->_conn = $this->getMock('\Ratchet\ConnectionInterface'); $this->_req = $this->getMock('\Guzzle\Http\Message\RequestInterface'); + $this->_req + ->expects($this->any()) + ->method('getQuery') + ->will($this->returnValue($queryMock)); $this->_matcher = $this->getMock('Symfony\Component\Routing\Matcher\UrlMatcherInterface'); $this->_matcher ->expects($this->any()) From 3edd0cdd7e571f67b6d6cf017d71ea6f05ca7230 Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Sun, 14 Sep 2014 11:19:37 -0400 Subject: [PATCH 11/31] Added unit test for query parameter fix closes #220 closes #228 closes #229 --- tests/unit/Http/RouterTest.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/tests/unit/Http/RouterTest.php b/tests/unit/Http/RouterTest.php index 3615be0..5a1128e 100644 --- a/tests/unit/Http/RouterTest.php +++ b/tests/unit/Http/RouterTest.php @@ -98,8 +98,7 @@ class RouterTest extends \PHPUnit_Framework_TestCase { $this->_router->onError($this->_conn, $e); } - public function testRouterGeneratesRouteParameters() - { + public function testRouterGeneratesRouteParameters() { /** @var $controller WsServerInterface */ $controller = $this->getMockBuilder('\Ratchet\WebSocket\WsServer')->disableOriginalConstructor()->getMock(); /** @var $matcher UrlMatcherInterface */ @@ -120,4 +119,22 @@ class RouterTest extends \PHPUnit_Framework_TestCase { $this->assertEquals(array('foo' => 'bar', 'baz' => 'qux'), $request->getQuery()->getAll()); } + + public function testQueryParams() { + $controller = $this->getMockBuilder('\Ratchet\WebSocket\WsServer')->disableOriginalConstructor()->getMock(); + $this->_matcher->expects($this->any())->method('match')->will( + $this->returnValue(array('_controller' => $controller, 'foo' => 'bar', 'baz' => 'qux')) + ); + + $conn = $this->getMock('Ratchet\Mock\Connection'); + $request = $this->getMock('Guzzle\Http\Message\Request', array('getPath'), array('GET', ''), '', false); + + $request->setHeaderFactory($this->getMock('Guzzle\Http\Message\Header\HeaderFactoryInterface')); + $request->setUrl('ws://doesnt.matter?hello=world&foo=nope'); + + $router = new Router($this->_matcher); + $router->onOpen($conn, $request); + + $this->assertEquals(array('foo' => 'nope', 'baz' => 'qux', 'hello' => 'world'), $request->getQuery()->getAll()); + } } From a6e7952671b5287f2478309f839b37656b8aff9c Mon Sep 17 00:00:00 2001 From: Ben Connito Date: Sun, 14 Sep 2014 11:59:46 -0400 Subject: [PATCH 12/31] changed echos back to trigger_error --- src/Ratchet/App.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Ratchet/App.php b/src/Ratchet/App.php index 484129a..4755560 100644 --- a/src/Ratchet/App.php +++ b/src/Ratchet/App.php @@ -62,7 +62,7 @@ class App { */ public function __construct($httpHost = 'localhost', $port = 8080, $address = '127.0.0.1', LoopInterface $loop = null) { if (extension_loaded('xdebug')) { - echo("XDebug extension detected. Remember to disable this if performance testing or going live!" . PHP_EOL); + trigger_error('XDebug extension detected. Remember to disable this if performance testing or going live!', E_USER_WARNING); } if (3 !== strlen('✓')) { @@ -102,7 +102,7 @@ class App { $flashSock->listen(843, '0.0.0.0'); }else{ fclose($test); - echo('flash socket server already running on 843' . PHP_EOL); + trigger_error('flash socket server already running on 843', E_USER_NOTICE); } } From f5d148cdc426e7209ee2bbd44fa4a9b9df54a81c Mon Sep 17 00:00:00 2001 From: Ben Connito Date: Mon, 15 Sep 2014 17:01:24 -0400 Subject: [PATCH 13/31] just strip the '.' from uniqid with added entropy. this way we dont run into any md5 collisions. --- src/Ratchet/Wamp/WampConnection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ratchet/Wamp/WampConnection.php b/src/Ratchet/Wamp/WampConnection.php index a12b162..8364efd 100644 --- a/src/Ratchet/Wamp/WampConnection.php +++ b/src/Ratchet/Wamp/WampConnection.php @@ -17,7 +17,7 @@ class WampConnection extends AbstractConnectionDecorator { parent::__construct($conn); $this->WAMP = new \StdClass; - $this->WAMP->sessionId = md5(uniqid(mt_rand(), true)); + $this->WAMP->sessionId = str_replace('.','',uniqid(mt_rand(), true)); $this->WAMP->prefixes = array(); $this->send(json_encode(array(WAMP::MSG_WELCOME, $this->WAMP->sessionId, 1, \Ratchet\VERSION))); From 3240c87733b35ebb461a3d5fe9b8e7b5897fe70e Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Sun, 19 Oct 2014 12:21:32 -0400 Subject: [PATCH 14/31] Fragmented Hixie76 body test. refs #238 --- tests/unit/WebSocket/Version/Hixie76Test.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/unit/WebSocket/Version/Hixie76Test.php b/tests/unit/WebSocket/Version/Hixie76Test.php index d09cdf7..75998aa 100644 --- a/tests/unit/WebSocket/Version/Hixie76Test.php +++ b/tests/unit/WebSocket/Version/Hixie76Test.php @@ -80,4 +80,24 @@ class Hixie76Test extends \PHPUnit_Framework_TestCase { $mockApp->expects($this->once())->method('onOpen'); $server->onMessage($mockConn, $body . $this->_crlf . $this->_crlf); } + + public function testTcpFragmentedBodyUpgrade() { + $headers = $this->headerProvider(); + $body = base64_decode($this->_body); + $body1 = substr($body, 0, 4); + $body2 = substr($body, 4); + + $mockConn = $this->getMock('\Ratchet\ConnectionInterface'); + $mockApp = $this->getMock('\Ratchet\MessageComponentInterface'); + + $server = new HttpServer(new WsServer($mockApp)); + $server->onOpen($mockConn); + $server->onMessage($mockConn, $headers); + + $mockApp->expects($this->once())->method('onOpen'); + + $server->onMessage($mockConn, $body1); + $server->onMessage($mockConn, $body2); + $server->onMessage($mockConn, $this->_crlf . $this->_crlf); + } } From c179d60e77a9f370d278285c95eb34464687c862 Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Sun, 23 Nov 2014 11:40:06 -0500 Subject: [PATCH 15/31] Formatting, removed flash check --- src/Ratchet/App.php | 34 ++++++++++------------------- src/Ratchet/Wamp/ServerProtocol.php | 1 - src/Ratchet/Wamp/WampConnection.php | 25 ++++++++++----------- tests/unit/Wamp/TopicTest.php | 2 +- 4 files changed, 24 insertions(+), 38 deletions(-) diff --git a/src/Ratchet/App.php b/src/Ratchet/App.php index 4755560..4e44663 100644 --- a/src/Ratchet/App.php +++ b/src/Ratchet/App.php @@ -42,12 +42,12 @@ class App { * @var string */ protected $httpHost; - + /*** * The port the socket is listening * @var int */ - protected $port; + protected $port; /** * @var int @@ -87,22 +87,10 @@ class App { $policy->addAllowedAccess($httpHost, $port); $flashSock = new Reactor($loop); $this->flashServer = new IoServer($policy, $flashSock); - - //check if another App is already running a flash policy server on 843 - $test = @fsockopen('127.0.0.1', 843, $errno, $errstr, 5); - - //if not start a flash policy serever - if(is_resource($test) === false){ - $policy = new FlashPolicy; - $policy->addAllowedAccess($httpHost, 80); - $policy->addAllowedAccess($httpHost, $port); - $flashSock = new Reactor($loop); - $this->flashServer = new IoServer($policy, $flashSock); - - $flashSock->listen(843, '0.0.0.0'); - }else{ - fclose($test); - trigger_error('flash socket server already running on 843', E_USER_NOTICE); + if (80 == $port) { + $flashSock->listen(843, '0.0.0.0'); + } else { + $flashSock->listen(8843); } } @@ -136,12 +124,12 @@ class App { if ('*' !== $allowedOrigins[0]) { $decorated = new OriginCheck($decorated, $allowedOrigins); } - + //allow origins in flash policy server - if(empty($this->flashServer) === false){ - foreach($allowedOrigins as $allowedOrgin){ - $this->flashServer->app->addAllowedAccess($allowedOrgin, $this->port); - } + if(empty($this->flashServer) === false) { + foreach($allowedOrigins as $allowedOrgin) { + $this->flashServer->app->addAllowedAccess($allowedOrgin, $this->port); + } } $this->routes->add('rr-' . ++$this->_routeCounter, new Route($path, array('_controller' => $decorated), array('Origin' => $this->httpHost), array(), $httpHost)); diff --git a/src/Ratchet/Wamp/ServerProtocol.php b/src/Ratchet/Wamp/ServerProtocol.php index 0bddc83..28badd3 100644 --- a/src/Ratchet/Wamp/ServerProtocol.php +++ b/src/Ratchet/Wamp/ServerProtocol.php @@ -107,7 +107,6 @@ class ServerProtocol implements MessageComponentInterface, WsServerInterface { $json = $json[0]; } - //procURI should be un prefixed $this->_decorating->onCall($from, $callID, $from->getUri($procURI), $json); break; diff --git a/src/Ratchet/Wamp/WampConnection.php b/src/Ratchet/Wamp/WampConnection.php index 8364efd..64590a0 100644 --- a/src/Ratchet/Wamp/WampConnection.php +++ b/src/Ratchet/Wamp/WampConnection.php @@ -17,7 +17,7 @@ class WampConnection extends AbstractConnectionDecorator { parent::__construct($conn); $this->WAMP = new \StdClass; - $this->WAMP->sessionId = str_replace('.','',uniqid(mt_rand(), true)); + $this->WAMP->sessionId = str_replace('.', '', uniqid(mt_rand(), true)); $this->WAMP->prefixes = array(); $this->send(json_encode(array(WAMP::MSG_WELCOME, $this->WAMP->sessionId, 1, \Ratchet\VERSION))); @@ -77,24 +77,23 @@ class WampConnection extends AbstractConnectionDecorator { /** * Get the full request URI from the connection object if a prefix has been established for it - * Compliant with WAMP Spec for curie URIs * @param string $uri * @return string */ public function getUri($uri) { - $curieSeperator = ':'; - $fullSeperator = '#'; - - if(preg_match('/http(s*)\:\/\//', $uri) == false){ - if(strpos($uri, $curieSeperator) !== false){ - list($prefix, $action) = explode($curieSeperator, $uri); - $expandedPrefix = isset($this->WAMP->prefixes[$prefix]) ? $this->WAMP->prefixes[$prefix] : $prefix; + $curieSeperator = ':'; + $fullSeperator = '#'; - return $expandedPrefix . $fullSeperator . $action; + if (preg_match('/http(s*)\:\/\//', $uri) == false) { + if (strpos($uri, $curieSeperator) !== false) { + list($prefix, $action) = explode($curieSeperator, $uri); + $expandedPrefix = isset($this->WAMP->prefixes[$prefix]) ? $this->WAMP->prefixes[$prefix] : $prefix; + + return $expandedPrefix . $fullSeperator . $action; + } } - } - - return $uri; + + return $uri; } /** diff --git a/tests/unit/Wamp/TopicTest.php b/tests/unit/Wamp/TopicTest.php index 26db0d3..b8685b7 100644 --- a/tests/unit/Wamp/TopicTest.php +++ b/tests/unit/Wamp/TopicTest.php @@ -81,7 +81,7 @@ class TopicTest extends \PHPUnit_Framework_TestCase { $topic->add($first); $topic->add($second); $topic->add($third); - + $topic->broadcast($msg, array($second->WAMP->sessionId)); } From f4fe5c9d99bcfc203ee7127d627160f30583a59b Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Sat, 29 Nov 2014 10:30:09 -0500 Subject: [PATCH 16/31] [sess] Attempt to fix Symfony 2.6 PDO error --- tests/unit/Session/SessionComponentTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/Session/SessionComponentTest.php b/tests/unit/Session/SessionComponentTest.php index c91f13e..7d36735 100644 --- a/tests/unit/Session/SessionComponentTest.php +++ b/tests/unit/Session/SessionComponentTest.php @@ -72,6 +72,7 @@ class SessionProviderTest extends AbstractMessageComponentTestCase { , 'db_id_col' => 'sess_id' , 'db_data_col' => 'sess_data' , 'db_time_col' => 'sess_time' + , 'db_lifetime_col' => 'sess_lifetime' ); $pdo = new \PDO("sqlite::memory:"); From 47123de527a6bc0a76db052aed76653f2f2176ac Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Sat, 29 Nov 2014 11:09:02 -0500 Subject: [PATCH 17/31] Fixed unit test for Symfony 2.6 --- tests/unit/Session/SessionComponentTest.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/unit/Session/SessionComponentTest.php b/tests/unit/Session/SessionComponentTest.php index 7d36735..7f91639 100644 --- a/tests/unit/Session/SessionComponentTest.php +++ b/tests/unit/Session/SessionComponentTest.php @@ -77,10 +77,12 @@ class SessionProviderTest extends AbstractMessageComponentTestCase { $pdo = new \PDO("sqlite::memory:"); $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); - $pdo->exec(vsprintf("CREATE TABLE %s (%s VARCHAR(255) PRIMARY KEY, %s TEXT, %s INTEGER)", $dbOptions)); - $pdo->prepare(vsprintf("INSERT INTO %s (%s, %s, %s) VALUES (?, ?, ?)", $dbOptions))->execute(array($sessionId, base64_encode('_sf2_attributes|a:2:{s:5:"hello";s:5:"world";s:4:"last";i:1332872102;}_sf2_flashes|a:0:{}'), time())); + $pdo->exec(vsprintf("CREATE TABLE %s (%s TEXT NOT NULL PRIMARY KEY, %s BLOB NOT NULL, %s INTEGER NOT NULL, %s INTEGER)", $dbOptions)); - $component = new SessionProvider($this->getMock('Ratchet\\MessageComponentInterface'), new PdoSessionHandler($pdo, $dbOptions), array('auto_start' => 1)); + $pdoHandler = new PdoSessionHandler($pdo, $dbOptions); + $pdoHandler->write($sessionId, '_sf2_attributes|a:2:{s:5:"hello";s:5:"world";s:4:"last";i:1332872102;}_sf2_flashes|a:0:{}'); + + $component = new SessionProvider($this->getMock('Ratchet\\MessageComponentInterface'), $pdoHandler, array('auto_start' => 1)); $connection = $this->getMock('Ratchet\\ConnectionInterface'); $headers = $this->getMock('Guzzle\\Http\\Message\\Request', array('getCookie'), array('POST', '/', array())); From c167b476b817500f2a6fd32291629b88e815eea6 Mon Sep 17 00:00:00 2001 From: Hannes Van De Vreken Date: Sat, 27 Dec 2014 11:09:41 +0100 Subject: [PATCH 18/31] Typo endpiont -> endpoint --- src/Ratchet/App.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Ratchet/App.php b/src/Ratchet/App.php index 4e44663..b7d0e55 100644 --- a/src/Ratchet/App.php +++ b/src/Ratchet/App.php @@ -95,7 +95,7 @@ class App { } /** - * Add an endpiont/application to the server + * Add an endpoint/application to the server * @param string $path The URI the client will connect to * @param ComponentInterface $controller Your application to server for the route. If not specified, assumed to be for a WebSocket * @param array $allowedOrigins An array of hosts allowed to connect (same host by default), ['*'] for any @@ -143,4 +143,4 @@ class App { public function run() { $this->_server->run(); } -} \ No newline at end of file +} From 7798571db96469c10b3de4e22f078d7293a8d72b Mon Sep 17 00:00:00 2001 From: Bob van de Vijver Date: Wed, 21 Jan 2015 02:12:05 +0100 Subject: [PATCH 19/31] Remove unneeded catch The second JsonException catch in not necessary, and can be removed. --- src/Ratchet/Wamp/WampServer.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Ratchet/Wamp/WampServer.php b/src/Ratchet/Wamp/WampServer.php index 8fb9e65..f0675a3 100644 --- a/src/Ratchet/Wamp/WampServer.php +++ b/src/Ratchet/Wamp/WampServer.php @@ -41,8 +41,6 @@ class WampServer implements MessageComponentInterface, WsServerInterface { $this->wampProtocol->onMessage($conn, $msg); } catch (Exception $we) { $conn->close(1007); - } catch (JsonException $je) { - $conn->close(1007); } } From 8f4cac00cc6de7200f19b0614991cea4af1ef440 Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Sun, 24 May 2015 16:02:24 -0400 Subject: [PATCH 20/31] misc: PHP "7", deps, license --- .travis.yml | 1 + LICENSE | 2 +- composer.json | 8 ++++---- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index a9dea98..f0b9273 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ php: - 5.4 - 5.5 - 5.6 + - 7 - hhvm before_script: diff --git a/LICENSE b/LICENSE index 66857ea..293a211 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2011-2014 Chris Boden +Copyright (c) 2011-2015 Chris Boden Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/composer.json b/composer.json index 2092cc1..6096381 100644 --- a/composer.json +++ b/composer.json @@ -24,9 +24,9 @@ } , "require": { "php": ">=5.3.9" - , "react/socket": "0.3.*|0.4.*" - , "guzzle/http": "~3.6" - , "symfony/http-foundation": "~2.2" - , "symfony/routing": "~2.2" + , "react/socket": "^0.3 || ^0.4" + , "guzzle/http": "^3.6" + , "symfony/http-foundation": "^2.2" + , "symfony/routing": "^2.2" } } From db8814718dfacd964a0683c569ccbb1aae09ad7a Mon Sep 17 00:00:00 2001 From: matt Date: Mon, 25 May 2015 17:05:40 -0400 Subject: [PATCH 21/31] Fix and test for uncommon payload length issue --- .../WebSocket/Version/RFC6455/Frame.php | 1 + .../WebSocket/Version/RFC6455/FrameTest.php | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/Ratchet/WebSocket/Version/RFC6455/Frame.php b/src/Ratchet/WebSocket/Version/RFC6455/Frame.php index 1a92c1f..77d1258 100644 --- a/src/Ratchet/WebSocket/Version/RFC6455/Frame.php +++ b/src/Ratchet/WebSocket/Version/RFC6455/Frame.php @@ -379,6 +379,7 @@ class Frame implements FrameInterface { $byte_length = $this->getNumPayloadBytes(); if ($this->bytesRecvd < 1 + $byte_length) { + $this->defPayLen = -1; throw new \UnderflowException('Not enough data buffered to determine payload length'); } diff --git a/tests/unit/WebSocket/Version/RFC6455/FrameTest.php b/tests/unit/WebSocket/Version/RFC6455/FrameTest.php index 7f56a6e..eff9513 100644 --- a/tests/unit/WebSocket/Version/RFC6455/FrameTest.php +++ b/tests/unit/WebSocket/Version/RFC6455/FrameTest.php @@ -500,4 +500,44 @@ class FrameTest extends \PHPUnit_Framework_TestCase { return $randomString; } + + /** + * There was a frame boundary issue when the first 3 bytes of a frame with a payload greater than + * 126 was added to the frame buffer and then Frame::getPayloadLength was called. It would cause the frame + * to set the payload length to 126 and then not recalculate it once the full length information was available. + * + * This is fixed by setting the defPayLen back to -1 before the underflow exception is thrown. + * + * @covers Ratchet\WebSocket\Version\RFC6455\Frame::getPayloadLength + * @covers Ratchet\WebSocket\Version\RFC6455\Frame::extractOverflow + */ + public function testFrameDeliveredOneByteAtATime() { + $startHeader = "\x01\x7e\x01\x00"; // header for a text frame of 256 - non-final + $framePayload = str_repeat("*", 256); + $rawOverflow = "xyz"; + $rawFrame = $startHeader . $framePayload . $rawOverflow; + + $frame = new Frame(); + $payloadLen = 256; + + for ($i = 0; $i < strlen($rawFrame); $i++) { + $frame->addBuffer($rawFrame[$i]); + + try { + // payloadLen will + $payloadLen = $frame->getPayloadLength(); + } catch (\UnderflowException $e) { + if ($i > 2) { // we should get an underflow on 0,1,2 + $this->fail("Underflow exception when the frame length should be available"); + } + } + + if ($payloadLen !== 256) { + $this->fail("Payload length of " . $payloadLen . " should have been 256."); + } + } + + // make sure the overflow is good + $this->assertEquals($rawOverflow, $frame->extractOverflow()); + } } From 6b247c05251b4b5cbd14243366b649f99a0e5681 Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Wed, 27 May 2015 08:51:05 -0400 Subject: [PATCH 22/31] PSR-4, v0.3.3 --- CHANGELOG.md | 8 ++++++++ composer.json | 4 ++-- src/Ratchet/ConnectionInterface.php | 2 +- tests/bootstrap.php | 3 +-- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1585c2..ec240e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,14 @@ CHANGELOG --- +* 0.3.3 (2015-05-26) + +* BF: Framing bug on large messages upon TCP fragmentation +* BF: Symfony Router query parameter defaults applied to Request +* BF: WAMP CURIE on all URIs +* OriginCheck rules applied to FlashPolicy +* Switched from PSR-0 to PSR-4 + * 0.3.2 (2014-06-08) * BF: No messages after closing handshake (fixed rare race condition causing 100% CPU) diff --git a/composer.json b/composer.json index 6096381..c4a7809 100644 --- a/composer.json +++ b/composer.json @@ -18,8 +18,8 @@ , "irc": "irc://irc.freenode.org/reactphp" } , "autoload": { - "psr-0": { - "Ratchet": "src" + "psr-4": { + "Ratchet\\": "src/Ratchet" } } , "require": { diff --git a/src/Ratchet/ConnectionInterface.php b/src/Ratchet/ConnectionInterface.php index 594e339..c8c4e1c 100644 --- a/src/Ratchet/ConnectionInterface.php +++ b/src/Ratchet/ConnectionInterface.php @@ -5,7 +5,7 @@ namespace Ratchet; * The version of Ratchet being used * @var string */ -const VERSION = 'Ratchet/0.3.2'; +const VERSION = 'Ratchet/0.3.3'; /** * A proxy object representing a connection to the application diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 9d21c77..40791ba 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,5 +1,4 @@ add('Ratchet', __DIR__ . '/helpers'); - $loader->register(); + $loader->addPsr4('Ratchet\\', __DIR__ . '/helpers/Ratchet'); From 259d384bcf347ca51792e2961d2ec74ff5e6d8b3 Mon Sep 17 00:00:00 2001 From: Ben Connito Date: Mon, 8 Jun 2015 09:29:21 -0400 Subject: [PATCH 23/31] if a CURIE prefix has not been defined, do not convert the URI from CURIE to URI. per @attozk comment --- src/Ratchet/Wamp/WampConnection.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Ratchet/Wamp/WampConnection.php b/src/Ratchet/Wamp/WampConnection.php index 64590a0..3b8f93e 100644 --- a/src/Ratchet/Wamp/WampConnection.php +++ b/src/Ratchet/Wamp/WampConnection.php @@ -82,14 +82,12 @@ class WampConnection extends AbstractConnectionDecorator { */ public function getUri($uri) { $curieSeperator = ':'; - $fullSeperator = '#'; if (preg_match('/http(s*)\:\/\//', $uri) == false) { - if (strpos($uri, $curieSeperator) !== false) { + if (strpos($uri, $curieSeperator) !== false && isset($this->WAMP->prefixes[$prefix]) === true) { list($prefix, $action) = explode($curieSeperator, $uri); - $expandedPrefix = isset($this->WAMP->prefixes[$prefix]) ? $this->WAMP->prefixes[$prefix] : $prefix; - return $expandedPrefix . $fullSeperator . $action; + return $this->WAMP->prefixes[$prefix] . '#' . $action; } } From ddec2cb313f1cba3a31e8c8ea230dfa0a73dba2f Mon Sep 17 00:00:00 2001 From: Ben Connito Date: Mon, 8 Jun 2015 09:49:36 -0400 Subject: [PATCH 24/31] oops! fix using $prefix before it was defined. --- src/Ratchet/Wamp/WampConnection.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Ratchet/Wamp/WampConnection.php b/src/Ratchet/Wamp/WampConnection.php index 3b8f93e..dda1e4e 100644 --- a/src/Ratchet/Wamp/WampConnection.php +++ b/src/Ratchet/Wamp/WampConnection.php @@ -84,10 +84,12 @@ class WampConnection extends AbstractConnectionDecorator { $curieSeperator = ':'; if (preg_match('/http(s*)\:\/\//', $uri) == false) { - if (strpos($uri, $curieSeperator) !== false && isset($this->WAMP->prefixes[$prefix]) === true) { + if (strpos($uri, $curieSeperator) !== false) { list($prefix, $action) = explode($curieSeperator, $uri); - - return $this->WAMP->prefixes[$prefix] . '#' . $action; + + if(isset($this->WAMP->prefixes[$prefix]) === true){ + return $this->WAMP->prefixes[$prefix] . '#' . $action; + } } } From f6294e25c987563823ce5d716be689a6df7e6a34 Mon Sep 17 00:00:00 2001 From: Klein Thomas Date: Sat, 4 Jul 2015 18:38:10 +0200 Subject: [PATCH 25/31] Removed special @temporary annotation --- src/Ratchet/WebSocket/WsServerInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ratchet/WebSocket/WsServerInterface.php b/src/Ratchet/WebSocket/WsServerInterface.php index 03b0710..15d1f7b 100644 --- a/src/Ratchet/WebSocket/WsServerInterface.php +++ b/src/Ratchet/WebSocket/WsServerInterface.php @@ -8,7 +8,7 @@ interface WsServerInterface { /** * If any component in a stack supports a WebSocket sub-protocol return each supported in an array * @return array - * @temporary This method may be removed in future version (note that will not break code, just make some code obsolete) + * @todo This method may be removed in future version (note that will not break code, just make some code obsolete) */ function getSubProtocols(); } From 6cc97ab44539a805e1bca561e389d8b1e6f7af95 Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Wed, 15 Jul 2015 11:29:06 -0400 Subject: [PATCH 26/31] Attempt handshake after adding to buffer --- src/Ratchet/WebSocket/WsServer.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Ratchet/WebSocket/WsServer.php b/src/Ratchet/WebSocket/WsServer.php index b4be1f0..5783789 100644 --- a/src/Ratchet/WebSocket/WsServer.php +++ b/src/Ratchet/WebSocket/WsServer.php @@ -102,14 +102,14 @@ class WsServer implements HttpServerInterface { protected function attemptUpgrade(ConnectionInterface $conn, $data = '') { if ('' !== $data) { $conn->WebSocket->request->getBody()->write($data); - } else { - if (!$this->versioner->isVersionEnabled($conn->WebSocket->request)) { - return $this->close($conn); - } - - $conn->WebSocket->version = $this->versioner->getVersion($conn->WebSocket->request); } + if (!$this->versioner->isVersionEnabled($conn->WebSocket->request)) { + return $this->close($conn); + } + + $conn->WebSocket->version = $this->versioner->getVersion($conn->WebSocket->request); + try { $response = $conn->WebSocket->version->handshake($conn->WebSocket->request); } catch (\UnderflowException $e) { From 39882fbb16d04fefb63ed91a3dc52a767219fdbe Mon Sep 17 00:00:00 2001 From: Sebastian Kroczek Date: Tue, 25 Aug 2015 13:32:30 +0200 Subject: [PATCH 27/31] Fixes VirtualSessionStorage with pdo_sqlite as storage --- .../Session/Storage/VirtualSessionStorage.php | 6 ++ .../Storage/VirtualSessionStoragePDOTest.php | 58 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 tests/unit/Session/Storage/VirtualSessionStoragePDOTest.php diff --git a/src/Ratchet/Session/Storage/VirtualSessionStorage.php b/src/Ratchet/Session/Storage/VirtualSessionStorage.php index 9fb0eb7..daa10bb 100644 --- a/src/Ratchet/Session/Storage/VirtualSessionStorage.php +++ b/src/Ratchet/Session/Storage/VirtualSessionStorage.php @@ -30,6 +30,12 @@ class VirtualSessionStorage extends NativeSessionStorage { return true; } + // You have to call Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler::open() to use + // pdo_sqlite (and possible pdo_*) as session storage, if you are using a DSN string instead of a \PDO object + // in the constructor. The method arguments are filled with the values, which are also used by the symfony + // framework in this case. This must not be the best choice, but it works. + $this->saveHandler->open(session_save_path(), session_name()); + $rawData = $this->saveHandler->read($this->saveHandler->getId()); $sessionData = $this->_serializer->unserialize($rawData); diff --git a/tests/unit/Session/Storage/VirtualSessionStoragePDOTest.php b/tests/unit/Session/Storage/VirtualSessionStoragePDOTest.php new file mode 100644 index 0000000..9909bce --- /dev/null +++ b/tests/unit/Session/Storage/VirtualSessionStoragePDOTest.php @@ -0,0 +1,58 @@ +_pathToDB = tempnam(sys_get_temp_dir(), 'SQ3');; + $dsn = 'sqlite:' . $this->_pathToDB; + + $pdo = new \PDO($dsn); + $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); + $pdo->exec($schema); + $pdo = null; + + $sessionHandler = new PdoSessionHandler($dsn); + $serializer = new PhpHandler(); + $this->_virtualSessionStorage = new VirtualSessionStorage($sessionHandler, 'foobar', $serializer); + $this->_virtualSessionStorage->registerBag(new FlashBag()); + $this->_virtualSessionStorage->registerBag(new AttributeBag()); + } + + public function tearDown() + { + unlink($this->_pathToDB); + } + + public function testStartWithDSN() + { + $this->_virtualSessionStorage->start(); + + $this->assertTrue($this->_virtualSessionStorage->isStarted()); + } + + +} From cf2da8631ee0c2eb913d92ad3ada0e39a84fbe77 Mon Sep 17 00:00:00 2001 From: thpl Date: Tue, 22 Dec 2015 00:14:36 +0100 Subject: [PATCH 28/31] Added composer.json requirement for symfony/routing at version 3.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c4a7809..0f25ed0 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,6 @@ , "react/socket": "^0.3 || ^0.4" , "guzzle/http": "^3.6" , "symfony/http-foundation": "^2.2" - , "symfony/routing": "^2.2" + , "symfony/routing": "^2.2|^3.0" } } From 1e6c6946ac2633964ecb740ee76dabe39eaf3559 Mon Sep 17 00:00:00 2001 From: thpl Date: Tue, 22 Dec 2015 00:14:54 +0100 Subject: [PATCH 29/31] Added composer.json requirement for symfony/http-foundation at version 3.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 0f25ed0..80a3aa5 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "php": ">=5.3.9" , "react/socket": "^0.3 || ^0.4" , "guzzle/http": "^3.6" - , "symfony/http-foundation": "^2.2" + , "symfony/http-foundation": "^2.2|^3.0" , "symfony/routing": "^2.2|^3.0" } } From 80bfbd0568535c9fc689ffd62b0e26b19bdac7d2 Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Wed, 23 Dec 2015 09:54:30 -0500 Subject: [PATCH 30/31] v0.3.4 prep --- CHANGELOG.md | 19 +++++++++++++------ LICENSE | 2 +- src/Ratchet/ConnectionInterface.php | 2 +- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec240e1..9ee7f13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,13 +8,20 @@ CHANGELOG --- +* 0.3.4 (2015-12-23) + + * BF: Edge case where version check wasn't run on message coalesce + * BF: Session didn't start when using pdo_sqlite + * BF: WAMP currie prefix check when using '#' + * Compatibility with Symfony 3 + * 0.3.3 (2015-05-26) -* BF: Framing bug on large messages upon TCP fragmentation -* BF: Symfony Router query parameter defaults applied to Request -* BF: WAMP CURIE on all URIs -* OriginCheck rules applied to FlashPolicy -* Switched from PSR-0 to PSR-4 + * BF: Framing bug on large messages upon TCP fragmentation + * BF: Symfony Router query parameter defaults applied to Request + * BF: WAMP CURIE on all URIs + * OriginCheck rules applied to FlashPolicy + * Switched from PSR-0 to PSR-4 * 0.3.2 (2014-06-08) @@ -119,4 +126,4 @@ CHANGELOG * 0.1 (2012-05-11) * First release with components: IoServer, WsServer, SessionProvider, WampServer, FlashPolicy, IpBlackList - * I/O now handled by React, making Ratchet fully asynchronous \ No newline at end of file + * I/O now handled by React, making Ratchet fully asynchronous diff --git a/LICENSE b/LICENSE index 293a211..7f8c128 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2011-2015 Chris Boden +Copyright (c) 2011-2016 Chris Boden Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/src/Ratchet/ConnectionInterface.php b/src/Ratchet/ConnectionInterface.php index c8c4e1c..5c07a2d 100644 --- a/src/Ratchet/ConnectionInterface.php +++ b/src/Ratchet/ConnectionInterface.php @@ -5,7 +5,7 @@ namespace Ratchet; * The version of Ratchet being used * @var string */ -const VERSION = 'Ratchet/0.3.3'; +const VERSION = 'Ratchet/0.3.4'; /** * A proxy object representing a connection to the application From 5937851faca4d39d51e4fd74b956be46188de590 Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Wed, 17 Feb 2016 17:29:03 -0500 Subject: [PATCH 31/31] Skip PDO test if extension missing --- .../Storage/VirtualSessionStoragePDOTest.php | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/tests/unit/Session/Storage/VirtualSessionStoragePDOTest.php b/tests/unit/Session/Storage/VirtualSessionStoragePDOTest.php index 9909bce..2727484 100644 --- a/tests/unit/Session/Storage/VirtualSessionStoragePDOTest.php +++ b/tests/unit/Session/Storage/VirtualSessionStoragePDOTest.php @@ -1,15 +1,11 @@ markTestSkipped('Session test requires PDO and pdo_sqlite'); + } + $schema = <<_virtualSessionStorage->registerBag(new AttributeBag()); } - public function tearDown() - { + public function tearDown() { unlink($this->_pathToDB); } - public function testStartWithDSN() - { + public function testStartWithDSN() { $this->_virtualSessionStorage->start(); $this->assertTrue($this->_virtualSessionStorage->isStarted()); } - - }