Refine forced password change flow
linter / quality (pull_request) Successful in 1m19s
tests / ci (8.4) (pull_request) Successful in 1m31s

This commit is contained in:
2026-05-22 18:57:10 +00:00
parent d13e919310
commit 5bb6e57db4
6 changed files with 204 additions and 6 deletions
+3 -2
View File
@@ -33,7 +33,7 @@ class AuthenticationTest extends TestCase
$response->assertRedirect(route('dashboard', absolute: false));
}
public function test_users_who_must_change_their_password_are_redirected_to_security_settings_after_login()
public function test_users_who_must_change_their_password_are_redirected_to_the_dedicated_force_change_page_after_login()
{
$user = User::factory()->create([
'must_change_password_on_next_login' => true,
@@ -46,7 +46,8 @@ class AuthenticationTest extends TestCase
$this->assertAuthenticated();
$response->assertInertia(fn (Assert $page) => $page
->component('auth/ConfirmPassword'),
->component('auth/ForcePasswordChange')
->where('status', 'You must change your password before continuing.'),
);
}
+58 -2
View File
@@ -97,7 +97,40 @@ class SecurityTest extends TestCase
$this->actingAs($user)
->get(route('dashboard'))
->assertRedirect(route('security.edit'));
->assertRedirect(route('password.force-change.edit'));
}
public function test_users_who_must_change_their_password_can_view_the_dedicated_force_change_page()
{
$user = User::factory()->create([
'must_change_password_on_next_login' => true,
]);
$this->actingAs($user)
->get(route('password.force-change.edit'))
->assertOk()
->assertInertia(fn (Assert $page) => $page
->component('auth/ForcePasswordChange'),
);
}
public function test_users_who_must_change_their_password_are_not_sent_to_the_normal_security_page()
{
$this->skipUnlessFortifyFeature(Features::twoFactorAuthentication());
Features::twoFactorAuthentication([
'confirm' => true,
'confirmPassword' => true,
]);
$user = User::factory()->create([
'must_change_password_on_next_login' => true,
]);
$this->actingAs($user)
->withSession(['auth.password_confirmed_at' => time()])
->get(route('security.edit'))
->assertRedirect(route('password.force-change.edit'));
}
public function test_password_can_be_updated()
@@ -135,11 +168,34 @@ class SecurityTest extends TestCase
'password_confirmation' => 'new-password',
])
->assertSessionHasNoErrors()
->assertRedirect(route('security.edit'));
->assertRedirect(route('dashboard'));
$this->assertFalse((bool) $user->refresh()->must_change_password_on_next_login);
}
public function test_forced_password_change_returns_the_user_to_their_intended_page_after_updating()
{
$user = User::factory()->create([
'must_change_password_on_next_login' => true,
]);
$this->actingAs($user)
->get(route('dashboard'));
$this->actingAs($user)
->from(route('password.force-change.edit'))
->put(route('user-password.update'), [
'current_password' => 'password',
'password' => 'new-password',
'password_confirmation' => 'new-password',
])
->assertSessionHasNoErrors()
->assertRedirect(route('dashboard'));
$this->assertFalse((bool) $user->refresh()->must_change_password_on_next_login);
$this->assertTrue(Hash::check('new-password', $user->password));
}
public function test_correct_password_must_be_provided_to_update_password()
{
$user = User::factory()->create();