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

Commit 54a20ae

Browse files
committed
Fixed mc
2 parents a84f143 + e9b9cc4 commit 54a20ae

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace BeyondCode\LaravelWebSockets\Statistics\Http\Middleware;
4+
5+
use BeyondCode\LaravelWebSockets\Apps\App;
6+
7+
class Authorize
8+
{
9+
public function handle($request, $next)
10+
{
11+
$app = App::findByKey($request->key);
12+
13+
return is_null($app) || $app->secret !== $request->secret
14+
? abort(403)
15+
: $next($request);
16+
}
17+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace BeyondCode\LaravelWebSockets\Tests\Statistics\Controllers;
4+
5+
use BeyondCode\LaravelWebSockets\Statistics\Http\Controllers\WebSocketStatisticsEntriesController;
6+
use BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry;
7+
use BeyondCode\LaravelWebSockets\Tests\TestCase;
8+
9+
class WebSocketsStatisticsControllerTest extends TestCase
10+
{
11+
/** @test */
12+
public function it_can_store_statistics()
13+
{
14+
$this->post(
15+
action([WebSocketStatisticsEntriesController::class, 'store']),
16+
array_merge($this->payload(), [
17+
'key' => config('websockets.apps.0.key'),
18+
'secret' => config('websockets.apps.0.secret'),
19+
])
20+
);
21+
22+
$entries = WebSocketsStatisticsEntry::get();
23+
24+
$this->assertCount(1, $entries);
25+
26+
$this->assertArrayHasKey('app_id', $entries->first()->attributesToArray());
27+
}
28+
29+
protected function payload(): array
30+
{
31+
return [
32+
'app_id' => config('websockets.apps.0.id'),
33+
'peak_connection_count' => 1,
34+
'websocket_message_count' => 2,
35+
'api_message_count' => 3,
36+
];
37+
}
38+
}

0 commit comments

Comments
 (0)