Skip to content

Commit 0e99b68

Browse files
committed
Added tests
1 parent a0c3c96 commit 0e99b68

14 files changed

Lines changed: 526 additions & 327 deletions

File tree

.github/workflows/ci.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
8+
jobs:
9+
lint:
10+
name: Pint (lint)
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Setup PHP
16+
uses: shivammathur/setup-php@v2
17+
with:
18+
php-version: '8.3'
19+
extensions: openssl, mbstring, pdo_sqlite, zip
20+
coverage: none
21+
22+
- name: Install Composer dependencies
23+
run: composer install --no-interaction --prefer-dist
24+
25+
- name: Run Pint
26+
run: vendor/bin/pint --test
27+
28+
test:
29+
name: PHPUnit
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/checkout@v4
33+
34+
- name: Setup PHP
35+
uses: shivammathur/setup-php@v2
36+
with:
37+
php-version: '8.3'
38+
extensions: openssl, mbstring, pdo_sqlite, zip
39+
coverage: none
40+
41+
- name: Install Composer dependencies
42+
run: composer install --no-interaction --prefer-dist
43+
44+
- name: Prepare environment
45+
run: |
46+
cp .env.example .env
47+
php artisan key:generate
48+
49+
- name: Run test suite
50+
run: composer test

app/Http/Controllers/WebhookController.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ public function __invoke(Request $request): Response
3131
$payload = $request->json()->all();
3232

3333
WebhookEvent::create([
34-
'webhook_id' => $webhookId,
35-
'event_type' => $payload['type'] ?? null,
36-
'source' => $payload['source'] ?? null,
37-
'subject' => $payload['subject'] ?? null,
38-
'payload' => $payload,
39-
'headers' => $request->headers->all(),
34+
'webhook_id' => $webhookId,
35+
'event_type' => $payload['type'] ?? null,
36+
'source' => $payload['source'] ?? null,
37+
'subject' => $payload['subject'] ?? null,
38+
'payload' => $payload,
39+
'headers' => $request->headers->all(),
4040
'received_at' => now(),
4141
]);
4242

app/Http/Controllers/WebhookHandshakeController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ class WebhookHandshakeController extends Controller
1919
{
2020
public function __invoke(Request $request): Response
2121
{
22-
$requestOrigin = $request->header('WebHook-Request-Origin', '*');
23-
$configOrigin = config('webhook-receiver.sender_origin', '*');
22+
$requestOrigin = $request->header('WebHook-Request-Origin', '*');
23+
$configOrigin = config('webhook-receiver.sender_origin', '*');
2424

2525
// Echo back the sender's origin when we accept any origin, otherwise
2626
// respond with the specific origin we are configured to allow.
27-
$allowedOrigin = ($configOrigin === '*') ? $requestOrigin : $configOrigin;
28-
$allowedRate = (string) config('webhook-receiver.allowed_rate', 1000);
27+
$allowedOrigin = ($configOrigin === '*') ? $requestOrigin : $configOrigin;
28+
$allowedRate = (string) config('webhook-receiver.allowed_rate', 1000);
2929

3030
return response('', 200)
3131
->header('WebHook-Allowed-Origin', $allowedOrigin)

app/Models/WebhookEvent.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ class WebhookEvent extends Model
2525
];
2626

2727
protected $casts = [
28-
'payload' => 'array',
29-
'headers' => 'array',
30-
'received_at' => 'datetime',
28+
'payload' => 'array',
29+
'headers' => 'array',
30+
'received_at' => 'datetime',
3131
'signature_verified' => 'boolean',
3232
];
3333
}

app/Providers/AppServiceProvider.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,3 @@ public function register(): void
1818

1919
public function boot(): void {}
2020
}
21-

app/Services/JwksCache.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ class JwksCache
1212
{
1313
public function fetch(string $url): array
1414
{
15-
$ttl = (int) config('webhook-receiver.jwks_cache_ttl', 3600);
16-
$cacheKey = 'webhook_receiver.jwks.' . md5($url);
15+
$ttl = (int) config('webhook-receiver.jwks_cache_ttl', 3600);
16+
$cacheKey = 'webhook_receiver.jwks.'.md5($url);
1717

1818
return Cache::remember($cacheKey, $ttl, function () use ($url) {
1919
$response = Http::timeout(5)->get($url);

0 commit comments

Comments
 (0)