public function xtestUnauthorizedActions() { $this->markTestIncomplete("Authorization cannot be tested here and will be moved to a module"); $session = $this->getMockBuilder('\\Thruway\\Session')->disableOriginalConstructor()->setMethods(["sendMessage"])->getMock(); $authorizationManager = $this->getMockBuilder('\\Thruway\\Authentication\\AuthorizationManagerInterface')->getMock(); $realm = new \Thruway\Realm("some_realm"); $realm->setAuthorizationManager($authorizationManager); $subscribeMsg = new \Thruway\Message\SubscribeMessage(\Thruway\Common\Utils::getUniqueId(), [], "some_topic"); $publishMsg = new \Thruway\Message\PublishMessage(\Thruway\Common\Utils::getUniqueId(), (object) ["acknowledge" => true], "some_topic"); $registerMsg = new \Thruway\Message\RegisterMessage(\Thruway\Common\Utils::getUniqueId(), [], 'some_procedure'); $callMsg = new \Thruway\Message\CallMessage(\Thruway\Common\Utils::getUniqueId(), [], "some_procedure"); $authorizationManager->expects($this->exactly(5))->method("isAuthorizedTo")->withConsecutive([$this->isInstanceOf('\\Thruway\\Session'), $this->isInstanceOf('\\Thruway\\Message\\SubscribeMessage')], [$this->isInstanceOf('\\Thruway\\Session'), $this->isInstanceOf('\\Thruway\\Message\\PublishMessage')], [$this->isInstanceOf('\\Thruway\\Session'), $this->isInstanceOf('\\Thruway\\Message\\RegisterMessage')], [$this->isInstanceOf('\\Thruway\\Session'), $this->isInstanceOf('\\Thruway\\Message\\CallMessage')], [$this->isInstanceOf('\\Thruway\\Session'), $this->isInstanceOf('\\Thruway\\Message\\PublishMessage')])->willReturn(false); $errorCheck = function ($msg) { $this->assertInstanceOf('\\Thruway\\Message\\ErrorMessage', $msg); $this->assertEquals('wamp.error.not_authorized', $msg->getErrorUri()); return true; }; $session->expects($this->exactly(5))->method("sendMessage")->withConsecutive([$this->isInstanceOf('\\Thruway\\Message\\WelcomeMessage')], [$this->callback($errorCheck)], [$this->callback($errorCheck)], [$this->callback($errorCheck)], [$this->callback($errorCheck)]); $helloMsg = new \Thruway\Message\HelloMessage("some_realm", []); $realm->onMessage($session, $helloMsg); $realm->onMessage($session, $subscribeMsg); $realm->onMessage($session, $publishMsg); $realm->onMessage($session, $registerMsg); $realm->onMessage($session, $callMsg); // make sure publish doesn't send error back when ack is false $publishMsg2 = $publishMsg = new \Thruway\Message\PublishMessage(\Thruway\Common\Utils::getUniqueId(), [], "some_topic"); $realm->onMessage($session, $publishMsg2); }
/** * This can only happen in an instance where Welcome is not sent immediately after Hello * (when a challenge has been sent) */ public function testJoinSessionTwice() { $realm = new \Thruway\Realm("realm1"); $authMgr = $this->getMockBuilder('\\Thruway\\Authentication\\AuthenticationManagerInterface')->getMock(); $authMgr->expects($this->once())->method("onAuthenticationMessage")->with($this->isInstanceOf('\\Thruway\\Realm'), $this->isInstanceOf('\\Thruway\\Session'), $this->isInstanceOf('\\Thruway\\Message\\HelloMessage')); $realm->setAuthenticationManager($authMgr); $session = $this->getMockBuilder('\\Thruway\\Session')->disableOriginalConstructor()->setMethods(["sendMessage", "shutdown", "abort"])->getMock(); $session->expects($this->once())->method("shutdown"); $realm->onMessage($session, new \Thruway\Message\HelloMessage('realm1', ["roles" => []])); $realm->onMessage($session, new \Thruway\Message\HelloMessage('realm1', ["roles" => []])); $authMgr->expects($this->once())->method("onSessionClose")->with($this->isInstanceOf('\\Thruway\\Session')); $realm->leave($session); }