Add tests for password changing
This commit is contained in:
parent
6e9123af19
commit
be2c76c24a
6 changed files with 32 additions and 10 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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'));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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.',
|
||||
],
|
||||
];
|
||||
|
|
|
@ -13,6 +13,7 @@ abstract class BasePage extends Page
|
|||
{
|
||||
return [
|
||||
'@@success' => '.alert.success[role="alert"]',
|
||||
'@@error' => '.alert.error[role="alert"]',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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']);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue