From 309564cbf11d04d66f01cc02a56180416c305514 Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Sat, 14 Oct 2017 21:19:07 -0400 Subject: [PATCH] Close connection if invalid topic --- src/Ratchet/Wamp/ServerProtocol.php | 2 +- tests/unit/Wamp/ServerProtocolTest.php | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Ratchet/Wamp/ServerProtocol.php b/src/Ratchet/Wamp/ServerProtocol.php index db0e150..97fa868 100644 --- a/src/Ratchet/Wamp/ServerProtocol.php +++ b/src/Ratchet/Wamp/ServerProtocol.php @@ -94,7 +94,7 @@ class ServerProtocol implements MessageComponentInterface, WsServerInterface { } if (isset($json[1]) && !is_string($json[1])) { - $json[1] = json_encode($json[1]); + throw new Exception('Invalid Topic, must be a string'); } switch ($json[0]) { diff --git a/tests/unit/Wamp/ServerProtocolTest.php b/tests/unit/Wamp/ServerProtocolTest.php index e3c6563..8ff68c2 100644 --- a/tests/unit/Wamp/ServerProtocolTest.php +++ b/tests/unit/Wamp/ServerProtocolTest.php @@ -267,21 +267,29 @@ class ServerProtocolTest extends \PHPUnit_Framework_TestCase { } public function testBadClientInputFromNonStringTopic() { + $this->setExpectedException('\Ratchet\Wamp\Exception'); + $conn = new WampConnection($this->newConn()); $this->_comp->onOpen($conn); $this->_comp->onMessage($conn, json_encode([5, ['hells', 'nope']])); - - $this->assertEquals('["hells","nope"]', $this->_app->last['onSubscribe'][1]); } public function testBadPrefixWithNonStringTopic() { + $this->setExpectedException('\Ratchet\Wamp\Exception'); + $conn = new WampConnection($this->newConn()); $this->_comp->onOpen($conn); $this->_comp->onMessage($conn, json_encode([1, ['hells', 'nope'], ['bad', 'input']])); - $this->_comp->onMessage($conn, json_encode([7, ['bad', 'input'], 'Hider'])); + } - $this->assertEquals('["bad","input"]', $this->_app->last['onPublish'][1]); + public function testBadPublishWithNonStringTopic() { + $this->setExpectedException('\Ratchet\Wamp\Exception'); + + $conn = new WampConnection($this->newConn()); + $this->_comp->onOpen($conn); + + $this->_comp->onMessage($conn, json_encode([7, ['bad', 'input'], 'Hider'])); } }