|
| 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