useLegacyDatabase(); } public function test_staff_logs_in_with_legacy_credentials(): void { $this->post(route('login.store'), ['username' => '198001012005011001', 'password' => 'rahasia-staf']) ->assertRedirect(route('operator.dashboard')); $user = Auth::user(); $this->assertInstanceOf(Account::class, $user); $this->assertSame('Dr. Budi Santoso, S.T., M.T.', $user->name); $this->assertSame('Staff Fakultas', $user->profile->jabatan); $this->assertSame('Fakultas Teknik', $user->profile->unit_kerja); $this->get(route('operator.dashboard')) ->assertOk() ->assertSee('Selamat Datang, Dr. Budi Santoso, S.T., M.T.!'); } public function test_session_is_restored_from_legacy_account(): void { $this->post(route('login.store'), ['username' => 'D1041191001', 'password' => 'rahasia-mhs']) ->assertRedirect(route('mahasiswa.dashboard')); Auth::forgetGuards(); $this->get(route('mahasiswa.dashboard'))->assertOk()->assertSee('D1041191001'); $this->get(route('operator.dashboard'))->assertForbidden(); } public function test_dosen_without_otoritas_logs_in_as_dosen(): void { $this->post(route('login.store'), ['username' => '197501012000031002', 'password' => 'rahasia-dosen']) ->assertRedirect(route('dosen.dashboard')); $this->assertSame('0001017501', Auth::user()->profile->nidn); $this->assertSame('Lektor', Auth::user()->profile->jabatan_fungsional); } public function test_wrong_password_fails_generically(): void { $this->from(route('login')) ->post(route('login.store'), ['username' => '198001012005011001', 'password' => 'rahasia-dosen']) ->assertRedirect(route('login')) ->assertSessionHasErrors(['username' => trans('auth.failed')]); $this->assertGuest(); } public function test_frozen_account_fails_generically(): void { $this->from(route('login')) ->post(route('login.store'), ['username' => '196001011990011001', 'password' => 'rahasia-beku']) ->assertSessionHasErrors(['username' => trans('auth.failed')]); $this->assertGuest(); } public function test_employee_without_role_cannot_log_in(): void { $this->from(route('login')) ->post(route('login.store'), ['username' => '199001012015011001', 'password' => 'rahasia-pegawai']) ->assertSessionHasErrors(['username' => trans('auth.failed')]); $this->assertGuest(); } public function test_login_does_not_write_to_legacy_database(): void { $before = DB::connection('untan')->table('t_account')->where('iduser', 1)->first(); $this->post(route('login.store'), ['username' => '198001012005011001', 'password' => 'rahasia-staf']); $this->assertEquals($before, DB::connection('untan')->table('t_account')->where('iduser', 1)->first()); } public function test_database_error_during_login_does_not_expose_the_password(): void { $account = Auth::createUserProvider('legacy')->retrieveById(1); DB::connection('untan')->statement('drop table t_account'); try { Auth::createUserProvider('legacy')->validateCredentials($account, ['password' => 'rahasia-staf']); $this->fail('Galat DB seharusnya dilempar.'); } catch (\RuntimeException $e) { $this->assertStringNotContainsString('rahasia-staf', $e->getMessage()); $this->assertNull($e->getPrevious()); } } }