36 lines
1010 B
PHP
36 lines
1010 B
PHP
<?php
|
|
|
|
namespace Tests\Feature\Api;
|
|
|
|
use Tests\TestCase;
|
|
|
|
class CorsTest extends TestCase
|
|
{
|
|
public function test_preflight_options_on_api_returns_cors_headers(): void
|
|
{
|
|
$response = $this->call(
|
|
'OPTIONS',
|
|
'/api/v1/health',
|
|
server: [
|
|
'HTTP_ORIGIN' => 'http://localhost:5173',
|
|
'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'GET',
|
|
'HTTP_ACCESS_CONTROL_REQUEST_HEADERS' => 'Authorization, Content-Type',
|
|
],
|
|
);
|
|
|
|
$response->assertOk();
|
|
$response->assertHeader('Access-Control-Allow-Origin', '*');
|
|
$response->assertHeader('Access-Control-Allow-Methods');
|
|
}
|
|
|
|
public function test_get_request_includes_cors_headers_for_browser_origin(): void
|
|
{
|
|
$response = $this->getJson('/api/v1/health', [
|
|
'Origin' => 'http://localhost:5173',
|
|
]);
|
|
|
|
$response->assertOk();
|
|
$response->assertHeader('Access-Control-Allow-Origin', '*');
|
|
}
|
|
}
|