Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Handle expiration in seconds #48600

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ protected function shouldntReport(Throwable $e)
with($throttle->key ?: 'illuminate:foundation:exceptions:'.$e::class, fn ($key) => $this->hashThrottleKeys ? md5($key) : $key),
$throttle->maxAttempts,
fn () => true,
$throttle->decayMinutes
60 * $throttle->decayMinutes
);
}), rescue: false, report: false);
}
Expand Down
46 changes: 46 additions & 0 deletions tests/Foundation/FoundationExceptionsHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,52 @@ public function attempt($key, $maxAttempts, Closure $callback, $decaySeconds = 6
$this->assertCount(14, $reported);
$this->assertSame('Something in the app went wrong.', $reported[0]->getMessage());
}

public function testRateLimitExpiresOnBoundary()
{
$handler = new class($this->container) extends Handler
{
protected function throttle($e)
{
return Limit::perMinute(1);
}
};
$reported = [];
$handler->reportable(function (\Throwable $e) use (&$reported) {
$reported[] = $e;

return false;
});
$this->container->instance(RateLimiter::class, $limiter = new class(new Repository(new ArrayStore)) extends RateLimiter
{
public $attempted = 0;

public function attempt($key, $maxAttempts, Closure $callback, $decaySeconds = 60)
{
$this->attempted++;

return parent::attempt(...func_get_args());
}
});

Carbon::setTestNow('2000-01-01 00:00:00.000');
$handler->report(new Exception('Something in the app went wrong 1.'));
Carbon::setTestNow('2000-01-01 00:00:59.999');
$handler->report(new Exception('Something in the app went wrong 1.'));

$this->assertSame(2, $limiter->attempted);
$this->assertCount(1, $reported);
$this->assertSame('Something in the app went wrong 1.', $reported[0]->getMessage());

Carbon::setTestNow('2000-01-01 00:01:00.000');
$handler->report(new Exception('Something in the app went wrong 2.'));
Carbon::setTestNow('2000-01-01 00:01:59.999');
$handler->report(new Exception('Something in the app went wrong 2.'));

$this->assertSame(4, $limiter->attempted);
$this->assertCount(2, $reported);
$this->assertSame('Something in the app went wrong 2.', $reported[1]->getMessage());
}
}

class CustomException extends Exception
Expand Down