diff --git a/src/Ratchet/ConnectionInterface.php b/src/Ratchet/ConnectionInterface.php index cc4d74b..088823d 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.2.5'; +const VERSION = 'Ratchet/0.3-beta'; /** * A proxy object representing a connection to the application diff --git a/src/Ratchet/Http/HttpServer.php b/src/Ratchet/Http/HttpServer.php index d4e8967..5788807 100644 --- a/src/Ratchet/Http/HttpServer.php +++ b/src/Ratchet/Http/HttpServer.php @@ -29,14 +29,14 @@ class HttpServer implements MessageComponentInterface { } /** - * @{inheritdoc} + * {@inheritdoc} */ public function onOpen(ConnectionInterface $conn) { $conn->httpHeadersReceived = false; } /** - * @{inheritdoc} + * {@inheritdoc} */ public function onMessage(ConnectionInterface $from, $msg) { if (true !== $from->httpHeadersReceived) { @@ -57,7 +57,7 @@ class HttpServer implements MessageComponentInterface { } /** - * @{inheritdoc} + * {@inheritdoc} */ public function onClose(ConnectionInterface $conn) { if ($conn->httpHeadersReceived) { @@ -66,7 +66,7 @@ class HttpServer implements MessageComponentInterface { } /** - * @{inheritdoc} + * {@inheritdoc} */ public function onError(ConnectionInterface $conn, \Exception $e) { if ($conn->httpHeadersReceived) { diff --git a/src/Ratchet/Session/SessionProvider.php b/src/Ratchet/Session/SessionProvider.php index b2c549b..9cd4dd3 100644 --- a/src/Ratchet/Session/SessionProvider.php +++ b/src/Ratchet/Session/SessionProvider.php @@ -42,7 +42,7 @@ class SessionProvider implements MessageComponentInterface, WsServerInterface { * @param \SessionHandlerInterface $handler * @param array $options * @param \Ratchet\Session\Serialize\HandlerInterface $serializer - * @throws \RuntimeExcpetion + * @throws \RuntimeException */ public function __construct(MessageComponentInterface $app, \SessionHandlerInterface $handler, array $options = array(), HandlerInterface $serializer = null) { $this->_app = $app; diff --git a/src/Ratchet/WebSocket/Version/RFC6455/HandshakeVerifier.php b/src/Ratchet/WebSocket/Version/RFC6455/HandshakeVerifier.php index 7fbf452..ea17d08 100644 --- a/src/Ratchet/WebSocket/Version/RFC6455/HandshakeVerifier.php +++ b/src/Ratchet/WebSocket/Version/RFC6455/HandshakeVerifier.php @@ -113,22 +113,6 @@ class HandshakeVerifier { return (16 === strlen(base64_decode((string)$val))); } - /** - * Verify Origin matches RFC6454 IF it is set - * Origin is an optional field - * @param string|null - * @return bool - * @todo Implement verification functionality - see section 4.2.1.7 - */ - public function verifyOrigin($val) { - if (null === $val) { - return true; - } - - // logic here - return true; - } - /** * Verify the version passed matches this RFC * @param string|int MUST equal 13|"13" diff --git a/src/Ratchet/WebSocket/WsServer.php b/src/Ratchet/WebSocket/WsServer.php index 24ea580..0373a14 100644 --- a/src/Ratchet/WebSocket/WsServer.php +++ b/src/Ratchet/WebSocket/WsServer.php @@ -216,7 +216,6 @@ class WsServer implements HttpServerInterface { * Close a connection with an HTTP response * @param \Ratchet\ConnectionInterface $conn * @param int $code HTTP status code - * @return void */ protected function close(ConnectionInterface $conn, $code = 400) { $response = new Response($code, array( diff --git a/tests/Ratchet/Tests/Http/HtpRequestParserTest.php b/tests/Ratchet/Tests/Http/HttpRequestParserTest.php similarity index 78% rename from tests/Ratchet/Tests/Http/HtpRequestParserTest.php rename to tests/Ratchet/Tests/Http/HttpRequestParserTest.php index 4de396c..3a540ec 100644 --- a/tests/Ratchet/Tests/Http/HtpRequestParserTest.php +++ b/tests/Ratchet/Tests/Http/HttpRequestParserTest.php @@ -31,7 +31,7 @@ class HttpRequestParserTest extends \PHPUnit_Framework_TestCase { } public function testBufferOverflowResponse() { - $conn = $this->getMock('\\Ratchet\\ConnectionInterface'); + $conn = $this->getMock('\Ratchet\ConnectionInterface'); $this->parser->maxSize = 20; @@ -41,4 +41,11 @@ class HttpRequestParserTest extends \PHPUnit_Framework_TestCase { $this->parser->onMessage($conn, "Header-Is: Too Big"); } + + public function testReturnTypeIsRequest() { + $conn = $this->getMock('\Ratchet\ConnectionInterface'); + $return = $this->parser->onMessage($conn, "GET / HTTP/1.1\r\nHost: socketo.me\r\n\r\n"); + + $this->assertInstanceOf('\Guzzle\Http\Message\RequestInterface', $return); + } } \ No newline at end of file diff --git a/tests/Ratchet/Tests/Http/HttpServerTest.php b/tests/Ratchet/Tests/Http/HttpServerTest.php index c7fef74..203172a 100644 --- a/tests/Ratchet/Tests/Http/HttpServerTest.php +++ b/tests/Ratchet/Tests/Http/HttpServerTest.php @@ -30,4 +30,35 @@ class HttpServerTest extends AbstractMessageComponentTestCase { $this->_app->expects($this->once())->method('onOpen')->with($this->isExpectedConnection()); $this->_serv->onMessage($this->_conn, $headers); } + + public function testOnMessageAfterHeaders() { + $headers = "GET / HTTP/1.1\r\nHost: socketo.me\r\n\r\n"; + $this->_conn->httpHeadersReceived = false; + $this->_serv->onMessage($this->_conn, $headers); + + $message = "Hello World!"; + $this->_app->expects($this->once())->method('onMessage')->with($this->isExpectedConnection(), $message); + $this->_serv->onMessage($this->_conn, $message); + } + + public function testBufferOverflow() { + $this->_conn->expects($this->once())->method('close'); + $this->_conn->httpHeadersReceived = false; + + $this->_serv->onMessage($this->_conn, str_repeat('a', 5000)); + } + + public function testCloseIfNotEstablished() { + $this->_conn->httpHeadersReceived = false; + $this->_conn->expects($this->once())->method('close'); + $this->_serv->onError($this->_conn, new \Exception('Whoops!')); + } + + public function testBufferHeaders() { + $this->_conn->httpHeadersReceived = false; + $this->_app->expects($this->never())->method('onOpen'); + $this->_app->expects($this->never())->method('onMessage'); + + $this->_serv->onMessage($this->_conn, "GET / HTTP/1.1"); + } } \ No newline at end of file diff --git a/tests/Ratchet/Tests/Session/SessionComponentTest.php b/tests/Ratchet/Tests/Session/SessionComponentTest.php index 4b4b41d..290e7dd 100644 --- a/tests/Ratchet/Tests/Session/SessionComponentTest.php +++ b/tests/Ratchet/Tests/Session/SessionComponentTest.php @@ -22,6 +22,10 @@ class SessionProviderTest extends AbstractMessageComponentTestCase { $this->_serv = new SessionProvider($this->_app, new NullSessionHandler); } + public function tearDown() { + ini_set('session.serialize_handler', 'php'); + } + public function getConnectionClassString() { return '\Ratchet\ConnectionInterface'; } @@ -89,9 +93,9 @@ class SessionProviderTest extends AbstractMessageComponentTestCase { } protected function newConn() { - $conn = $this->getMock('Ratchet\\ConnectionInterface'); + $conn = $this->getMock('Ratchet\ConnectionInterface'); - $headers = $this->getMock('Guzzle\\Http\\Message\\Request', array('getCookie'), array('POST', '/', array())); + $headers = $this->getMock('Guzzle\Http\Message\Request', array('getCookie'), array('POST', '/', array())); $headers->expects($this->once())->method('getCookie', array(ini_get('session.name')))->will($this->returnValue(null)); $conn->WebSocket = new \StdClass; @@ -100,6 +104,12 @@ class SessionProviderTest extends AbstractMessageComponentTestCase { return $conn; } + public function testOnMessageDecorator() { + $message = "Database calls are usually blocking :("; + $this->_app->expects($this->once())->method('onMessage')->with($this->isExpectedConnection(), $message); + $this->_serv->onMessage($this->_conn, $message); + } + public function testGetSubProtocolsReturnsArray() { $mock = $this->getMock('Ratchet\\MessageComponentInterface'); $comp = new SessionProvider($mock, new NullSessionHandler); @@ -114,4 +124,10 @@ class SessionProviderTest extends AbstractMessageComponentTestCase { $this->assertGreaterThanOrEqual(2, count($comp->getSubProtocols())); } + + public function testRejectInvalidSeralizers() { + ini_set('session.serialize_handler', 'wddx'); + $this->setExpectedException('\RuntimeException'); + new SessionProvider($this->getMock('\Ratchet\MessageComponentInterface'), $this->getMock('\SessionHandlerInterface')); + } } \ No newline at end of file