Close connection if invalid topic

This commit is contained in:
Chris Boden 2017-10-14 21:19:07 -04:00
parent 810429a6fe
commit 309564cbf1
2 changed files with 13 additions and 5 deletions

View File

@ -94,7 +94,7 @@ class ServerProtocol implements MessageComponentInterface, WsServerInterface {
} }
if (isset($json[1]) && !is_string($json[1])) { 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]) { switch ($json[0]) {

View File

@ -267,21 +267,29 @@ class ServerProtocolTest extends \PHPUnit_Framework_TestCase {
} }
public function testBadClientInputFromNonStringTopic() { public function testBadClientInputFromNonStringTopic() {
$this->setExpectedException('\Ratchet\Wamp\Exception');
$conn = new WampConnection($this->newConn()); $conn = new WampConnection($this->newConn());
$this->_comp->onOpen($conn); $this->_comp->onOpen($conn);
$this->_comp->onMessage($conn, json_encode([5, ['hells', 'nope']])); $this->_comp->onMessage($conn, json_encode([5, ['hells', 'nope']]));
$this->assertEquals('["hells","nope"]', $this->_app->last['onSubscribe'][1]);
} }
public function testBadPrefixWithNonStringTopic() { public function testBadPrefixWithNonStringTopic() {
$this->setExpectedException('\Ratchet\Wamp\Exception');
$conn = new WampConnection($this->newConn()); $conn = new WampConnection($this->newConn());
$this->_comp->onOpen($conn); $this->_comp->onOpen($conn);
$this->_comp->onMessage($conn, json_encode([1, ['hells', 'nope'], ['bad', 'input']])); $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']));
} }
} }