Skip to content
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

Added seeUserPasswordDoesNotNeedRehash function #29

Merged
merged 1 commit into from Nov 16, 2020
Merged

Added seeUserPasswordDoesNotNeedRehash function #29

merged 1 commit into from Nov 16, 2020

Conversation

TavoNiievez
Copy link
Member

@TavoNiievez TavoNiievez commented Nov 7, 2020

Method to verify that the user's password would not benefit from rehashing.

     $I->seeUserPasswordDoesNotNeedRehash();
     $I->seeUserPasswordDoesNotNeedRehash($user);

If the user is not specified it is taken from the session.

@DavertMik
Copy link
Member

I don't understand the context fully.
Could you specify where this method should be used?

@TavoNiievez
Copy link
Member Author

TavoNiievez commented Nov 14, 2020

Sure. This method is useful after persisting entities that implement the UserInterface, for example when registering a new user, or when submitting a password update form or forgotten password.

With this function you can verify that the password is correctly encrypted with the best available algorithm. (that is, the listener or event that you wrote to encode the user's password is working correctly.)

I will update the docblock to include the context where it is intended to be used.

@@ -1074,6 +1074,56 @@ public function seeCurrentActionIs($action)
$this->fail("Action '$action' does not exist");
}

/**
* Checks that the user's password is encrypted
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it odd that Symfony decided to name this feature password encoding
but using word "encrypted" is worse, because encrypting passwords is bad practice, they must be hashed.
I looked at Symfony Security component and it hashes passwords, except PlaintextPasswordEncoder.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's called 'encode' for historical reasons [1], i agree that using 'encrypt' left even more room for improvement.

However in the new description there is no mention of that word, thank you for letting me know.

$this->markTestIncomplete('User password needs rehash');
return;
}
$this->assertFalse($needsRehash);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your description says that this method Checks that the user's password is encrypted,
but I don't see that in the code.

If the second parameter is provided, this method checks if the password is correct.
otherwise it marks test as incomplete if password needs rehashing.

The behaviour of this method just doesn't match description,
I would replace it with 2 separate methods - seeUserPasswordIsValid and skipTestIfPasswordNeedsRehash.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Naktibalda Thank you!
Symfony does not provide a method to directly check if a password is encoded.

If for example, i have a password encoded with bcrypt, needsRehash would return true, because there are better algorithms like argon2... so i changed the name of the function.

Now there are no intermediate results with markTestIncomplete and i think that verifying that the password is encoded with the best possible algorithm is the only thing i want to assert.

@TavoNiievez TavoNiievez reopened this Nov 16, 2020
@TavoNiievez TavoNiievez changed the title Added seeUserPasswordIsEncoded function Added seeUserPasswordDoesNotNeedRehash function Nov 16, 2020
@TavoNiievez TavoNiievez reopened this Nov 16, 2020
@TavoNiievez TavoNiievez merged commit 261f951 into Codeception:master Nov 16, 2020
@TavoNiievez TavoNiievez deleted the seeUserPasswordIsEncoded branch November 16, 2020 16:26
@TavoNiievez TavoNiievez added this to the 1.3.0 milestone Nov 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants