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

Commit bce93ad

Browse files
authored
Merge pull request #457 from beyondcode/fix/allow-missing-user-info-on-presence-channels
[fix] Allow missing user_info on Presence channels
2 parents 8383054 + 8b15897 commit bce93ad

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/WebSockets/Channels/PresenceChannel.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,17 @@ protected function getUserIds(): array
8686
return array_values($userIds);
8787
}
8888

89+
/**
90+
* Compute the hash for the presence channel integrity.
91+
*
92+
* @return array
93+
*/
8994
protected function getHash(): array
9095
{
9196
$hash = [];
9297

9398
foreach ($this->users as $socketId => $channelData) {
94-
$hash[$channelData->user_id] = $channelData->user_info;
99+
$hash[$channelData->user_id] = $channelData->user_info ?? [];
95100
}
96101

97102
return $hash;

tests/Channels/PresenceChannelTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,33 @@ public function clients_with_valid_auth_signatures_can_join_presence_channels()
5959
'channel' => 'presence-channel',
6060
]);
6161
}
62+
63+
/** @test */
64+
public function clients_with_no_user_info_can_join_presence_channels()
65+
{
66+
$connection = $this->getWebSocketConnection();
67+
68+
$this->pusherServer->onOpen($connection);
69+
70+
$channelData = [
71+
'user_id' => 1,
72+
];
73+
74+
$signature = "{$connection->socketId}:presence-channel:".json_encode($channelData);
75+
76+
$message = new Message(json_encode([
77+
'event' => 'pusher:subscribe',
78+
'data' => [
79+
'auth' => $connection->app->key.':'.hash_hmac('sha256', $signature, $connection->app->secret),
80+
'channel' => 'presence-channel',
81+
'channel_data' => json_encode($channelData),
82+
],
83+
]));
84+
85+
$this->pusherServer->onMessage($connection, $message);
86+
87+
$connection->assertSentEvent('pusher_internal:subscription_succeeded', [
88+
'channel' => 'presence-channel',
89+
]);
90+
}
6291
}

0 commit comments

Comments
 (0)