From b8b0e3200ec57b1ce981937d4a1957a86e8a33f4 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 27 Mar 2025 17:27:28 -0700 Subject: [PATCH] Add tests around loggin login attempts --- tests/Feature/Authentication/LoginTest.php | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/Feature/Authentication/LoginTest.php diff --git a/tests/Feature/Authentication/LoginTest.php b/tests/Feature/Authentication/LoginTest.php new file mode 100644 index 000000000..85bbc78ad --- /dev/null +++ b/tests/Feature/Authentication/LoginTest.php @@ -0,0 +1,49 @@ +create(['username' => 'username_here']); + + $this->withServerVariables(['REMOTE_ADDR' => '127.0.0.100']) + ->post('/login', [ + 'username' => 'username_here', + 'password' => 'not a real password', + ], [ + 'User-Agent' => 'Some Custom User Agent', + ]); + + $this->assertDatabaseHas('login_attempts', [ + 'username' => 'username_here', + 'remote_ip' => '127.0.0.100', + 'user_agent' => 'Some Custom User Agent', + 'successful' => 0, + ]); + } + + public function testLogsSuccessfulLogin() + { + User::factory()->create(['username' => 'username_here']); + + $this->withServerVariables(['REMOTE_ADDR' => '127.0.0.100']) + ->post('/login', [ + 'username' => 'username_here', + 'password' => 'password', + ], [ + 'User-Agent' => 'Some Custom User Agent', + ]); + + $this->assertDatabaseHas('login_attempts', [ + 'username' => 'username_here', + 'remote_ip' => '127.0.0.100', + 'user_agent' => 'Some Custom User Agent', + 'successful' => 1, + ]); + } +}