added tests for too many emails sent
This commit is contained in:
parent
3d85092082
commit
c60b48d65f
@ -30,12 +30,16 @@ class TellFirewallTooManyEmailsSent
|
|||||||
|
|
||||||
public function loadConfig(): void
|
public function loadConfig(): void
|
||||||
{
|
{
|
||||||
|
if (! empty(Config::get('firewall.middleware.' . $this->middleware))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$config = array_merge_recursive(
|
$config = array_merge_recursive(
|
||||||
Config::get('firewall'),
|
Config::get('firewall'),
|
||||||
[
|
[
|
||||||
'middleware' => [
|
'middleware' => [
|
||||||
$this->middleware => [
|
$this->middleware => [
|
||||||
'enabled' => env('FIREWALL_MIDDLEWARE_' . strtoupper($this->middleware) . '_ENABLED', env('FIREWALL_ENABLED', true)),
|
'enabled' => env('FIREWALL_MIDDLEWARE_' . strtoupper($this->middleware) . '_ENABLED', Config::get('firewall.enabled', true)),
|
||||||
|
|
||||||
'methods' => ['post'],
|
'methods' => ['post'],
|
||||||
|
|
||||||
|
51
tests/Feature/Email/TooManyEmailsSentTest.php
Normal file
51
tests/Feature/Email/TooManyEmailsSentTest.php
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Email;
|
||||||
|
|
||||||
|
use App\Events\Email\TooManyEmailsSent;
|
||||||
|
use Tests\Feature\FeatureTestCase;
|
||||||
|
|
||||||
|
class TooManyEmailsSentTest extends FeatureTestCase
|
||||||
|
{
|
||||||
|
public function testItShouldNotBlockIpDueToTooManyEmailsSent()
|
||||||
|
{
|
||||||
|
$this->loginAs();
|
||||||
|
|
||||||
|
config(['firewall.enabled' => true]);
|
||||||
|
|
||||||
|
for ($i = 0; $i < 19; $i++) {
|
||||||
|
event(new TooManyEmailsSent(user_id()));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('firewall_logs', [
|
||||||
|
'user_id' => user_id(),
|
||||||
|
'middleware' => 'too_many_emails_sent',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertDatabaseCount('firewall_logs', 19);
|
||||||
|
|
||||||
|
$this->assertDatabaseEmpty('firewall_ips');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testItShouldBlockIpDueToTooManyEmailsSent()
|
||||||
|
{
|
||||||
|
$this->loginAs();
|
||||||
|
|
||||||
|
config(['firewall.enabled' => true]);
|
||||||
|
|
||||||
|
for ($i = 0; $i < 20; $i++) {
|
||||||
|
event(new TooManyEmailsSent(user_id()));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('firewall_logs', [
|
||||||
|
'user_id' => user_id(),
|
||||||
|
'middleware' => 'too_many_emails_sent',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertDatabaseCount('firewall_logs', 20);
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('firewall_ips', [
|
||||||
|
'ip' => request()->ip(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user