Exemplo n.º 1
0
 public function testBadToken()
 {
     $conn = new \Thruway\Connection($this->getOptions("asdasDAaSDasdaSD"));
     $conn->on('open', function (ClientSession $session) {
         $this->_result = "logged in";
         $session->close();
     });
     $conn->on('error', function ($reason) {
         $this->_error = $reason;
     });
     $conn->open();
     $this->assertEquals("thruway.error.authentication_failure", $this->_error);
     $this->assertNull($this->_result);
 }
Exemplo n.º 2
0
 private function flushRules()
 {
     $conn = new \Thruway\Connection(["realm" => 'authful_realm', "url" => 'ws://127.0.0.1:8090', "max_retries" => 0, "authmethods" => ["simplysimple"], "onChallenge" => function () {
         return "ozTheGreatAndPowerful";
     }]);
     // now set permissions to allow stuff
     $conn->on('open', function (\Thruway\ClientSession $session) use($conn) {
         $session->call("flush_authorization_rules", [false])->then(function ($r) use($conn) {
             $conn->close();
         }, function ($msg) use($conn) {
             $conn->close();
             $this->fail("failed to flush rules " . $msg->getErrorUri());
         });
     });
     $conn->open();
 }
Exemplo n.º 3
0
 public function testWhiteList()
 {
     $conns = [];
     $sessionIds = [];
     $results = [];
     $loop = $this->_loop;
     $subscribePromises = [];
     for ($i = 0; $i < 5; $i++) {
         $results[$i] = "";
         $conns[$i] = $conn = new \Thruway\Connection($this->_connOptions, $loop);
         $conn->on('open', function (\Thruway\ClientSession $session) use($i, &$sessionIds, &$subscribePromises, &$results) {
             $sessionIds[$i] = $session->getSessionId();
             $subscribePromises[] = $session->subscribe('test.whitelist', function ($args) use($i, $session, &$results) {
                 $results[$i] .= "-" . $args[0] . "." . $i . "-";
                 if ($args[0] == "X") {
                     $session->close();
                 }
             });
         });
         $conn->open(false);
     }
     $this->_conn->on('open', function (\Thruway\ClientSession $session) use($subscribePromises, &$sessionIds) {
         \React\Promise\all($subscribePromises)->then(function () use($session, &$sessionIds) {
             $session->publish('test.whitelist', ["A"], null, ['acknowledge' => true])->then(function () use($session, &$sessionIds) {
                 $session->publish('test.whitelist', ["B"], null, ['acknowledge' => true, 'eligible' => $sessionIds])->then(function () use($session, &$sessionIds) {
                     $session->publish('test.whitelist', ["C"], null, ['acknowledge' => true, 'exclude' => [$sessionIds[1]], 'eligible' => $sessionIds])->then(function () use($session, &$sessionIds) {
                         $session->publish('test.whitelist', ["D"], null, ['acknowledge' => true, 'exclude' => [$sessionIds[1]], 'eligible' => [$sessionIds[2]]])->then(function () use($session, &$sessionIds) {
                             $session->publish('test.whitelist', ["E"], null, ['acknowledge' => true, 'exclude' => [$sessionIds[1]], 'eligible' => []])->then(function () use($session, &$sessionIds) {
                                 $session->publish('test.whitelist', ["F"], null, ['acknowledge' => true, 'exclude' => [], 'eligible' => [$sessionIds[0]]])->then(function () use($session, &$sessionIds) {
                                     // shutdown the sessions
                                     $session->publish('test.whitelist', ["X"], null, ['acknowledge' => true])->then(function () use($session) {
                                         $session->close();
                                     });
                                 });
                             });
                         });
                     });
                 });
             });
         });
     });
     $this->_conn->open();
     $this->assertEquals("-A.0--B.0--C.0--F.0--X.0-", $results[0]);
     $this->assertEquals("-A.1--B.1--X.1-", $results[1]);
     $this->assertEquals("-A.2--B.2--C.2--D.2--X.2-", $results[2]);
     $this->assertEquals("-A.3--B.3--C.3--X.3-", $results[3]);
     $this->assertEquals("-A.4--B.4--C.4--X.4-", $results[4]);
 }
Exemplo n.º 4
0
 public function testBadUser()
 {
     $this->_user = "******";
     $this->_password = "******";
     $conn = new \Thruway\Connection($this->getOptions());
     $conn->on('open', function (ClientSession $session) {
         $this->_result = "logged in";
         $session->close();
     });
     $conn->on('error', function ($reason) {
         $this->_error = $reason;
     });
     $conn->open();
     $this->assertEquals("thruway.error.authentication_failure", $this->_error);
     $this->assertNull($this->_result);
 }
