Skip to content

Commit be2c76c

Browse files
committed
Add tests for password changing
1 parent 6e9123a commit be2c76c

File tree

6 files changed

+32
-10
lines changed

6 files changed

+32
-10
lines changed

app/Http/Requests/Api/Client/Account/UpdateEmailRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function authorize(): bool
2121

2222
// Verify password matches when changing password or email.
2323
if (! password_verify($this->input('password'), $this->user()->password)) {
24-
throw new InvalidPasswordProvidedException(trans('base.account.invalid_password'));
24+
throw new InvalidPasswordProvidedException(trans('validation.internal.invalid_password'));
2525
}
2626

2727
return true;

app/Http/Requests/Api/Client/Account/UpdatePasswordRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function authorize(): bool
2121

2222
// Verify password matches when changing password or email.
2323
if (! password_verify($this->input('current_password'), $this->user()->password)) {
24-
throw new InvalidPasswordProvidedException(trans('base.account.invalid_password'));
24+
throw new InvalidPasswordProvidedException(trans('validation.internal.invalid_password'));
2525
}
2626

2727
return true;

app/Http/Requests/Base/AccountDataFormRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function authorize()
2828
// Verify password matches when changing password or email.
2929
if (in_array($this->input('do_action'), ['password', 'email'])) {
3030
if (! password_verify($this->input('current_password'), $this->user()->password)) {
31-
throw new InvalidPasswordProvidedException(trans('base.account.invalid_password'));
31+
throw new InvalidPasswordProvidedException(trans('validation.internal.invalid_password'));
3232
}
3333
}
3434

resources/lang/en/validation.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,6 @@
101101
// Internal validation logic for Pterodactyl
102102
'internal' => [
103103
'variable_value' => ':env variable',
104+
'invalid_password' => 'The password provided was invalid for this account.',
104105
],
105106
];

tests/Browser/Pages/BasePage.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public static function siteElements()
1313
{
1414
return [
1515
'@@success' => '.alert.success[role="alert"]',
16+
'@@error' => '.alert.error[role="alert"]',
1617
];
1718
}
1819
}

tests/Browser/Processes/Dashboard/AccountEmailProcessTest.php

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Pterodactyl\Tests\Browser\Processes\Dashboard;
44

5-
use Pterodactyl\Models\User;
6-
use Illuminate\Support\Facades\Hash;
75
use Pterodactyl\Tests\Browser\BrowserTestCase;
86
use Pterodactyl\Tests\Browser\PterodactylBrowser;
97
use Pterodactyl\Tests\Browser\Pages\Dashboard\AccountPage;
@@ -16,17 +14,18 @@ class AccountEmailProcessTest extends BrowserTestCase
1614
private $user;
1715

1816
/**
19-
* Setup a user for the test process to use.
17+
* Setup tests.
2018
*/
21-
public function setUp()
19+
protected function setUp()
2220
{
2321
parent::setUp();
2422

25-
$this->user = factory(User::class)->create([
26-
'password' => Hash::make('Password123'),
27-
]);
23+
$this->user = $this->user();
2824
}
2925

26+
/**
27+
* Test that an email address can be changed successfully.
28+
*/
3029
public function testEmailCanBeChanged()
3130
{
3231
$this->browse(function (PterodactylBrowser $browser) {
@@ -43,4 +42,25 @@ public function testEmailCanBeChanged()
4342
$this->assertDatabaseHas('users', ['id' => $this->user->id, 'email' => 'new.email@example.com']);
4443
});
4544
}
45+
46+
/**
47+
* Test that entering the wrong password for an account returns an error.
48+
*/
49+
public function testInvalidPasswordShowsError()
50+
{
51+
$this->browse(function (PterodactylBrowser $browser) {
52+
$browser->loginAs($this->user)
53+
->visit(new AccountPage)
54+
->type('@email', 'new.email@example.com')
55+
->click('@submit')
56+
->assertFocused('@password')
57+
->type('@password', 'test1234')
58+
->click('@submit')
59+
->waitFor('@@error')
60+
->assertSeeIn('@@error', trans('validation.internal.invalid_password'))
61+
->assertValue('@email', 'new.email@example.com');
62+
63+
$this->assertDatabaseMissing('users', ['id' => $this->user->id, 'email' => 'new.email@example.com']);
64+
});
65+
}
4666
}

0 commit comments

Comments
 (0)