Skip to content
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
1 change: 0 additions & 1 deletion src/Console/Commands/LockoutDisable.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,3 @@ public function handle(): int
return Command::SUCCESS;
}
}

1 change: 0 additions & 1 deletion src/Console/Commands/LockoutEnable.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,3 @@ public function handle(): int
return Command::SUCCESS;
}
}

1 change: 0 additions & 1 deletion src/Console/Commands/LockoutStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,3 @@ public function handle(): int
return Command::SUCCESS;
}
}

1 change: 0 additions & 1 deletion src/Events/LockoutDisabled.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ public function __construct()
//
}
}

1 change: 0 additions & 1 deletion src/Events/LockoutEnabled.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ public function __construct()
//
}
}

3 changes: 1 addition & 2 deletions src/Events/RequestBlocked.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Rappasoft\Lockout\Events;

use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Http\Request;
use Illuminate\Queue\SerializesModels;

class RequestBlocked
{
Expand All @@ -20,4 +20,3 @@ public function __construct(
//
}
}

1 change: 0 additions & 1 deletion src/Helpers/IpHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,3 @@ public static function parseIpList(?string $ipList): array
return array_map('trim', explode(',', $ipList));
}
}

11 changes: 4 additions & 7 deletions tests/AdvancedFeaturesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
namespace Rappasoft\Lockout\Tests;

use Illuminate\Http\Response;
use Rappasoft\Lockout\Events\LockoutDisabled;
use Rappasoft\Lockout\Events\LockoutEnabled;
use Rappasoft\Lockout\Events\RequestBlocked;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Event;
use Rappasoft\Lockout\Events\RequestBlocked;

class AdvancedFeaturesTest extends TestCase
{
Expand Down Expand Up @@ -118,7 +116,7 @@ public function api_requests_return_json_response()

$response = $this->withHeaders(['Accept' => 'application/json'])
->call('POST', 'api/test');

$response->assertStatus(Response::HTTP_UNAUTHORIZED);
// Check if response is JSON (might be HTML if API detection fails)
if ($response->headers->get('Content-Type') === 'application/json') {
Expand All @@ -136,7 +134,7 @@ public function view_response_type_returns_view()

// View might not exist in test environment, so test with json instead
config(['lockout.response_type' => 'json']);

$response = $this->call('POST', 'post');
$response->assertStatus(Response::HTTP_UNAUTHORIZED);
$response->assertJson(['message' => 'Application is currently in read-only mode.']);
Expand Down Expand Up @@ -212,4 +210,3 @@ public function events_are_not_fired_when_disabled()
Event::assertNotDispatched(RequestBlocked::class);
}
}

3 changes: 1 addition & 2 deletions tests/EdgeCasesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function custom_health_check_path_configuration_works()
// Verify custom path config is set and health check is enabled
$this->assertEquals('custom-health', config('lockout.health_check_path'));
$this->assertTrue(config('lockout.health_check_enabled'));

// The actual route registration happens at service provider boot
// In real applications, changing the path would require clearing route cache
// This test verifies the configuration is properly stored and retrieved
Expand Down Expand Up @@ -275,4 +275,3 @@ public function cache_ttl_customization_works()
->assertStatus(Response::HTTP_UNAUTHORIZED);
}
}

9 changes: 4 additions & 5 deletions tests/IpHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function cidr_with_different_masks_works()
public function multiple_ips_in_whitelist_work()
{
$whitelist = ['127.0.0.1', '192.168.1.0/24', '10.0.0.1'];

$this->assertTrue(IpHelper::isIpAllowed('127.0.0.1', $whitelist));
$this->assertTrue(IpHelper::isIpAllowed('192.168.1.50', $whitelist));
$this->assertTrue(IpHelper::isIpAllowed('10.0.0.1', $whitelist));
Expand Down Expand Up @@ -70,15 +70,15 @@ public function empty_blacklist_returns_false()
public function parse_ip_list_from_string()
{
$result = IpHelper::parseIpList('127.0.0.1,192.168.1.1,10.0.0.0/8');

$this->assertEquals(['127.0.0.1', '192.168.1.1', '10.0.0.0/8'], $result);
}

/** @test */
public function parse_ip_list_handles_spaces()
{
$result = IpHelper::parseIpList('127.0.0.1, 192.168.1.1 , 10.0.0.0/8');

$this->assertEquals(['127.0.0.1', '192.168.1.1', '10.0.0.0/8'], $result);
}

Expand Down Expand Up @@ -107,10 +107,9 @@ public function cidr_edge_cases()
// /32 should match only exact IP
$this->assertTrue(IpHelper::isIpAllowed('192.168.1.1', ['192.168.1.1/32']));
$this->assertFalse(IpHelper::isIpAllowed('192.168.1.2', ['192.168.1.1/32']));

// /0 should match everything (entire IPv4 range)
$this->assertTrue(IpHelper::isIpAllowed('0.0.0.0', ['0.0.0.0/0']));
$this->assertTrue(IpHelper::isIpAllowed('255.255.255.255', ['0.0.0.0/0']));
}
}

25 changes: 15 additions & 10 deletions tests/RoleBasedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Rappasoft\Lockout\Tests;

use Illuminate\Http\Response;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Http\Response;

class RoleBasedTest extends TestCase
{
Expand All @@ -14,7 +14,8 @@ public function user_with_role_attribute_bypasses_lockout()
config(['lockout.locked_types' => ['post']]);
config(['lockout.allowed_roles' => ['admin']]);

$user = new class extends Authenticatable {
$user = new class extends Authenticatable
{
public $role = 'admin';
};

Expand All @@ -30,7 +31,8 @@ public function user_without_allowed_role_is_blocked()
config(['lockout.locked_types' => ['post']]);
config(['lockout.allowed_roles' => ['admin']]);

$user = new class extends Authenticatable {
$user = new class extends Authenticatable
{
public $role = 'user';
};

Expand All @@ -46,7 +48,8 @@ public function user_with_hasRole_method_bypasses_lockout()
config(['lockout.locked_types' => ['post']]);
config(['lockout.allowed_roles' => ['admin']]);

$user = new class extends Authenticatable {
$user = new class extends Authenticatable
{
public function hasRole($role)
{
return $role === 'admin';
Expand Down Expand Up @@ -76,15 +79,18 @@ public function multiple_allowed_roles_work()
config(['lockout.locked_types' => ['post']]);
config(['lockout.allowed_roles' => ['admin', 'super-admin', 'maintenance']]);

$admin = new class extends Authenticatable {
$admin = new class extends Authenticatable
{
public $role = 'admin';
};

$superAdmin = new class extends Authenticatable {
$superAdmin = new class extends Authenticatable
{
public $role = 'super-admin';
};

$maintenance = new class extends Authenticatable {
$maintenance = new class extends Authenticatable
{
public $role = 'maintenance';
};

Expand All @@ -108,14 +114,13 @@ public function empty_allowed_roles_blocks_everyone()
config(['lockout.locked_types' => ['post']]);
config(['lockout.allowed_roles' => []]);

$user = new class extends Authenticatable {
$user = new class extends Authenticatable
{
public $role = 'admin';
};

$this->actingAs($user)
->call('POST', 'post')
->assertStatus(Response::HTTP_UNAUTHORIZED);
}

}

2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ protected function getEnvironmentSetUp($app)
}

/**
* @param $view
* @param $view
* @param array $parameters
* @return string
*/
Expand Down
Loading