fix(pg,auth): prevent deactivated security guards from logging in and accessing pg module

This commit is contained in:
Ray1111-aa
2026-11-03 12:03:16 +07:00
parent 6e5c6eeeb8
commit c1be96c2ba
4 changed files with 53 additions and 0 deletions
+26
View File
@@ -175,4 +175,30 @@ class SecurityGuardFilterTest extends TestCase
$this->assertSoftDeleted('users', ['id' => $userId]);
}
}
/**
* Memastikan petugas Satpam yang dinonaktifkan tidak dapat login dan ditolak middleware.
*/
public function test_deactivated_guard_cannot_login_and_blocked_by_middleware(): void
{
$guard = SecurityGuard::with('user')->where('badge_id', 'SEC-001')->first();
$this->assertNotNull($guard);
$user = $guard->user;
$this->assertNotNull($user);
// 1. Nonaktifkan petugas satpam
$guard->update(['is_active' => false]);
// Coba login -> Harus ditolak
$loginResponse = $this->post(route('login'), [
'username' => $user->username,
'password' => 'password',
]);
$loginResponse->assertSessionHasErrors('username');
$this->assertGuest();
// 2. Jika dalam sesi aktif tapi di-nonaktifkan -> Middleware tolak dengan 403
$middlewareResponse = $this->actingAs($user)->get(route('pg.dashboard'));
$middlewareResponse->assertStatus(403);
}
}