wip
This commit is contained in:
parent
24580d0e96
commit
f75ed6d86c
|
|
@ -141,4 +141,62 @@ class ConnectionTest extends TestCase
|
||||||
'channel' => 'private-channel'
|
'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',
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue