Skip to content

Commit dd54c5a

Browse files
committed
Fix user password handling in Admin CP
1 parent e49c739 commit dd54c5a

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

app/Http/Controllers/Admin/UserController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ public function store(UserFormRequest $request)
161161
*
162162
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
163163
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
164-
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
165164
*/
166165
public function update(UserFormRequest $request, User $user)
167166
{

app/Services/Users/UserUpdateService.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ public function __construct(
5858
*/
5959
public function handle(User $user, array $data): Collection
6060
{
61-
if (array_has($data, 'password')) {
61+
if (! empty(array_get($data, 'password'))) {
6262
$data['password'] = $this->hasher->make($data['password']);
63+
} else {
64+
unset($data['password']);
6365
}
6466

6567
if ($this->isUserLevel(User::USER_LEVEL_ADMIN)) {

tests/Unit/Services/Users/UserUpdateServiceTest.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,38 @@ public function setUp()
4141
}
4242

4343
/**
44-
* Test that the handle function does not attempt to hash a password if no password is passed.
44+
* Test that the handle function does not attempt to hash a password if no
45+
* password is provided or the password is null.
46+
*
47+
* @dataProvider badPasswordDataProvider
4548
*/
46-
public function testUpdateUserWithoutTouchingHasherIfNoPasswordPassed()
49+
public function testUpdateUserWithoutTouchingHasherIfNoPasswordPassed(array $data)
4750
{
4851
$user = factory(User::class)->make();
4952
$this->revocationService->shouldReceive('getExceptions')->withNoArgs()->once()->andReturn([]);
5053
$this->repository->shouldReceive('update')->with($user->id, ['test-data' => 'value'])->once()->andReturnNull();
5154

52-
$response = $this->getService()->handle($user, ['test-data' => 'value']);
55+
$response = $this->getService()->handle($user, $data);
5356
$this->assertInstanceOf(Collection::class, $response);
5457
$this->assertTrue($response->has('model'));
5558
$this->assertTrue($response->has('exceptions'));
5659
}
5760

61+
/**
62+
* Provide a test data set with passwords that should not be hashed.
63+
*
64+
* @return array
65+
*/
66+
public function badPasswordDataProvider(): array
67+
{
68+
return [
69+
[['test-data' => 'value']],
70+
[['test-data' => 'value', 'password' => null]],
71+
[['test-data' => 'value', 'password' => '']],
72+
[['test-data' => 'value', 'password' => 0]],
73+
];
74+
}
75+
5876
/**
5977
* Test that the handle function hashes a password if passed in the data array.
6078
*/

0 commit comments

Comments
 (0)