wip
This commit is contained in:
parent
2a33b5ec1f
commit
df4af5f6f9
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace BeyondCode\LaravelWebsockets\Tests\Channels;
|
||||
|
||||
use BeyondCode\LaravelWebSockets\Tests\Mocks\Message;
|
||||
use BeyondCode\LaravelWebSockets\Tests\TestCase;
|
||||
|
||||
class ChannelTest extends TestCase
|
||||
{
|
||||
/** @test */
|
||||
public function clients_can_subscribe_to_channels()
|
||||
{
|
||||
$connection = $this->getWebSocketConnection();
|
||||
|
||||
$message = new Message(json_encode([
|
||||
'event' => 'pusher:subscribe',
|
||||
'data' => [
|
||||
'channel' => 'basic-channel'
|
||||
],
|
||||
]));
|
||||
|
||||
$this->pusherServer->onOpen($connection);
|
||||
|
||||
$this->pusherServer->onMessage($connection, $message);
|
||||
|
||||
$connection->assertSentEvent('pusher_internal:subscription_succeeded', [
|
||||
'channel' => 'basic-channel'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
namespace BeyondCode\LaravelWebsockets\Tests\Channels;
|
||||
|
||||
use BeyondCode\LaravelWebSockets\Tests\Mocks\Message;
|
||||
use BeyondCode\LaravelWebSockets\Tests\TestCase;
|
||||
use BeyondCode\LaravelWebSockets\WebSockets\Exceptions\InvalidSignature;
|
||||
|
||||
class PresenceChannelTest extends TestCase
|
||||
{
|
||||
/** @test */
|
||||
public function clients_need_valid_auth_signatures_to_join_presence_channels()
|
||||
{
|
||||
$this->expectException(InvalidSignature::class);
|
||||
|
||||
$connection = $this->getWebSocketConnection();
|
||||
|
||||
$message = new Message(json_encode([
|
||||
'event' => 'pusher:subscribe',
|
||||
'data' => [
|
||||
'auth' => 'invalid',
|
||||
'channel' => 'presence-channel'
|
||||
],
|
||||
]));
|
||||
|
||||
$this->pusherServer->onOpen($connection);
|
||||
|
||||
$this->pusherServer->onMessage($connection, $message);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function clients_with_valid_auth_signatures_can_join_presence_channels()
|
||||
{
|
||||
$connection = $this->getWebSocketConnection();
|
||||
|
||||
$this->pusherServer->onOpen($connection);
|
||||
|
||||
$channelData = [
|
||||
'user_id' => 1,
|
||||
'user_info' => [
|
||||
'name' => 'Marcel'
|
||||
]
|
||||
];
|
||||
|
||||
$signature = "{$connection->socketId}:presence-channel:".json_encode($channelData);
|
||||
|
||||
$message = new Message(json_encode([
|
||||
'event' => 'pusher:subscribe',
|
||||
'data' => [
|
||||
'auth' => $connection->client->appKey.':'.hash_hmac('sha256', $signature, $connection->client->appSecret),
|
||||
'channel' => 'presence-channel',
|
||||
'channel_data' => json_encode($channelData)
|
||||
],
|
||||
]));
|
||||
|
||||
$this->pusherServer->onMessage($connection, $message);
|
||||
|
||||
$connection->assertSentEvent('pusher_internal:subscription_succeeded', [
|
||||
'channel' => 'presence-channel',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace BeyondCode\LaravelWebsockets\Tests\Channels;
|
||||
|
||||
use BeyondCode\LaravelWebSockets\Tests\Mocks\Message;
|
||||
use BeyondCode\LaravelWebSockets\Tests\TestCase;
|
||||
use BeyondCode\LaravelWebSockets\WebSockets\Exceptions\InvalidSignature;
|
||||
|
||||
class PrivateChannelTest extends TestCase
|
||||
{
|
||||
/** @test */
|
||||
public function clients_need_valid_auth_signatures_to_join_private_channels()
|
||||
{
|
||||
$this->expectException(InvalidSignature::class);
|
||||
|
||||
$connection = $this->getWebSocketConnection();
|
||||
|
||||
$message = new Message(json_encode([
|
||||
'event' => 'pusher:subscribe',
|
||||
'data' => [
|
||||
'auth' => 'invalid',
|
||||
'channel' => 'private-channel'
|
||||
],
|
||||
]));
|
||||
|
||||
$this->pusherServer->onOpen($connection);
|
||||
|
||||
$this->pusherServer->onMessage($connection, $message);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function clients_with_valid_auth_signatures_can_join_private_channels()
|
||||
{
|
||||
$connection = $this->getWebSocketConnection();
|
||||
|
||||
$this->pusherServer->onOpen($connection);
|
||||
|
||||
$signature = "{$connection->socketId}:private-channel";
|
||||
|
||||
$message = new Message(json_encode([
|
||||
'event' => 'pusher:subscribe',
|
||||
'data' => [
|
||||
'auth' => $connection->client->appKey.':'.hash_hmac('sha256', $signature, $connection->client->appSecret),
|
||||
'channel' => 'private-channel'
|
||||
],
|
||||
]));
|
||||
|
||||
$this->pusherServer->onMessage($connection, $message);
|
||||
|
||||
$connection->assertSentEvent('pusher_internal:subscription_succeeded', [
|
||||
'channel' => 'private-channel'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -3,22 +3,11 @@
|
|||
namespace BeyondCode\LaravelWebSockets\Tests;
|
||||
|
||||
use BeyondCode\LaravelWebSockets\ClientProviders\Client;
|
||||
use BeyondCode\LaravelWebSockets\WebSockets\Exceptions\InvalidSignature;
|
||||
use BeyondCode\LaravelWebSockets\WebSockets\Exceptions\UnknownAppKey;
|
||||
use BeyondCode\LaravelWebSockets\WebSockets\WebSocketHandler;
|
||||
use BeyondCode\LaravelWebSockets\Tests\Mocks\Message;
|
||||
|
||||
class ConnectionTest extends TestCase
|
||||
{
|
||||
/** @var \BeyondCode\LaravelWebSockets\WebSockets\WebSocketHandler */
|
||||
protected $pusherServer;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->pusherServer = app(WebSocketHandler::class);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function unknown_app_keys_can_not_connect()
|
||||
|
|
@ -65,121 +54,4 @@ class ConnectionTest extends TestCase
|
|||
|
||||
$connection->assertSentEvent('pusher:pong');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function clients_can_subscribe_to_basic_channels()
|
||||
{
|
||||
$connection = $this->getWebSocketConnection();
|
||||
|
||||
$message = new Message(json_encode([
|
||||
'event' => 'pusher:subscribe',
|
||||
'data' => [
|
||||
'channel' => 'basic-channel'
|
||||
],
|
||||
]));
|
||||
|
||||
$this->pusherServer->onOpen($connection);
|
||||
|
||||
$this->pusherServer->onMessage($connection, $message);
|
||||
|
||||
$connection->assertSentEvent('pusher_internal:subscription_succeeded', [
|
||||
'channel' => 'basic-channel'
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function clients_need_valid_auth_signatures_for_private_channels()
|
||||
{
|
||||
$this->expectException(InvalidSignature::class);
|
||||
|
||||
$connection = $this->getWebSocketConnection();
|
||||
|
||||
$message = new Message(json_encode([
|
||||
'event' => 'pusher:subscribe',
|
||||
'data' => [
|
||||
'auth' => 'invalid',
|
||||
'channel' => 'private-channel'
|
||||
],
|
||||
]));
|
||||
|
||||
$this->pusherServer->onOpen($connection);
|
||||
|
||||
$this->pusherServer->onMessage($connection, $message);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function clients_can_subscribe_to_private_channels()
|
||||
{
|
||||
$connection = $this->getWebSocketConnection();
|
||||
|
||||
$this->pusherServer->onOpen($connection);
|
||||
|
||||
$signature = "{$connection->socketId}:private-channel";
|
||||
|
||||
$message = new Message(json_encode([
|
||||
'event' => 'pusher:subscribe',
|
||||
'data' => [
|
||||
'auth' => $connection->client->appKey.':'.hash_hmac('sha256', $signature, $connection->client->appSecret),
|
||||
'channel' => 'private-channel'
|
||||
],
|
||||
]));
|
||||
|
||||
$this->pusherServer->onMessage($connection, $message);
|
||||
|
||||
$connection->assertSentEvent('pusher_internal:subscription_succeeded', [
|
||||
'channel' => 'private-channel'
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function clients_need_valid_auth_signatures_for_presence_channels()
|
||||
{
|
||||
$this->expectException(InvalidSignature::class);
|
||||
|
||||
$connection = $this->getWebSocketConnection();
|
||||
|
||||
$message = new Message(json_encode([
|
||||
'event' => 'pusher:subscribe',
|
||||
'data' => [
|
||||
'auth' => 'invalid',
|
||||
'channel' => 'presence-channel'
|
||||
],
|
||||
]));
|
||||
|
||||
$this->pusherServer->onOpen($connection);
|
||||
|
||||
$this->pusherServer->onMessage($connection, $message);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function clients_can_subscribe_to_presence_channels()
|
||||
{
|
||||
$connection = $this->getWebSocketConnection();
|
||||
|
||||
$this->pusherServer->onOpen($connection);
|
||||
|
||||
$channelData = [
|
||||
'user_id' => 1,
|
||||
'user_info' => [
|
||||
'name' => 'Marcel'
|
||||
]
|
||||
];
|
||||
|
||||
$signature = "{$connection->socketId}:presence-channel:".json_encode($channelData);
|
||||
|
||||
$message = new Message(json_encode([
|
||||
'event' => 'pusher:subscribe',
|
||||
'data' => [
|
||||
'auth' => $connection->client->appKey.':'.hash_hmac('sha256', $signature, $connection->client->appSecret),
|
||||
'channel' => 'presence-channel',
|
||||
'channel_data' => json_encode($channelData)
|
||||
],
|
||||
]));
|
||||
|
||||
$this->pusherServer->onMessage($connection, $message);
|
||||
|
||||
$connection->assertSentEvent('pusher_internal:subscription_succeeded', [
|
||||
'channel' => 'presence-channel',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,12 +2,24 @@
|
|||
|
||||
namespace BeyondCode\LaravelWebSockets\Tests;
|
||||
|
||||
use BeyondCode\LaravelWebSockets\WebSockets\WebSocketHandler;
|
||||
use GuzzleHttp\Psr7\Request;
|
||||
use BeyondCode\LaravelWebSockets\Tests\Mocks\Connection;
|
||||
use BeyondCode\LaravelWebSockets\WebSocketsServiceProvider;
|
||||
|
||||
abstract class TestCase extends \Orchestra\Testbench\TestCase
|
||||
{
|
||||
|
||||
/** @var \BeyondCode\LaravelWebSockets\WebSockets\WebSocketHandler */
|
||||
protected $pusherServer;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->pusherServer = app(WebSocketHandler::class);
|
||||
}
|
||||
|
||||
protected function getPackageProviders($app)
|
||||
{
|
||||
return [WebSocketsServiceProvider::class];
|
||||
|
|
|
|||
Loading…
Reference in New Issue