Merge branch 'main' into koda/137-user-edit-flow
This commit is contained in:
@@ -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.'),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,54 @@ 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')
|
||||
->where('status', null),
|
||||
);
|
||||
}
|
||||
|
||||
public function test_forced_password_change_page_exposes_a_logout_action()
|
||||
{
|
||||
$user = User::factory()->create([
|
||||
'must_change_password_on_next_login' => true,
|
||||
]);
|
||||
|
||||
$this->actingAs($user)
|
||||
->get(route('password.force-change.edit'))
|
||||
->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 +182,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();
|
||||
@@ -157,4 +227,26 @@ class SecurityTest extends TestCase
|
||||
->assertSessionHasErrors('current_password')
|
||||
->assertRedirect(route('security.edit'));
|
||||
}
|
||||
|
||||
public function test_new_password_must_be_different_from_the_current_password()
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this
|
||||
->actingAs($user)
|
||||
->from(route('security.edit'))
|
||||
->put(route('user-password.update'), [
|
||||
'current_password' => 'password',
|
||||
'password' => 'password',
|
||||
'password_confirmation' => 'password',
|
||||
]);
|
||||
|
||||
$response
|
||||
->assertSessionHasErrors([
|
||||
'password' => 'The new password must be different from your current password.',
|
||||
])
|
||||
->assertRedirect(route('security.edit'));
|
||||
|
||||
$this->assertTrue(Hash::check('password', $user->fresh()->password));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user