Skip to content

Commit 307339d

Browse files
committed
Add callback test endpoint
1 parent 90b97b3 commit 307339d

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

routes/web.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,16 @@
112112
->middleware(EnsureFeaturesAreActive::using(ShowAuthButtons::class))
113113
->name('customer.logout');
114114

115+
Route::get('callback', function (Illuminate\Http\Request $request) {
116+
$url = $request->query('url');
117+
118+
if ($url && str_starts_with($url, 'nativephp://')) {
119+
return redirect()->away($url.'?token='.uuid_create());
120+
}
121+
122+
return response('Goodbye');
123+
})->name('callback');
124+
115125
// Customer license management routes
116126
Route::middleware(['auth', EnsureFeaturesAreActive::using(ShowAuthButtons::class)])->prefix('customer')->name('customer.')->group(function () {
117127
Route::get('licenses', [CustomerLicenseController::class, 'index'])->name('licenses');
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace Tests\Feature;
4+
5+
use Tests\TestCase;
6+
7+
class CallbackRedirectTest extends TestCase
8+
{
9+
public function test_callback_redirects_to_nativephp_url_with_token(): void
10+
{
11+
$response = $this->get('/callback?url=nativephp://127.0.0.1/some/url');
12+
13+
$response->assertRedirect();
14+
15+
$redirectUrl = $response->headers->get('Location');
16+
17+
$this->assertStringStartsWith('nativephp://127.0.0.1/some/url?token=', $redirectUrl);
18+
19+
// Extract and validate the token is a valid UUID
20+
$token = str_replace('nativephp://127.0.0.1/some/url?token=', '', $redirectUrl);
21+
$this->assertTrue(
22+
preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i', $token) === 1,
23+
"Token should be a valid UUID, got: {$token}"
24+
);
25+
}
26+
27+
public function test_callback_shows_goodbye_for_non_nativephp_url(): void
28+
{
29+
$response = $this->get('/callback?url=https://example.com');
30+
31+
$response->assertStatus(200);
32+
$response->assertSee('Goodbye');
33+
}
34+
35+
public function test_callback_shows_goodbye_when_no_url_provided(): void
36+
{
37+
$response = $this->get('/callback');
38+
39+
$response->assertStatus(200);
40+
$response->assertSee('Goodbye');
41+
}
42+
43+
public function test_callback_shows_goodbye_for_partial_nativephp_scheme(): void
44+
{
45+
$response = $this->get('/callback?url=nativephp:/missing-slash');
46+
47+
$response->assertStatus(200);
48+
$response->assertSee('Goodbye');
49+
}
50+
}

0 commit comments

Comments
 (0)