Skip to content

Commit 261f951

Browse files
authored
Added seeUserPasswordDoesNotNeedRehash function (#29)
1 parent bed4c5a commit 261f951

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/Codeception/Module/Symfony.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,44 @@ public function seeCurrentActionIs($action)
11391139
$this->fail("Action '$action' does not exist");
11401140
}
11411141

1142+
/**
1143+
* Checks that the user's password would not benefit from rehashing.
1144+
* If the user is not provided it is taken from the current session.
1145+
*
1146+
* You might use this function after performing tasks like registering a user or submitting a password update form.
1147+
*
1148+
* ```php
1149+
* <?php
1150+
* $I->seeUserPasswordDoesNotNeedRehash();
1151+
* $I->seeUserPasswordDoesNotNeedRehash($user);
1152+
* ```
1153+
*
1154+
* @param UserInterface|null $user
1155+
*/
1156+
public function seeUserPasswordDoesNotNeedRehash(UserInterface $user = null)
1157+
{
1158+
$container = $this->_getContainer();
1159+
1160+
if (!$user) {
1161+
if (!$container->has('security.helper')) {
1162+
$this->fail("Symfony container doesn't have 'security.helper' service");
1163+
}
1164+
1165+
$security = $this->grabService('security.helper');
1166+
if (!$user = $security->getUser()) {
1167+
$this->fail('No user found to validate');
1168+
}
1169+
}
1170+
1171+
if (!$container->has('security.user_password_encoder.generic')) {
1172+
$this->fail("Symfony container doesn't have 'security.user_password_encoder.generic' service");
1173+
}
1174+
1175+
$encoder = $this->grabService('security.user_password_encoder.generic');
1176+
1177+
$this->assertFalse($encoder->needsRehash($user), 'User password needs rehash');
1178+
}
1179+
11421180
public function amLoggedInAs(UserInterface $user, $firewallName = 'main', $firewallContext = null)
11431181
{
11441182
$container = $this->_getContainer();

0 commit comments

Comments
 (0)