Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

[fix] Allow missing user_info on Presence channels #457

Merged
merged 1 commit into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/WebSockets/Channels/PresenceChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,17 @@ protected function getUserIds(): array
return array_values($userIds);
}

/**
* Compute the hash for the presence channel integrity.
*
* @return array
*/
protected function getHash(): array
{
$hash = [];

foreach ($this->users as $socketId => $channelData) {
$hash[$channelData->user_id] = $channelData->user_info;
$hash[$channelData->user_id] = $channelData->user_info ?? [];
}

return $hash;
Expand Down
29 changes: 29 additions & 0 deletions tests/Channels/PresenceChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,33 @@ public function clients_with_valid_auth_signatures_can_join_presence_channels()
'channel' => 'presence-channel',
]);
}

/** @test */
public function clients_with_no_user_info_can_join_presence_channels()
{
$connection = $this->getWebSocketConnection();

$this->pusherServer->onOpen($connection);

$channelData = [
'user_id' => 1,
];

$signature = "{$connection->socketId}:presence-channel:".json_encode($channelData);

$message = new Message(json_encode([
'event' => 'pusher:subscribe',
'data' => [
'auth' => $connection->app->key.':'.hash_hmac('sha256', $signature, $connection->app->secret),
'channel' => 'presence-channel',
'channel_data' => json_encode($channelData),
],
]));

$this->pusherServer->onMessage($connection, $message);

$connection->assertSentEvent('pusher_internal:subscription_succeeded', [
'channel' => 'presence-channel',
]);
}
}