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); }
public function testUnauthorizedActions() { $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\Session::getUniqueId(), [], "some_topic"); $publishMsg = new \Thruway\Message\PublishMessage(\Thruway\Session::getUniqueId(), [], "some_topic"); $registerMsg = new \Thruway\Message\RegisterMessage(\Thruway\Session::getUniqueId(), [], 'some_procedure'); $callMsg = new \Thruway\Message\CallMessage(\Thruway\Session::getUniqueId(), [], "some_procedure"); $authorizationManager->expects($this->exactly(4))->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')])->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); }
$router->addTransportProvider(new \Thruway\Transport\InternalClientTransportProvider($authProvClient)); // provide aborting auth provider $authAbortAfterHello = new AbortAfterHelloAuthProviderClient(["abortafterhello"]); $router->addTransportProvider(new \Thruway\Transport\InternalClientTransportProvider($authAbortAfterHello)); //////////////////// // Test stuff for Authorization $authorizationManager = new \Thruway\Authentication\AuthorizationManager('authorizing_realm'); $authorizingRealm = new \Thruway\Realm('authorizing_realm'); $authorizingRealm->setAuthorizationManager($authorizationManager); $router->getRealmManager()->addRealm($authorizingRealm); $router->addTransportProvider(new \Thruway\Transport\InternalClientTransportProvider($authorizationManager)); // Create a realm with Authentication also // to test some stuff $authAndAuthAuthorizer = new \Thruway\Authentication\AuthorizationManager("authful_realm"); $authAndAuthRealm = new \Thruway\Realm("authful_realm"); $authAndAuthRealm->setAuthorizationManager($authAndAuthAuthorizer); $authAndAuthRealm->setAuthenticationManager($authMgr); $router->getRealmManager()->addRealm($authAndAuthRealm); $router->addTransportProvider(new \Thruway\Transport\InternalClientTransportProvider($authAndAuthAuthorizer)); //////////////////// $transportProvider = new RatchetTransportProvider("127.0.0.1", 8090); $router->addTransportProvider($transportProvider); $theInternalClient = new InternalClient('testRealm', $loop); $theInternalClient->setRouter($router); $internalTransportProvider = new Thruway\Transport\InternalClientTransportProvider($theInternalClient); $router->addTransportProvider($internalTransportProvider); //Client for Disclose Publisher Test $dpClient = new DisclosePublisherClient('testSimpleAuthRealm', $loop); $internalTransportProvider = new Thruway\Transport\InternalClientTransportProvider($dpClient); $router->addTransportProvider($internalTransportProvider); if ($timeout) {