8000 [HttpKernel] Make AbstractTestSessionListener compatible with CookieClearingLogoutHandler by thewilkybarkid · Pull Request #27659 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpKernel] Make AbstractTestSessionListener compatible with CookieClearingLogoutHandler #27659

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

Conversation

thewilkybarkid
Copy link
Contributor
Q A
Branch? 3.4
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

#26157 started to send a new cookie in AbstractTestSessionListener, but is incompatible with CookieClearingLogoutHandler as it overrides its Set-Cookie by setting a new cookie (breaking my test that checked to see that the cookie was removed after a log out).

@nicolas-grekas
Copy link
Member

ping @rpkamp I suppose.

@@ -71,6 +71,13 @@ public function onKernelResponse(FilterResponseEvent $event)

if ($session instanceof Session ? !$session->isEmpty() || (null !== $this->sessionId && $session->getId() !== $this->sessionId) : $wasStarted) {
$params = session_get_cookie_params();

foreach ($event->getResponse()->headers->getCookies() as $cookie) {
if ($session->getName() === $cookie->getName() && $params['path'] == $cookie->getPath() && $params['domain'] == $cookie->getDomain()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use === instead of ==

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They could be null or empty strings.

Copy link
Member

Choose a reason for hiding this comment

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

can you add a test case where this would fail when the first == is turned into a === please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking again, the path will always be a string and at least /, so can make that comparison strict. The domain, however, is null in Cookie but an empty string in $params['domain'] (so the existing test cases already fail if that's made strict).

Copy link
Contributor
@rpkamp rpkamp Jun 30, 2018

Choose a reason for hiding this comment

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

You can always cast the value from Cookie to a string and then use strict comparison. I think that would still be better than loose comparison.

$params['domain'] === (string) $cookie->getDomain()

Copy link
Member

Choose a reason for hiding this comment

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

both sides could need the cast.
but since this is tested, that's not really needed anyway.


$response = $this->filterResponse(new Request(), HttpKernelInterface::MASTER_REQUEST, $response);

$this->assertSame($expected, $response->headers->get('Set-Cookie', null, false));
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not really clear to me what this PR for. You state that it is to make it compatible with the CookieClearingLogoutHandler, but then I would expect a test that shows that no cookies are sent. However, you've added no tests that show this.

Furthermore, I doubt if this fix is the correct way to do it. It feels like it's battling symptoms instead of the root problem, but I can't quite lay my finger on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I still expect the original cookie to be sent (ie the one set by CookieClearingLogoutHandler).

Copy link
Contributor

Choose a reason for hiding this comment

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

But the CookieClearingLogoutHandler doesn't set cookies, it removes cookies. That's the whole point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To 'remove' a cookie you have to set a new expired one, hence:

public function clearCookie($name, $path = '/', $domain = null, $secure = false, $httpOnly = true)
{
$this->setCookie(new Cookie($name, null, 1, $path, $domain, $secure, $httpOnly));
}

Copy link
Contributor

Choose a reason for hiding this comment

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

aaah, check, I get it now.

In that case, LGTM

@thewilkybarkid
Copy link
Contributor Author

Should be back as 'Needs Review'.

Copy link
Member
@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

Thank you, LGTM, just one comment.

@@ -71,6 +71,13 @@ public function onKernelResponse(FilterResponseEvent $event)

if ($session instanceof Session ? !$session->isEmpty() || (null !== $this->sessionId && $session->getId() !== $this->sessionId) : $wasStarted) {
$params = session_get_cookie_params();

foreach ($event->getResponse()->headers->getCookies() as $cookie) {
if ($session->getName() === $cookie->getName() && $params['path'] == $cookie->getPath() && $params['domain'] == $cookie->getDomain()) {
Copy link
Member

Choose a reason for hiding this comment

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

can you add a test case where this would fail when the first == is turned into a === please?

@nicolas-grekas nicolas-grekas force-pushed the abstract-test-session-listener-cookie-clearing branch from 2725364 to f54d969 Compare July 1, 2018 06:51
@nicolas-grekas
Copy link
Member

Thank you @thewilkybarkid.

@nicolas-grekas nicolas-grekas merged commit f54d969 into symfony:3.4 Jul 1, 2018
nicolas-grekas added a commit that referenced this pull request Jul 1, 2018
…ith CookieClearingLogoutHandler (thewilkybarkid)

This PR was squashed before being merged into the 3.4 branch (closes #27659).

Discussion
----------

[HttpKernel] Make AbstractTestSessionListener compatible with CookieClearingLogoutHandler

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

#26157 started to send a new cookie in `AbstractTestSessionListener`, but is incompatible with `CookieClearingLogoutHandler` as it overrides its `Set-Cookie` by setting a new cookie (breaking my test that checked to see that the cookie was removed after a log out).

Commits
-------

f54d969 [HttpKernel] Make AbstractTestSessionListener compatible with CookieClearingLogoutHandler
@thewilkybarkid thewilkybarkid deleted the abstract-test-session-listener-cookie-clearing branch July 1, 2018 07:08
This was referenced Jul 23, 2018
6D40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0