-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
93 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,19 +7,21 @@ | |
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Illuminate\Http\Response; | ||
use Illuminate\Support\Facades\Hash; | ||
use Tests\HasPwnedMock; | ||
use Tests\TestCase; | ||
|
||
/** @see \App\Http\Controllers\Auth\ResetPasswordController */ | ||
class ResetPasswordControllerTest extends TestCase | ||
{ | ||
use RefreshDatabase, HasPwnedMock; | ||
use RefreshDatabase; | ||
|
||
/** @var string */ | ||
private $password; | ||
|
||
public function setUp() : void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->mockPwned(); | ||
$this->password = password_generator(); | ||
} | ||
|
||
/** @test */ | ||
|
@@ -44,13 +46,13 @@ public function user_with_valid_token_can_reset_his_password() | |
$response = $this->post('password/reset', [ | ||
'token' => $token, | ||
'email' => '[email protected]', | ||
'password' => 'new-password', | ||
'password_confirmation' => 'new-password', | ||
'password' => $this->password, | ||
'password_confirmation' => $this->password, | ||
]); | ||
|
||
$response->assertRedirect(route('home.index')); | ||
|
||
$this->assertTrue(Hash::check('new-password', $user->fresh()->password)); | ||
$this->assertTrue(Hash::check($this->password, $user->fresh()->password)); | ||
|
||
$this->assertAuthenticatedAs($user); | ||
} | ||
|
@@ -123,7 +125,7 @@ public function clientFormValidationProvider() | |
'Test email is required' => ['email', ''], | ||
'Test email is valid' => ['email', 'not-an-email'], | ||
'Test password is required' => ['password', ''], | ||
'Test password must be greater than 7' => ['password', '1234567'], | ||
'Test password must be greater than 7' => ['password', too_short_password()], | ||
]; | ||
} | ||
|
||
|
@@ -136,8 +138,8 @@ public function password_must_be_confirmed() | |
]); | ||
|
||
$validParams = $this->validParams($user, [ | ||
'password' => 'password', | ||
'password_confirmation' => 'non-matching-password', | ||
'password' => $this->password, | ||
'password_confirmation' => $this->password.'-non-matching-password', | ||
]); | ||
|
||
$response = $this->from(route('password.reset', ['token' => $validParams['token']])) | ||
|
@@ -151,18 +153,16 @@ public function password_must_be_confirmed() | |
} | ||
|
||
/** @test */ | ||
public function password_must_not_be_pwned() | ||
public function password_must_uncompromised() | ||
{ | ||
$this->mockPwned(false); | ||
|
||
$user = UserFactory::new()->create([ | ||
'email' => '[email protected]', | ||
'password' => bcrypt('password'), | ||
'password' => bcrypt('old-password'), | ||
]); | ||
|
||
$validParams = $this->validParams($user, [ | ||
'password' => 'new-password', | ||
'password_confirmation' => 'new-password', | ||
'password' => 'password', | ||
'password_confirmation' => 'password', | ||
]); | ||
|
||
$response = $this->from(route('password.reset', ['token' => $validParams['token']])) | ||
|
@@ -171,7 +171,7 @@ public function password_must_not_be_pwned() | |
$response->assertRedirect(route('password.reset', ['token' => $validParams['token']])) | ||
->assertInvalid('password'); | ||
|
||
$this->assertTrue(Hash::check('password', $user->fresh()->password)); | ||
$this->assertTrue(Hash::check('old-password', $user->fresh()->password)); | ||
$this->assertGuest(); | ||
} | ||
|
||
|
@@ -194,8 +194,8 @@ private function validParams($user, $overrides = []) | |
return array_merge([ | ||
'token' => $token, | ||
'email' => '[email protected]', | ||
'password' => 'new-password', | ||
'password_confirmation' => 'new-password', | ||
'password' => $this->password, | ||
'password_confirmation' => $this->password, | ||
], $overrides); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.