Merge pull request #457 from beyondcode/fix/allow-missing-user-info-on-presence-channels

[fix] Allow missing user_info on Presence channels
This commit is contained in:
rennokki 2020-08-13 19:30:07 +03:00 committed by GitHub
commit bce93adc00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 1 deletions

View File

@ -86,12 +86,17 @@ class PresenceChannel extends Channel
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;

View File

@ -59,4 +59,33 @@ class PresenceChannelTest extends TestCase
'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',
]);
}
}