Skip to content

Conversation

@robertpustulka
Copy link
Member

@robertpustulka robertpustulka commented Apr 23, 2021

This adds missing tests for calling persistIdentity() and setIdentity() with identity instance.

Refs #448

PS. I've also removed deprecated method calls form tests.


$service = new AuthenticationService();

$result = $service->persistIdentity($request, $response, $identity);
Copy link
Member

@ADmad ADmad Apr 23, 2021

Choose a reason for hiding this comment

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

Passing an Identity instance here would mean SessionAuthenticate would store that instance in the session. But when one uses form login the instance stored in session is an Entity (or array), not an IdentityInterface instance.

IMO it's better to avoid such discrepancy. The authenticators should always deal with the "raw" identity object and only AuthenticationService should deal with IdentityInterface instances.

Copy link
Member

@ADmad ADmad Apr 23, 2021

Choose a reason for hiding this comment

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

That said a clean way to fix the regression would be make buildIdentity() simply return the argument if it's already an IdentityInterface instance. That would also avoid the object type checks at multiple places.

Copy link
Member Author

Choose a reason for hiding this comment

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

The authenticators should always deal with the "raw" identity object and decorating it with IdentityInterface should be left to AuthenticationService.

The thing is that sometimes the "raw" identity object is an identity instance itself. If your User entity already implements IdentityInterface that is. And this test covers that case.

Copy link
Member

@ADmad ADmad Apr 23, 2021

Choose a reason for hiding this comment

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

If your User entity already implements IdentityInterface that is.

Ah, I had overlooked that case. Could you please add a comment stating this info in the relevant test case.

Copy link
Member Author

Choose a reason for hiding this comment

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

@ADmad done and done.

@markstory markstory merged commit e4c17b4 into cakephp:master Apr 23, 2021
@robertpustulka robertpustulka deleted the identity-wrap-fix branch April 23, 2021 14:39
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.

3 participants