diff --git a/app/Http/Requests/Api/Client/Account/UpdateEmailRequest.php b/app/Http/Requests/Api/Client/Account/UpdateEmailRequest.php index 0d8f9ea74..a990e79ba 100644 --- a/app/Http/Requests/Api/Client/Account/UpdateEmailRequest.php +++ b/app/Http/Requests/Api/Client/Account/UpdateEmailRequest.php @@ -21,7 +21,7 @@ class UpdateEmailRequest extends ClientApiRequest // Verify password matches when changing password or email. if (! password_verify($this->input('password'), $this->user()->password)) { - throw new InvalidPasswordProvidedException(trans('base.account.invalid_password')); + throw new InvalidPasswordProvidedException(trans('validation.internal.invalid_password')); } return true; diff --git a/app/Http/Requests/Api/Client/Account/UpdatePasswordRequest.php b/app/Http/Requests/Api/Client/Account/UpdatePasswordRequest.php index 2fe368f8c..12079f681 100644 --- a/app/Http/Requests/Api/Client/Account/UpdatePasswordRequest.php +++ b/app/Http/Requests/Api/Client/Account/UpdatePasswordRequest.php @@ -21,7 +21,7 @@ class UpdatePasswordRequest extends ClientApiRequest // Verify password matches when changing password or email. if (! password_verify($this->input('current_password'), $this->user()->password)) { - throw new InvalidPasswordProvidedException(trans('base.account.invalid_password')); + throw new InvalidPasswordProvidedException(trans('validation.internal.invalid_password')); } return true; diff --git a/app/Http/Requests/Base/AccountDataFormRequest.php b/app/Http/Requests/Base/AccountDataFormRequest.php index 0d24b7a16..74a00f7c6 100644 --- a/app/Http/Requests/Base/AccountDataFormRequest.php +++ b/app/Http/Requests/Base/AccountDataFormRequest.php @@ -28,7 +28,7 @@ class AccountDataFormRequest extends FrontendUserFormRequest // Verify password matches when changing password or email. if (in_array($this->input('do_action'), ['password', 'email'])) { if (! password_verify($this->input('current_password'), $this->user()->password)) { - throw new InvalidPasswordProvidedException(trans('base.account.invalid_password')); + throw new InvalidPasswordProvidedException(trans('validation.internal.invalid_password')); } } diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php index 201880ec9..a82aaa1be 100644 --- a/resources/lang/en/validation.php +++ b/resources/lang/en/validation.php @@ -101,5 +101,6 @@ return [ // Internal validation logic for Pterodactyl 'internal' => [ 'variable_value' => ':env variable', + 'invalid_password' => 'The password provided was invalid for this account.', ], ]; diff --git a/tests/Browser/Pages/BasePage.php b/tests/Browser/Pages/BasePage.php index 075634c40..c2e451a3d 100644 --- a/tests/Browser/Pages/BasePage.php +++ b/tests/Browser/Pages/BasePage.php @@ -13,6 +13,7 @@ abstract class BasePage extends Page { return [ '@@success' => '.alert.success[role="alert"]', + '@@error' => '.alert.error[role="alert"]', ]; } } diff --git a/tests/Browser/Processes/Dashboard/AccountEmailProcessTest.php b/tests/Browser/Processes/Dashboard/AccountEmailProcessTest.php index 7e249d6cd..013bb9fc2 100644 --- a/tests/Browser/Processes/Dashboard/AccountEmailProcessTest.php +++ b/tests/Browser/Processes/Dashboard/AccountEmailProcessTest.php @@ -2,8 +2,6 @@ namespace Pterodactyl\Tests\Browser\Processes\Dashboard; -use Pterodactyl\Models\User; -use Illuminate\Support\Facades\Hash; use Pterodactyl\Tests\Browser\BrowserTestCase; use Pterodactyl\Tests\Browser\PterodactylBrowser; use Pterodactyl\Tests\Browser\Pages\Dashboard\AccountPage; @@ -16,17 +14,18 @@ class AccountEmailProcessTest extends BrowserTestCase private $user; /** - * Setup a user for the test process to use. + * Setup tests. */ - public function setUp() + protected function setUp() { parent::setUp(); - $this->user = factory(User::class)->create([ - 'password' => Hash::make('Password123'), - ]); + $this->user = $this->user(); } + /** + * Test that an email address can be changed successfully. + */ public function testEmailCanBeChanged() { $this->browse(function (PterodactylBrowser $browser) { @@ -43,4 +42,25 @@ class AccountEmailProcessTest extends BrowserTestCase $this->assertDatabaseHas('users', ['id' => $this->user->id, 'email' => 'new.email@example.com']); }); } + + /** + * Test that entering the wrong password for an account returns an error. + */ + public function testInvalidPasswordShowsError() + { + $this->browse(function (PterodactylBrowser $browser) { + $browser->loginAs($this->user) + ->visit(new AccountPage) + ->type('@email', 'new.email@example.com') + ->click('@submit') + ->assertFocused('@password') + ->type('@password', 'test1234') + ->click('@submit') + ->waitFor('@@error') + ->assertSeeIn('@@error', trans('validation.internal.invalid_password')) + ->assertValue('@email', 'new.email@example.com'); + + $this->assertDatabaseMissing('users', ['id' => $this->user->id, 'email' => 'new.email@example.com']); + }); + } }