Files
projectsend/tests/Feature/Settings/PasswordUpdateTest.php
T
ignacionelson 6e47d76ba6 ProjectSend 2.0.0
Client file sharing, rebuilt from the ground up: a private area per
client, resumable uploads, folders, groups and categories, sharing with
expiry dates and download limits, comments, file versions, an activity
log, a REST API, and sixteen languages.

This repository begins here. ProjectSend 2 was developed privately, and
that development history is not published — the previous generation
remains available, with its own history, at projectsend/legacy.

Free software under the GNU General Public License v2, or (at your
option) any later version.
2026-08-14 01:38:12 -03:00

83 lines
2.7 KiB
PHP

<?php
namespace Tests\Feature\Settings;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Hash;
use Tests\TestCase;
class PasswordUpdateTest extends TestCase
{
use RefreshDatabase;
public function test_password_can_be_updated()
{
$user = User::factory()->create();
$response = $this
->actingAs($user)
->from('/settings/password')
->put('/settings/password', [
'current_password' => 'password',
'password' => 'new-password',
'password_confirmation' => 'new-password',
]);
$response
->assertSessionHasNoErrors()
->assertRedirect('/settings/password');
$this->assertTrue(Hash::check('new-password', $user->refresh()->password));
}
/**
* Changing a password is how someone reacts to a session they believe is
* stolen, so it has to actually end that session. AuthenticateSession
* binds each session to the password hash it was created under; the
* session doing the change is re-stamped, every other one fails its next
* request.
*/
public function test_changing_the_password_invalidates_the_accounts_other_sessions()
{
$user = User::factory()->create();
$oldHash = $user->password;
$this->actingAs($user)
->from('/settings/password')
->put('/settings/password', [
'current_password' => 'password',
'password' => 'new-password',
'password_confirmation' => 'new-password',
])->assertSessionHasNoErrors();
// The session that made the change carries the new hash and stays in.
$this->assertNotSame($oldHash, session('password_hash_web'));
$this->actingAs($user)->get('/settings/password')->assertOk();
// Another session, still holding the pre-change hash, is turned away.
$this->flushSession();
$this->withSession(['password_hash_web' => $oldHash]);
$this->actingAs($user)->get('/settings/password')->assertRedirect('/login');
$this->assertGuest();
}
public function test_correct_password_must_be_provided_to_update_password()
{
$user = User::factory()->create();
$response = $this
->actingAs($user)
->from('/settings/password')
->put('/settings/password', [
'current_password' => 'wrong-password',
'password' => 'new-password',
'password_confirmation' => 'new-password',
]);
$response
->assertSessionHasErrors('current_password')
->assertRedirect('/settings/password');
}
}