Files
Investidor-V2/tests/Feature/SimulationRateLimitTest.php
nala e65cb26901
tests / ci (push) Canceled after 0s
varias alteracoes
2026-10-06 14:50:12 +02:00

33 lines
1.0 KiB
PHP

<?php
namespace Tests\Feature;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Str;
use Tests\TestCase;
class SimulationRateLimitTest extends TestCase
{
public function test_public_calculation_endpoint_limits_repeated_requests_per_anonymous_token(): void
{
$token = Str::random(48);
$limiterKey = 'simulation-calculation:anonymous:'.hash('sha256', $token);
RateLimiter::clear($limiterKey);
try {
for ($attempt = 0; $attempt < 10; $attempt++) {
$this->postJson('/api/v1/simulations', [], [
'X-Simulation-Token' => $token,
])->assertUnprocessable();
}
$response = $this->postJson('/api/v1/simulations', [], [
'X-Simulation-Token' => $token,
])->assertTooManyRequests()->assertHeader('Retry-After');
$this->assertStringContainsString('demasiados', (string) $response->json('message'));
} finally {
RateLimiter::clear($limiterKey);
}
}
}