From 04742a29a3225d6878c79f202e0b448537161965 Mon Sep 17 00:00:00 2001 From: Joe Dixon Date: Mon, 12 Feb 2024 13:28:05 +0000 Subject: [PATCH 1/2] ship pusher sdk --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index db7a28cb..ed2f79bd 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,7 @@ "illuminate/contracts": "^10.0|^11.0", "illuminate/http": "^10.0|^11.0", "illuminate/support": "^10.0|^11.0", + "pusher/pusher-php-server": "^7.2", "ratchet/rfc6455": "^0.3.1", "react/socket": "^1.14", "symfony/http-foundation": "^6.3|^7.0" From 43ef33c36f7ec6ba9b3d4eca389a48a71affd6c9 Mon Sep 17 00:00:00 2001 From: Joe Dixon Date: Mon, 12 Feb 2024 13:33:40 +0000 Subject: [PATCH 2/2] remove pusher references --- config/reverb.php | 16 +++++++-------- phpunit.xml.dist | 6 +++--- tests/FakeConnection.php | 2 +- .../Reverb/ChannelUsersControllerTest.php | 2 +- .../Protocols/Pusher/Reverb/ServerTest.php | 8 ++++---- tests/Helpers/Reverb.php | 2 +- tests/Pest.php | 2 +- tests/ReverbTestCase.php | 20 +++++++++---------- tests/Unit/EventTest.php | 6 +++--- tests/Unit/Protocols/Pusher/ServerTest.php | 8 ++++---- 10 files changed, 36 insertions(+), 36 deletions(-) diff --git a/config/reverb.php b/config/reverb.php index 01a0bcf0..bf0fb355 100644 --- a/config/reverb.php +++ b/config/reverb.php @@ -56,16 +56,16 @@ 'apps' => [ [ - 'key' => env('PUSHER_APP_KEY'), - 'secret' => env('PUSHER_APP_SECRET'), - 'app_id' => env('PUSHER_APP_ID'), + 'key' => env('REVERB_APP_KEY'), + 'secret' => env('REVERB_APP_SECRET'), + 'app_id' => env('REVERB_APP_ID'), 'options' => [ - 'cluster' => env('PUSHER_APP_CLUSTER'), - 'host' => env('PUSHER_HOST'), - 'port' => env('PUSHER_PORT', 443), - 'scheme' => env('PUSHER_SCHEME', 'https'), + 'cluster' => env('REVERB_APP_CLUSTER'), + 'host' => env('REVERB_HOST'), + 'port' => env('REVERB_PORT', 443), + 'scheme' => env('REVERB_SCHEME', 'https'), 'encrypted' => true, - 'useTLS' => env('PUSHER_SCHEME', 'https') === 'https', + 'useTLS' => env('REVERB_SCHEME', 'https') === 'https', ], 'allowed_origins' => ['*'], 'ping_interval' => env('REVERB_APP_PING_INTERVAL', 60), diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 91b178c8..bed79193 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -11,9 +11,9 @@ - - - + + + diff --git a/tests/FakeConnection.php b/tests/FakeConnection.php index a7460bd1..308048ba 100644 --- a/tests/FakeConnection.php +++ b/tests/FakeConnection.php @@ -66,7 +66,7 @@ public function id(): string */ public function app(): Application { - return app()->make(ApplicationProvider::class)->findByKey('pusher-key'); + return app()->make(ApplicationProvider::class)->findByKey('reverb-key'); } /** diff --git a/tests/Feature/Protocols/Pusher/Reverb/ChannelUsersControllerTest.php b/tests/Feature/Protocols/Pusher/Reverb/ChannelUsersControllerTest.php index f549ba60..fc78cb3f 100644 --- a/tests/Feature/Protocols/Pusher/Reverb/ChannelUsersControllerTest.php +++ b/tests/Feature/Protocols/Pusher/Reverb/ChannelUsersControllerTest.php @@ -21,7 +21,7 @@ it('returns the user data', function () { $channel = app(ChannelManager::class) - ->for(app()->make(ApplicationProvider::class)->findByKey('pusher-key')) + ->for(app()->make(ApplicationProvider::class)->findByKey('reverb-key')) ->findOrCreate('presence-test-channel'); $channel->subscribe($connection = new FakeConnection('test-connection-one'), validAuth($connection->id(), 'presence-test-channel', $data = json_encode(['user_id' => 1, 'user_info' => ['name' => 'Taylor']])), $data); $channel->subscribe($connection = new FakeConnection('test-connection-two'), validAuth($connection->id(), 'presence-test-channel', $data = json_encode(['user_id' => 2, 'user_info' => ['name' => 'Joe']])), $data); diff --git a/tests/Feature/Protocols/Pusher/Reverb/ServerTest.php b/tests/Feature/Protocols/Pusher/Reverb/ServerTest.php index baf176d2..6b680386 100644 --- a/tests/Feature/Protocols/Pusher/Reverb/ServerTest.php +++ b/tests/Feature/Protocols/Pusher/Reverb/ServerTest.php @@ -13,8 +13,8 @@ it('can handle connections to different applications', function () { connect(); - connect(key: 'pusher-key-2'); - connect(key: 'pusher-key-3', headers: ['Origin' => 'http://laravel.com']); + connect(key: 'reverb-key-2'); + connect(key: 'reverb-key-3', headers: ['Origin' => 'http://laravel.com']); }); it('can subscribe to a channel', function () { @@ -366,7 +366,7 @@ it('cannot connect from an invalid origin', function () { $connection = await( - wsConnect('ws://0.0.0.0:8080/app/pusher-key-3') + wsConnect('ws://0.0.0.0:8080/app/reverb-key-3') ); $promise = new Deferred(); @@ -387,7 +387,7 @@ }); it('limits the size of messages', function () { - $connection = connect(key: 'pusher-key-3', headers: ['Origin' => 'http://laravel.com']); + $connection = connect(key: 'reverb-key-3', headers: ['Origin' => 'http://laravel.com']); send(['This message is waaaaaay longer than the 1 byte limit'], $connection); $connection->assertReceived('Maximum message size exceeded'); diff --git a/tests/Helpers/Reverb.php b/tests/Helpers/Reverb.php index 69fd99b5..db0f233f 100644 --- a/tests/Helpers/Reverb.php +++ b/tests/Helpers/Reverb.php @@ -10,7 +10,7 @@ /** * Connect to the WebSocket server. */ -function connect(string $host = '0.0.0.0', string $port = '8080', string $key = 'pusher-key', array $headers = []): TestConnection +function connect(string $host = '0.0.0.0', string $port = '8080', string $key = 'reverb-key', array $headers = []): TestConnection { $promise = new Deferred; diff --git a/tests/Pest.php b/tests/Pest.php index bf40e575..258c5c67 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -41,7 +41,7 @@ function validAuth(string $connectionId, string $channel, ?string $data = null): $signature .= ":{$data}"; } - return 'app-key:'.hash_hmac('sha256', $signature, 'pusher-secret'); + return 'app-key:'.hash_hmac('sha256', $signature, 'reverb-secret'); } /** diff --git a/tests/ReverbTestCase.php b/tests/ReverbTestCase.php index 8fc7d2eb..01f8f3a0 100644 --- a/tests/ReverbTestCase.php +++ b/tests/ReverbTestCase.php @@ -49,8 +49,8 @@ protected function defineEnvironment($app): void $app['config']->set('reverb.apps.apps.1', [ 'app_id' => '654321', - 'key' => 'pusher-key-2', - 'secret' => 'pusher-secret-2', + 'key' => 'reverb-key-2', + 'secret' => 'reverb-secret-2', 'capacity' => null, 'allowed_origins' => ['*'], 'ping_interval' => 10, @@ -59,8 +59,8 @@ protected function defineEnvironment($app): void $app['config']->set('reverb.apps.apps.2', [ 'app_id' => '987654', - 'key' => 'pusher-key-3', - 'secret' => 'pusher-secret-3', + 'key' => 'reverb-key-3', + 'secret' => 'reverb-secret-3', 'capacity' => null, 'allowed_origins' => ['laravel.com'], 'ping_interval' => 10, @@ -147,9 +147,9 @@ public function signedRequest(string $path, string $method = 'GET', mixed $data { $hash = md5(json_encode($data)); $timestamp = time(); - $query = "auth_key=pusher-key&auth_timestamp={$timestamp}&auth_version=1.0&body_md5={$hash}"; + $query = "auth_key=reverb-key&auth_timestamp={$timestamp}&auth_version=1.0&body_md5={$hash}"; $string = "POST\n/apps/{$appId}/{$path}\n$query"; - $signature = hash_hmac('sha256', $string, 'pusher-secret'); + $signature = hash_hmac('sha256', $string, 'reverb-secret'); $path = Str::contains($path, '?') ? "{$path}&{$query}" : "{$path}?{$query}"; return $this->request("{$path}&auth_signature={$signature}", $method, $data, $host, $port, $appId); @@ -170,9 +170,9 @@ public function signedPostRequest(string $path, array $data = [], string $host = { $hash = md5(json_encode($data)); $timestamp = time(); - $query = "auth_key=pusher-key&auth_timestamp={$timestamp}&auth_version=1.0&body_md5={$hash}"; + $query = "auth_key=reverb-key&auth_timestamp={$timestamp}&auth_version=1.0&body_md5={$hash}"; $string = "POST\n/apps/{$appId}/{$path}\n$query"; - $signature = hash_hmac('sha256', $string, 'pusher-secret'); + $signature = hash_hmac('sha256', $string, 'reverb-secret'); return $this->postReqeust("{$path}?{$query}&auth_signature={$signature}", $data, $host, $port, $appId); } @@ -184,9 +184,9 @@ public function getWithSignature(string $path, array $data = [], string $host = { $hash = md5(json_encode($data)); $timestamp = time(); - $query = "auth_key=pusher-key&auth_timestamp={$timestamp}&auth_version=1.0&body_md5={$hash}"; + $query = "auth_key=reverb-key&auth_timestamp={$timestamp}&auth_version=1.0&body_md5={$hash}"; $string = "POST\n/apps/{$appId}/{$path}\n$query"; - $signature = hash_hmac('sha256', $string, 'pusher-secret'); + $signature = hash_hmac('sha256', $string, 'reverb-secret'); $path = Str::contains($path, '?') ? "{$path}&{$query}" : "{$path}?{$query}"; diff --git a/tests/Unit/EventTest.php b/tests/Unit/EventTest.php index 4d99b107..ad48d186 100644 --- a/tests/Unit/EventTest.php +++ b/tests/Unit/EventTest.php @@ -7,7 +7,7 @@ use Laravel\Reverb\Servers\Reverb\Contracts\PubSubProvider; it('can publish an event when enabled', function () { - $app = app(ApplicationProvider::class)->findByKey('pusher-key'); + $app = app(ApplicationProvider::class)->findByKey('reverb-key'); app(ServerProviderManager::class)->withPublishing(); $pubSub = Mockery::mock(PubSubProvider::class); $pubSub->shouldReceive('publish')->once() @@ -29,7 +29,7 @@ channels()->findOrCreate('test-channel'); - EventDispatcher::dispatch(app(ApplicationProvider::class)->findByKey('pusher-key'), ['channel' => 'test-channel']); + EventDispatcher::dispatch(app(ApplicationProvider::class)->findByKey('reverb-key'), ['channel' => 'test-channel']); }); it('can broadcast an event for multiple channels', function () { @@ -44,5 +44,5 @@ channels()->findOrCreate('test-channel-one'); channels()->findOrCreate('test-channel-two'); - EventDispatcher::dispatch(app(ApplicationProvider::class)->findByKey('pusher-key'), ['channels' => ['test-channel-one', 'test-channel-two']]); + EventDispatcher::dispatch(app(ApplicationProvider::class)->findByKey('reverb-key'), ['channels' => ['test-channel-one', 'test-channel-two']]); }); diff --git a/tests/Unit/Protocols/Pusher/ServerTest.php b/tests/Unit/Protocols/Pusher/ServerTest.php index 7973e158..059de801 100644 --- a/tests/Unit/Protocols/Pusher/ServerTest.php +++ b/tests/Unit/Protocols/Pusher/ServerTest.php @@ -119,7 +119,7 @@ 'event' => 'pusher:subscribe', 'data' => [ 'channel' => 'private-test-channel', - 'auth' => 'app-key:'.hash_hmac('sha256', $connection->id().':private-test-channel', 'pusher-secret'), + 'auth' => 'app-key:'.hash_hmac('sha256', $connection->id().':private-test-channel', 'reverb-secret'), ], ])); @@ -136,7 +136,7 @@ 'event' => 'pusher:subscribe', 'data' => [ 'channel' => 'presence-test-channel', - 'auth' => 'app-key:'.hash_hmac('sha256', $connection->id().':presence-test-channel', 'pusher-secret'), + 'auth' => 'app-key:'.hash_hmac('sha256', $connection->id().':presence-test-channel', 'reverb-secret'), ], ])); @@ -242,7 +242,7 @@ 'event' => 'pusher:subscribe', 'data' => [ 'channel' => 'private-test-channel', - 'auth' => 'app-key:'.hash_hmac('sha256', '10000.00001:private-test-channel', 'pusher-secret'), + 'auth' => 'app-key:'.hash_hmac('sha256', '10000.00001:private-test-channel', 'reverb-secret'), ], ])); @@ -266,7 +266,7 @@ 'event' => 'pusher:subscribe', 'data' => [ 'channel' => 'presence-test-channel', - 'auth' => 'app-key:'.hash_hmac('sha256', '10000.00001:presence-test-channel', 'pusher-secret'), + 'auth' => 'app-key:'.hash_hmac('sha256', '10000.00001:presence-test-channel', 'reverb-secret'), ], ]));