Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
bug #25731 [HttpFoundation] Always call proxied handler::destroy() in…
… StrictSessionHandler (nicolas-grekas)

This PR was merged into the 3.4 branch.

Discussion
----------

[HttpFoundation] Always call proxied handler::destroy() in StrictSessionHandler

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

Noticed by @jpauli: the native file session handler needs a call to `destroy()` to remove session files, even for new empty sessions.

Commits
-------

e5e2d5d [HttpFoundation] Always call proxied handler::destroy() in StrictSessionHandler
  • Loading branch information
fabpot committed Jan 10, 2018
2 parents eac7e19 + e5e2d5d commit 93755ab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Expand Up @@ -19,6 +19,7 @@
class StrictSessionHandler extends AbstractSessionHandler
{
private $handler;
private $doDestroy;

public function __construct(\SessionHandlerInterface $handler)
{
Expand Down Expand Up @@ -63,11 +64,24 @@ protected function doWrite($sessionId, $data)
return $this->handler->write($sessionId, $data);
}

/**
* {@inheritdoc}
*/
public function destroy($sessionId)
{
$this->doDestroy = true;
$destroyed = parent::destroy($sessionId);

return $this->doDestroy ? $this->doDestroy($sessionId) : $destroyed;
}

/**
* {@inheritdoc}
*/
protected function doDestroy($sessionId)
{
$this->doDestroy = false;

return $this->handler->destroy($sessionId);
}

Expand Down
Expand Up @@ -118,7 +118,7 @@ public function testWriteEmptyNewSession()
$handler->expects($this->once())->method('read')
->with('id')->willReturn('');
$handler->expects($this->never())->method('write');
$handler->expects($this->never())->method('destroy');
$handler->expects($this->once())->method('destroy')->willReturn(true);
$proxy = new StrictSessionHandler($handler);

$this->assertFalse($proxy->validateId('id'));
Expand Down Expand Up @@ -154,7 +154,7 @@ public function testDestroyNewSession()
$handler = $this->getMockBuilder('SessionHandlerInterface')->getMock();
$handler->expects($this->once())->method('read')
->with('id')->willReturn('');
$handler->expects($this->never())->method('destroy');
$handler->expects($this->once())->method('destroy')->willReturn(true);
$proxy = new StrictSessionHandler($handler);

$this->assertSame('', $proxy->read('id'));
Expand Down

0 comments on commit 93755ab

Please sign in to comment.