8000 [FrameworkBundle][HttpKernel] Added `session.strict_statless` configu… · symfony/symfony@2d20edb · GitHub
[go: up one dir, main page]

Skip to content

Commit 2d20edb

Browse files
committed
[FrameworkBundle][HttpKernel] Added session.strict_statless configuration option
1 parent 0bec08f commit 2d20edb

File tree

13 files changed

+22
-13
lines changed

13 files changed

+22
-13
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ CHANGELOG
1818
* Made `BrowserKitAssertionsTrait` report the original error message in case of a failure
1919
* Added ability for `config:dump-reference` and `debug:config` to dump and debug kernel container extension configuration.
2020
* Deprecated `session.attribute_bag` service and `session.flash_bag` service.
21+
* Added `session.strict_statless` option to configure the strictness of stateless reporting
2122

2223
5.0.0
2324
-----

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ private function addSessionSection(ArrayNodeDefinition $rootNode)
540540
->min(4)
541541
->max(6)
542542
->end()
543+
->booleanNode('strict_stateless')->defaultValue('%kernel.debug%')->end()
543544
->end()
544545
->end()
545546
->end()

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,8 @@ private function registerSessionConfiguration(array $config, ContainerBuilder $c
972972
$container->setParameter('session.save_path', $config['save_path']);
973973

974974
$container->setParameter('session.metadata.update_threshold', $config['metadata_update_threshold']);
975+
976+
$container->setParameter('session.strict_stateless', $config['strict_stateless']);
975977
}
976978

977979
private function registerRequestConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)

src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
<xsd:attribute name="metadata-update-threshold" type="xsd:nonNegativeInteger" />
118118
<xsd:attribute name="sid-length" type="sid_length" />
119119
<xsd:attribute name="sid-bits-per-character" type="sid_bits_per_character" />
120+
<xsd:attribute name="strict-stateless" type="xsd:boolean" />
120121
</xsd:complexType>
121122

122123
<xsd:complexType name="request">

src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
<argument key="initialized_session" type="service" id="session" on-invalid="ignore_uninitialized" />
7979
<argument key="logger" type="service" id="logger" on-invalid="ignore" />
8080
</argument>
81-
<argument>%kernel.debug%</argument>
81+
<argument>%session.strict_stateless%</argument> <!-- strictStatelessReport -->
8282
</service>
8383

8484
<!-- for BC -->

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ protected static function getBundleDefaultConfig()
429429
'gc_probability' => 1,
430430
'save_path' => '%kernel.cache_dir%/sessions',
431431
'metadata_update_threshold' => 0,
432+
'strict_stateless' => '%kernel.debug%',
432433
],
433434
'request' => [
434435
'enabled' => false,

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
'sid_length' => 22,
4242
'sid_bits_per_character' => 4,
4343
'save_path' => '/path/to/sessions',
44+
'strict_stateless' => true,
4445
],
4546
'assets' => [
4647
'version' => 'v1',

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<framework:ssi enabled="true" />
1616
<framework:profiler only-exceptions="true" enabled="false" />
1717
<framework:router resource="%kernel.project_dir%/config/routing.xml" type="xml" utf8="true" />
18-
<framework:session gc-maxlifetime="90000" gc-probability="1" gc-divisor="108" storage-id="session.storage.native" handler-id="session.handler.native_file" name="_SYMFONY" cookie-lifetime="86400" cookie-path="/" cookie-domain="example.com" cookie-secure="true" cookie-httponly="false" use-cookies="true" save-path="/path/to/sessions" sid-length="22" sid-bits-per-character="4" />
18+
<framework:session gc-maxlifetime="90000" gc-probability="1" gc-divisor="108" storage-id="session.storage.native" handler-id="session.handler.native_file" name="_SYMFONY" cookie-lifetime="86400" cookie-path="/" cookie-domain="example.com" cookie-secure="true" cookie-httponly="false" use-cookies="true" save-path="/path/to/sessions" sid-length="22" sid-bits-per-character="4" strict-stateless="true" />
1919
<framework:request>
2020
<framework:format name="csv">
2121
<framework:mime-type>text/csv</framework:mime-type>

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ framework:
3333
sid_length: 22
3434
sid_bits_per_character: 4
3535
save_path: /path/to/sessions
36+
strict_stateless: true
3637
assets:
3738
version: v1
3839
translator:

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ public function testSession()
478478
$this->assertEquals('fr', $container->getParameter('kernel.default_locale'));
479479
$this->assertEquals('session.storage.native', (string) $container->getAlias('session.storage'));
480480
$this->assertEquals('session.handler.native_file', (string) $container->getAlias('session.handler'));
481+
$this->assertTrue($container->getParameter('session.strict_stateless'));
481482

482483
$options = $container->getParameter('session.storage.options');
483484
$this->assertEquals('_SYMFONY', $options['name']);

src/Symfony/Component/HttpKernel/EventListener/AbstractSessionListener.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ abstract class AbstractSessionListener implements EventSubscriberInterface
4242

4343
protected $container;
4444
private $sessionUsageStack = [];
45-
private $debug;
45+
private $strictStatelessReport;
4646

47-
public function __construct(ContainerInterface $container = null, bool $debug = false)
47+
public function __construct(ContainerInterface $container = null, bool $strictStatelessReport = false)
4848
{
4949
$this->container = $container;
50-
$this->debug = $debug;
50+
$this->strictStatelessReport = $strictStatelessReport;
5151
}
5252

5353
public function onKernelRequest(RequestEvent $event)
@@ -130,7 +130,7 @@ public function onKernelResponse(ResponseEvent $event)
130130
return;
131131
}
132132