Exemplo n.º 5
0
 private function go($message, $to)
 {
     $S = anyC::getFirst("Websocket", "WebsocketUseFor", "phim");
     $realm = $S->A("WebsocketRealm");
     spl_autoload_unregister("phynxAutoloader");
     require Util::getRootPath() . 'PWS/Thruway/vendor/autoload.php';
     require_once __DIR__ . '/ClientPhimAuthenticator.php';
     Thruway\Logging\Logger::set(new Psr\Log\NullLogger());
     $connection = new \Thruway\Connection(["realm" => $realm, "url" => "ws" . ($S->A("WebsocketSecure") ? "s" : "") . "://" . $S->A("WebsocketServer") . ":" . $S->A("WebsocketServerPort") . "/"]);
     $client = $connection->getClient();
     $client->addClientAuthenticator(new ClientPhimAuthenticator($realm, "phimUser", $S->A("WebsocketToken")));
     $connection->on('open', function (\Thruway\ClientSession $session) use($connection, $message, $to) {
         $session->publish('it.furtmeier.phim_' . $to, [json_encode($message, JSON_UNESCAPED_UNICODE)], [], ["acknowledge" => true])->then(function () use($connection) {
             $connection->close();
         }, function ($connection) {
             $connection->close();
         });
     });
     $connection->open();
     /*$client = new Thruway\Peer\Client($realm);
     		$client->addClientAuthenticator(new ClientPhimAuthenticator($realm, "phimUser", $S->A("WebsocketToken")));
     		
     		$client->addTransportProvider(new Thruway\Transport\PawlTransportProvider("ws".($S->A("WebsocketSecure") ? "s" : "")."://".$S->A("WebsocketServer").":".$S->A("WebsocketServerPort")."/"));
     
     		$client->on('open', function (Thruway\ClientSession $session) use ($message, $to) {
     
     			$session->publish('it.furtmeier.phim_'.$to, [json_encode($message, JSON_UNESCAPED_UNICODE)], [], ["acknowledge" => true])->then(
     				function () {
     					echo "Publish Acknowledged!\n";
     					die();
     				},
     				function ($error) {
     					// publish failed
     					echo "Publish Error {$error}\n";
     				}
     			);
     
     			//$session->close();
     		});
     
     
     		$client->start();*/
 }
Exemplo n.º 6
0
 function xtestRealmUnauthenticated()
 {
     $this->_error = null;
     $this->_testResult = "nothing";
     $conn = new \Thruway\Connection(array("realm" => 'not_allowed', "url" => 'ws://127.0.0.1:8080', "max_retries" => 0));
     $conn->on('open', function (\Thruway\ClientSession $session) {
         $session->close();
     });
     $conn->on('error', function ($reason) {
         $this->_testResult = $reason;
     });
     $conn->open();
     $this->assertNull($this->_error, "Got this error when making an RPC call: {$this->_error}");
     $this->assertEquals('wamp.error.not_authorized', $this->_testResult);
 }
Exemplo n.º 7
0
            public function getAuthId()
            {
                return $this->authID;
            }
            public function setAuthId($authid)
            {
            }
            public function getAuthMethods()
            {
                return ["phimAuth_" . $this->realm];
            }
            public function getAuthenticateFromChallenge(Thruway\Message\ChallengeMessage $msg)
            {
                return new \Thruway\Message\AuthenticateMessage($this->key);
            }
        }
    }
    $connection = new \Thruway\Connection(["realm" => $realm, "url" => "ws" . ($S->A("WebsocketSecure") ? "s" : "") . "://" . $S->A("WebsocketServer") . ":" . $S->A("WebsocketServerPort") . "/"]);
    $client = $connection->getClient();
    $client->addClientAuthenticator(new ClientPhimAuthenticator($realm, "phimUser", $S->A("WebsocketToken")));
    $connection->on('open', function (\Thruway\ClientSession $session) use($connection, $message) {
        $session->publish('it.furtmeier.fheme', [json_encode($message, JSON_UNESCAPED_UNICODE)], [], ["acknowledge" => true])->then(function () use($connection) {
            $connection->close();
        }, function ($connection) {
            $connection->close();
        });
    });
    $connection->open();
    #spl_autoload_unregister(array("ThruwayLoader", "alienClassLoader"));
    #spl_autoload_register("phynxAutoloader");
}