From 2c68b3adb5077604c6919692c0d9ce603788c4ac Mon Sep 17 00:00:00 2001 From: matt Date: Wed, 22 Apr 2015 13:54:06 -0400 Subject: [PATCH] Serialize and deserialize messages for InternalClients plus some fixes --- .../Authentication/AuthenticationManager.php | 2 +- .../Authentication/WampCraAuthProvider.php | 16 +++++++++++++++- .../InternalClientTransportProvider.php | 6 ++++-- tests/WAMP/WampCraTest.php | 2 +- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/Thruway/Authentication/AuthenticationManager.php b/src/Thruway/Authentication/AuthenticationManager.php index 4369298b..15ad07bd 100644 --- a/src/Thruway/Authentication/AuthenticationManager.php +++ b/src/Thruway/Authentication/AuthenticationManager.php @@ -348,7 +348,7 @@ private function onAuthenticateHandler($authMethod, $authMethodInfo, Realm $real $res[1]->authrole = $session->getAuthenticationDetails()->getAuthRole(); $res[1]->authroles = $session->getAuthenticationDetails()->getAuthRoles(); $res[1]->authid = $session->getAuthenticationDetails()->getAuthId(); - if (is_array($res[1])) { + if (is_object($res[1])) { foreach ($res[1] as $k => $v) { $welcomeDetails->$k = $v; } diff --git a/src/Thruway/Authentication/WampCraAuthProvider.php b/src/Thruway/Authentication/WampCraAuthProvider.php index caf6af00..8e5de81e 100644 --- a/src/Thruway/Authentication/WampCraAuthProvider.php +++ b/src/Thruway/Authentication/WampCraAuthProvider.php @@ -4,6 +4,7 @@ use Thruway\Message\HelloMessage; +use Thruway\Message\Message; /** * Class WampCraAuthProvider @@ -40,6 +41,16 @@ public function processHello(array $args) $helloMsg = array_shift($args); $sessionInfo = array_shift($args); + if (!is_array($helloMsg)) { + return ["ERROR"]; + } + + if (!is_object($sessionInfo)) { + return ["ERROR"]; + } + + $helloMsg = Message::createMessageFromArray($helloMsg); + if (!$helloMsg instanceof HelloMessage || !$sessionInfo || !isset($helloMsg->getDetails()->authid) @@ -62,7 +73,10 @@ public function processHello(array $args) $authProvider = "userdb"; $now = new \DateTime(); $timeStamp = $now->format($now::ISO8601); - $sessionId = $sessionInfo['sessionId']; + if (!isset($sessionInfo->sessionId)) { + return ["ERROR"]; + } + $sessionId = $sessionInfo->sessionId; $challenge = [ "authid" => $authid, diff --git a/src/Thruway/Transport/InternalClientTransportProvider.php b/src/Thruway/Transport/InternalClientTransportProvider.php index bd1ff8ab..ca49befe 100644 --- a/src/Thruway/Transport/InternalClientTransportProvider.php +++ b/src/Thruway/Transport/InternalClientTransportProvider.php @@ -6,6 +6,7 @@ use Thruway\Event\ConnectionOpenEvent; use Thruway\Event\RouterStartEvent; use Thruway\Event\RouterStopEvent; +use Thruway\Message\Message; use Thruway\Peer\ClientInterface; use Thruway\Session; @@ -45,13 +46,14 @@ public function handleRouterStart(RouterStartEvent $event) { // create a new transport for the client side to use $clientTransport = new InternalClientTransport(function ($msg) use (&$session) { - $session->dispatchMessage($msg); + $session->dispatchMessage(Message::createMessageFromArray(json_decode(json_encode($msg)))); }, $this->loop); // create a new transport for the router side to use $transport = new InternalClientTransport(function ($msg) use ($clientTransport) { - $this->internalClient->onMessage($clientTransport, $msg); + $this->internalClient->onMessage($clientTransport, + Message::createMessageFromArray(json_decode(json_encode($msg)))); }, $this->loop); $transport->setTrusted($this->trusted); diff --git a/tests/WAMP/WampCraTest.php b/tests/WAMP/WampCraTest.php index f29278d1..88bc9c73 100644 --- a/tests/WAMP/WampCraTest.php +++ b/tests/WAMP/WampCraTest.php @@ -63,9 +63,9 @@ public function testLogin() $conn = new \Thruway\Connection($this->getOptions()); $conn->on('open', function (ClientSession $session, $transport, $details) { + $session->close(); $this->_result = "logged in"; $this->_authid = $details->authid; - $session->close(); }); $conn->on('error', function ($reason) {