133-
if ($this->debug) {
133+
if ($this->strictStatelessReport) {
134134
throw new UnexpectedSessionUsageException('Session was used while the request was declared stateless.');
135135
}
136136

@@ -148,7 +148,7 @@ public function onFinishRequest(FinishRequestEvent $event)
148148

149149
public function onSessionUsage(): void
150150
{
151-
if (!$this->debug) {
151+
if (!$this->strictStatelessReport) {
152152
return;
153153
}
154154

src/Symfony/Component/HttpKernel/EventListener/SessionListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
*/
2929
class SessionListener extends AbstractSessionListener
3030
{
31-
public function __construct(ContainerInterface $container, bool $debug = false)
31+
public function __construct(ContainerInterface $container, bool $strictStatelessReport = false)
3232
{
33-
parent::__construct($container, $debug);
33+
parent::__construct($container, $strictStatelessReport);
3434
}
3535

3636
protected function getSession(): ?SessionInterface

src/Symfony/Component/HttpKernel/Tests/EventListener/SessionListenerTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public function testSurrogateMasterRequestIsPublic()
181181
$this->assertLessThanOrEqual((new \DateTime('now', new \DateTimeZone('UTC'))), (new \DateTime($response->headers->get('Expires'))));
182182
}
183183

184-
public function testSessionUsageExceptionIfStatelessAndSessionUsed()
184+
public function testSessionUsageExceptionWhenStrictStatelessAndSessionUsed()
185185
{
186186
$session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock();
187187
$session->expects($this->exactly(2))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1));
@@ -200,7 +200,7 @@ public function testSessionUsageExceptionIfStatelessAndSessionUsed()
200200
$listener->onKernelResponse(new ResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, new Response()));
201201
}
202202

203-
public function testSessionUsageLogIfStatelessAndSessionUsed()
203+
public function testSessionUsageLogWhenNotStrictStatelessAndSessionUsed()
204204
{
205205
$session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock();
206206
$session->expects($this->exactly(2))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1));
@@ -245,7 +245,7 @@ public function testSessionIsSavedWhenUnexpectedSessionExceptionThrown()
245245
$listener->onKernelResponse(new ResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response));
246246
}
247247

248-
public function testSessionUsageCallbackWhenDebugAndStateless()
248+
public function testSessionUsageCallbackWhenStrictAndStateless()
249249
{
250250
$session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock();
251251
$session->method('isStarted')->willReturn(true);
@@ -268,7 +268,7 @@ public function testSessionUsageCallbackWhenDebugAndStateless()
268268
(new SessionListener($container, true))->onSessionUsage();
269269
}
270270

271-
public function testSessionUsageCallbackWhenNoDebug()
271+
public function testSessionUsageCallbackWhenNotStrict()
272272
{
273273
$session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock();
274274
$session->method('isStarted')->willReturn(true);

0 commit comments

Comments
 (0)
0