diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2023-01-23 17:11:39 +0100 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2023-01-26 11:54:28 +0100 |
commit | 8d9af3e26214f07e833a6b8d8b60329fc71916a7 (patch) | |
tree | c41dc1835261e45f9f5751b0d07d1f45d8f4d7ba /tests | |
parent | 3eb73d0a3d081194e676b7e7ba220a118e01e18d (diff) | |
download | nextcloud-server-8d9af3e26214f07e833a6b8d8b60329fc71916a7.tar.gz nextcloud-server-8d9af3e26214f07e833a6b8d8b60329fc71916a7.zip |
feat(app-framework): Add support for global middlewares
This allows apps to register middlewares that always register, not just
for the app's own requests
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/AppFramework/Bootstrap/RegistrationContextTest.php | 2 | ||||
-rw-r--r-- | tests/lib/AppFramework/DependencyInjection/DIContainerTest.php | 38 |
2 files changed, 36 insertions, 4 deletions
diff --git a/tests/lib/AppFramework/Bootstrap/RegistrationContextTest.php b/tests/lib/AppFramework/Bootstrap/RegistrationContextTest.php index cee30b665fb..55f30a895f5 100644 --- a/tests/lib/AppFramework/Bootstrap/RegistrationContextTest.php +++ b/tests/lib/AppFramework/Bootstrap/RegistrationContextTest.php @@ -180,7 +180,7 @@ class RegistrationContextTest extends TestCase { } public function testGetMiddlewareRegistrations(): void { - $this->context->registerMiddleware('core', TwoFactorMiddleware::class); + $this->context->registerMiddleware('core', TwoFactorMiddleware::class, false); $registrations = $this->context->getMiddlewareRegistrations(); diff --git a/tests/lib/AppFramework/DependencyInjection/DIContainerTest.php b/tests/lib/AppFramework/DependencyInjection/DIContainerTest.php index bcf4e0a2771..04422643121 100644 --- a/tests/lib/AppFramework/DependencyInjection/DIContainerTest.php +++ b/tests/lib/AppFramework/DependencyInjection/DIContainerTest.php @@ -26,8 +26,8 @@ namespace Test\AppFramework\DependencyInjection; use OC\AppFramework\Bootstrap\Coordinator; +use OC\AppFramework\Bootstrap\MiddlewareRegistration; use OC\AppFramework\Bootstrap\RegistrationContext; -use OC\AppFramework\Bootstrap\ServiceRegistration; use OC\AppFramework\DependencyInjection\DIContainer; use OC\AppFramework\Http\Request; use OC\AppFramework\Middleware\Security\SecurityMiddleware; @@ -95,8 +95,40 @@ class DIContainerTest extends \Test\TestCase { $registrationContext = $this->createMock(RegistrationContext::class); $registrationContext->method('getMiddlewareRegistrations') ->willReturn([ - new ServiceRegistration($this->container['appName'], 'foo'), - new ServiceRegistration('otherapp', 'bar'), + new MiddlewareRegistration($this->container['appName'], 'foo', false), + new MiddlewareRegistration('otherapp', 'bar', false), + ]); + $this->container['foo'] = new class extends Middleware { + }; + $this->container['bar'] = new class extends Middleware { + }; + $coordinator->method('getRegistrationContext')->willReturn($registrationContext); + + $dispatcher = $this->container['MiddlewareDispatcher']; + + $middlewares = $dispatcher->getMiddlewares(); + self::assertNotEmpty($middlewares); + foreach ($middlewares as $middleware) { + if ($middleware === $this->container['bar']) { + $this->fail('Container must not register this middleware'); + } + if ($middleware === $this->container['foo']) { + // It is done + return; + } + } + $this->fail('Bootstrap registered middleware not found'); + } + + public function testMiddlewareDispatcherIncludesGlobalBootstrapMiddlewares(): void { + $coordinator = $this->createMock(Coordinator::class); + $this->container[Coordinator::class] = $coordinator; + $this->container['Request'] = $this->createMock(Request::class); + $registrationContext = $this->createMock(RegistrationContext::class); + $registrationContext->method('getMiddlewareRegistrations') + ->willReturn([ + new MiddlewareRegistration('otherapp', 'foo', true), + new MiddlewareRegistration('otherapp', 'bar', false), ]); $this->container['foo'] = new class extends Middleware { }; |