Skip to content

[HttpFoundation] Add Session::isEmpty(), fix MockFileSessionStorage to behave like the native one #25220

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 30, 2017

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Nov 30, 2017

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 -

MockFileSessionStorage should not create any file when the session is empty. Like the native session storage, it should ignore the metadataBag to decide if the session is empty.

And to prevent AbstractTestSessionListener from registering a wrong cookie, it must have access to this empty state, which is now possible thanks to a new Session::isEmpty() method. Implementing it requires access to the internal storage of bags, which is possible via an internal proxy.

@@ -29,7 +29,7 @@
protected $options = array(
'check_path' => '/login_check',
'use_forward' => false,
'require_previous_session' => true,
'require_previous_session' => false,
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 Request::hasPreviousSession() check that this triggers is a micro-optimization that doesn't make sense, and in fact doesn't work anymore now that we destroy any empty session.
The only case were it can make sense is for remember-me strategy, and this is still enabled there as RememberMeFactory replaces this $options array, and the default is true.

Copy link
Member

@stof stof left a comment

Choose a reason for hiding this comment

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

Looks good to me.

Too bad that this requires a new public method in Session just for the test layer though.

@nicolas-grekas
Copy link
Member Author

Too bad that this requires a new public method in Session just for the test layer though.

the method is now @internal

@nicolas-grekas nicolas-grekas merged commit 56846ac into symfony:3.4 Nov 30, 2017
nicolas-grekas added a commit that referenced this pull request Nov 30, 2017
…onStorage to behave like the native one (nicolas-grekas)

This PR was merged into the 3.4 branch.

Discussion
----------

[HttpFoundation] Add Session::isEmpty(), fix MockFileSessionStorage to behave like the native one

| 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        | -

MockFileSessionStorage should not create any file when the session is empty. Like the native session storage, it should ignore the metadataBag to decide if the session is empty.

And to prevent AbstractTestSessionListener from registered a wrong cookie, it must have access to this empty state, which is now possible thanks to a new `Session::isEmpty()` method. Implementing is requires access to the internal storage of bags, which is possible via an internal proxy.

Commits
-------

56846ac [HttpFoundation] Add Session::isEmpty(), fix MockFileSessionStorage to behave like the native one
@nicolas-grekas nicolas-grekas deleted the test-session branch November 30, 2017 15:29
This was referenced Nov 30, 2017
jpuck added a commit to razorbacks/laravel-shibboleth that referenced this pull request Nov 30, 2017
jpuck added a commit to razorbacks/laravel-shibboleth that referenced this pull request Nov 30, 2017
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