Skip to content

Added seeUserPasswordDoesNotNeedRehash function #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/Codeception/Module/Symfony.php
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,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