Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[HttpFoundation] Allow reuse of Session between requests if ID did not change #28433

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
Sep 21, 2018

Conversation

tgalopin
Copy link
Contributor

@tgalopin tgalopin commented Sep 10, 2018

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

I stumbled upon the issue from #13450 in a more simple case than what was exposed in the issue. From my understanding, the problem arises when the session is used between an access to the session and a functional test request: because the session was accessed (usually using the container directly), the session has started and the following request fails.

This PR checks whether the ID was actually regenerated before throwing (if a setId is called with the same ID, it is the same request context, it shouldn't throw IMO).

Not sure I understood everything correctly though, feel free to fix it for me if needed.

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.

Would you mind adding a test case please?
Otherwise, lgtm thanks.

$this->storage->setId($id);
} catch (\Exception $e) {
$exception = $e;
}
Copy link
Member

Choose a reason for hiding this comment

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

$e = null;
try {
    $this->storage->setId($id);
} catch (\Exception $e) {
}
$this->assertNull($e);

same below

@@ -97,6 +97,30 @@ public function testGetId()
$this->assertNotEquals('', $this->storage->getId());
}

public function testSetId()
Copy link
Member

Choose a reason for hiding this comment

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

testSetIdAfterStart()?


$this->assertNull($exception);

$exception = null;
Copy link
Member

Choose a reason for hiding this comment

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

no need to reassign

@chalasr chalasr added this to the 2.8 milestone Sep 11, 2018
@nicolas-grekas nicolas-grekas changed the title Allow reuse of MockArraySessionStorage between requests [HttpFoundation] Allow reuse of MockArraySessionStorage between requests Sep 17, 2018
@tgalopin tgalopin changed the title [HttpFoundation] Allow reuse of MockArraySessionStorage between requests [HttpFoundation] Allow reuse of Session between requests if ID did not change Sep 20, 2018
@nicolas-grekas
Copy link
Member

Thank you @tgalopin.

@nicolas-grekas nicolas-grekas merged commit fd30f4a into symfony:2.8 Sep 21, 2018
nicolas-grekas added a commit that referenced this pull request Sep 21, 2018
…f ID did not change (tgalopin)

This PR was merged into the 2.8 branch.

Discussion
----------

[HttpFoundation] Allow reuse of Session between requests if ID did not change

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

I stumbled upon the issue from #13450 in a more simple case than what was exposed in the issue. From my understanding, the problem arises when the session is used between an access to the session and a functional test request: because the session was accessed (usually using the container directly), the session has started and the following request fails.

This PR checks whether the ID was actually regenerated before throwing (if a setId is called with the same ID, it is the same request context, it shouldn't throw IMO).

Not sure I understood everything correctly though, feel free to fix it for me if needed.

Commits
-------

fd30f4a Allow reuse of Session between requests
@tgalopin tgalopin deleted the patch-2 branch September 21, 2018 11:42
This was referenced Sep 30, 2018
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