This commit is contained in:
Marcel Pociot 2018-11-26 00:33:07 +01:00
parent 24580d0e96
commit f75ed6d86c
1 changed files with 58 additions and 0 deletions

View File

@ -141,4 +141,62 @@ class ConnectionTest extends TestCase
'channel' => 'private-channel'
]);
}
/** @test */
public function clients_need_valid_auth_signatures_for_presence_channels()
{
$this->expectException(InvalidSignatureException::class);
/** @var PusherServer $server */
$server = app(PusherServer::class);
$connection = $this->getWebSocketConnection();
$message = new Message(json_encode([
'event' => 'pusher:subscribe',
'data' => [
'auth' => 'invalid',
'channel' => 'presence-channel'
],
]));
$server->onOpen($connection);
$server->onMessage($connection, $message);
}
/** @test */
public function clients_can_subscribe_to_presence_channels()
{
/** @var PusherServer $server */
$server = app(PusherServer::class);
$connection = $this->getWebSocketConnection();
$server->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)
],
]));
$server->onMessage($connection, $message);
$connection->assertSentEvent('pusher_internal:subscription_succeeded', [
'channel' => 'presence-channel',
]);
}
}