Skip to content

Commit

Permalink
Added seeUserPasswordDoesNotNeedRehash function (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
TavoNiievez authored Nov 16, 2020
1 parent bed4c5a commit 261f951
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/Codeception/Module/Symfony.php
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,44 @@ public function seeCurrentActionIs($action)
$this->fail("Action '$action' does not exist");
}

/**
* Checks that the user's password would not benefit from rehashing.
* If the user is not provided it is taken from the current session.
*
* You might use this function after performing tasks like registering a user or submitting a password update form.
*
* ```php
* <?php
* $I->seeUserPasswordDoesNotNeedRehash();
* $I->seeUserPasswordDoesNotNeedRehash($user);
* ```
*
* @param UserInterface|null $user
*/
public function seeUserPasswordDoesNotNeedRehash(UserInterface $user = null)
{
$container = $this->_getContainer();

if (!$user) {
if (!$container->has('security.helper')) {
$this->fail("Symfony container doesn't have 'security.helper' service");
}

$security = $this->grabService('security.helper');
if (!$user = $security->getUser()) {
$this->fail('No user found to validate');
}
}

if (!$container->has('security.user_password_encoder.generic')) {
$this->fail("Symfony container doesn't have 'security.user_password_encoder.generic' service");
}

$encoder = $this->grabService('security.user_password_encoder.generic');

$this->assertFalse($encoder->needsRehash($user), 'User password needs rehash');
}

public function amLoggedInAs(UserInterface $user, $firewallName = 'main', $firewallContext = null)
{
$container = $this->_getContainer();
Expand Down

0 comments on commit 261f951

Please sign in to comment.