Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Allow deactivation of PSR-15 middlewares
Similar to other places that use dependency configurations via arrays, the middleware stack configuration now allows disabling single middlewares by setting disabled=true. Change-Id: I42c741062b5f6952577e164939593f0553b1ad31 Resolves: #83907 Related: #83906 Related: #83725 Releases: master Reviewed-on: https://review.typo3.org/55725 Reviewed-by: Mathias Schreiber <mathias.schreiber@typo3.com> Tested-by: Mathias Schreiber <mathias.schreiber@typo3.com> Tested-by: TYPO3com <no-reply@typo3.com> Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de> Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de> Reviewed-by: Benjamin Franzke <bfr@qbus.de> Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
- Loading branch information
Showing
7 changed files
with
151 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
typo3/sysext/core/Tests/Unit/Http/Fixtures/Package1/Configuration/RequestMiddlewares.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
return [ | ||
'testStack' => [ | ||
'firstMiddleware' => [ | ||
'target' => 'aClassName', | ||
], | ||
] | ||
]; |
8 changes: 8 additions & 0 deletions
8
typo3/sysext/core/Tests/Unit/Http/Fixtures/Package2/Configuration/RequestMiddlewares.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
return [ | ||
'testStack' => [ | ||
'secondMiddleware' => [ | ||
'target' => 'anotherClassName', | ||
], | ||
] | ||
]; |
11 changes: 11 additions & 0 deletions
11
...sext/core/Tests/Unit/Http/Fixtures/Package2Disables1/Configuration/RequestMiddlewares.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
return [ | ||
'testStack' => [ | ||
'firstMiddleware' => [ | ||
'disabled' => true, | ||
], | ||
'secondMiddleware' => [ | ||
'target' => 'anotherClassName', | ||
], | ||
] | ||
]; |
88 changes: 88 additions & 0 deletions
88
typo3/sysext/core/Tests/Unit/Http/MiddlewareStackResolverTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
namespace TYPO3\CMS\Core\Tests\Unit\Http; | ||
|
||
/* | ||
* This file is part of the TYPO3 CMS project. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
* | ||
* The TYPO3 project - inspiring people to share! | ||
*/ | ||
|
||
use Prophecy\Argument; | ||
use TYPO3\CMS\Core\Cache\Frontend\PhpFrontend; | ||
use TYPO3\CMS\Core\Http\MiddlewareStackResolver; | ||
use TYPO3\CMS\Core\Package\Package; | ||
use TYPO3\CMS\Core\Package\PackageManager; | ||
use TYPO3\CMS\Core\Service\DependencyOrderingService; | ||
use TYPO3\TestingFramework\Core\Unit\UnitTestCase; | ||
|
||
/** | ||
* Test case | ||
*/ | ||
class MiddlewareStackResolverTest extends UnitTestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function resolveReturnsMiddlewareStack() | ||
{ | ||
$package1 = $this->prophesize(Package::class); | ||
$package1->getPackagePath()->willReturn(__DIR__ . '/' . 'Fixtures/Package1/'); | ||
$package2 = $this->prophesize(Package::class); | ||
$package2->getPackagePath()->willReturn(__DIR__ . '/' . 'Fixtures/Package2/'); | ||
$packageManagerProphecy = $this->prophesize(PackageManager::class); | ||
$packageManagerProphecy->getActivePackages()->willReturn([$package1->reveal(), $package2->reveal()]); | ||
$dependencyOrderingServiceProphecy = $this->prophesize(DependencyOrderingService::class); | ||
$dependencyOrderingServiceProphecy->orderByDependencies(Argument::cetera())->willReturnArgument(0); | ||
$phpFrontendCacheProphecy = $this->prophesize(PhpFrontend::class); | ||
$phpFrontendCacheProphecy->has(Argument::cetera())->willReturn(false); | ||
$phpFrontendCacheProphecy->set(Argument::cetera())->willReturn(false); | ||
|
||
$subject = new MiddlewareStackResolver( | ||
$packageManagerProphecy->reveal(), | ||
$dependencyOrderingServiceProphecy->reveal(), | ||
$phpFrontendCacheProphecy->reveal() | ||
); | ||
$expected = [ | ||
'secondMiddleware' => 'anotherClassName', | ||
'firstMiddleware' => 'aClassName', | ||
]; | ||
$this->assertEquals($expected, $subject->resolve('testStack')); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function resolveAllowsDisablingAMiddleware() | ||
{ | ||
$package1 = $this->prophesize(Package::class); | ||
$package1->getPackagePath()->willReturn(__DIR__ . '/' . 'Fixtures/Package1/'); | ||
$package2 = $this->prophesize(Package::class); | ||
$package2->getPackagePath()->willReturn(__DIR__ . '/' . 'Fixtures/Package2Disables1/'); | ||
$packageManagerProphecy = $this->prophesize(PackageManager::class); | ||
$packageManagerProphecy->getActivePackages()->willReturn([$package1->reveal(), $package2->reveal()]); | ||
$dependencyOrderingServiceProphecy = $this->prophesize(DependencyOrderingService::class); | ||
$dependencyOrderingServiceProphecy->orderByDependencies(Argument::cetera())->willReturnArgument(0); | ||
$phpFrontendCacheProphecy = $this->prophesize(PhpFrontend::class); | ||
$phpFrontendCacheProphecy->has(Argument::cetera())->willReturn(false); | ||
$phpFrontendCacheProphecy->set(Argument::cetera())->willReturn(false); | ||
|
||
$subject = new MiddlewareStackResolver( | ||
$packageManagerProphecy->reveal(), | ||
$dependencyOrderingServiceProphecy->reveal(), | ||
$phpFrontendCacheProphecy->reveal() | ||
); | ||
$expected = [ | ||
// firstMiddleware is missing, RequestMiddlewares.php of Package2 sets disables=true on firstMiddleware | ||
'secondMiddleware' => 'anotherClassName', | ||
]; | ||
$this->assertEquals($expected, $subject->resolve('testStack')); | ||
} | ||
} |