From fdcc6b77289d6dd6f9040aac47411a8195208d4f Mon Sep 17 00:00:00 2001 From: upstream Date: Mon, 21 Sep 2026 16:30:28 +0200 Subject: [PATCH] Upstream spiral/testing state of the touched files before e812c3d094 --- src/Http/FakeHttp.php | 30 +--------- tests/src/Http/FakeHttpAuthTransportTest.php | 55 ------------------- .../Http/Stub/ActorReportingMiddleware.php | 26 --------- 3 files changed, 3 insertions(+), 108 deletions(-) delete mode 100644 tests/src/Http/FakeHttpAuthTransportTest.php delete mode 100644 tests/src/Http/Stub/ActorReportingMiddleware.php diff --git a/src/Http/FakeHttp.php b/src/Http/FakeHttp.php index d85ff49..2c20cd6 100644 --- a/src/Http/FakeHttp.php +++ b/src/Http/FakeHttp.php @@ -421,7 +421,9 @@ class FakeHttp $bindings[ActorProviderInterface::class] = new FakeActorProvider($this->actor); $bindings[TokenStorageInterface::class] = new FakeTokenStorage(); - $bindings[TransportRegistry::class] = $this->createFakeTransportRegistry(); + $transport = new TransportRegistry(); + $transport->setTransport('testing', new HeaderTransport(static::AUTH_TOKEN_HEADER_KEY)); + $bindings[TransportRegistry::class] = $transport; } if ($this->session) { @@ -459,30 +461,4 @@ class FakeHttp throw new \InvalidArgumentException('$data should be an array or an object.'); } } - - /** - * The fake token travels in the {@see self::AUTH_TOKEN_HEADER_KEY} header, so every transport the - * application has configured is replaced by one that reads it. The configured names are kept because - * {@see \Spiral\Auth\Middleware\AuthTransportMiddleware} resolves a transport by name. - */ - private function createFakeTransportRegistry(): TransportRegistry - { - $registry = new TransportRegistry(); - $transport = new HeaderTransport(static::AUTH_TOKEN_HEADER_KEY); - - try { - /** @var TransportRegistry $configured */ - $configured = $this->container->get(TransportRegistry::class); - foreach (\array_keys($configured->getTransports()) as $name) { - $registry->setTransport((string) $name, $transport); - } - } catch (\Throwable) { - // Nothing to copy the names from; the fake transport is all there is. - } - - $registry->setTransport('testing', $transport); - $registry->setDefaultTransport('testing'); - - return $registry; - } } diff --git a/tests/src/Http/FakeHttpAuthTransportTest.php b/tests/src/Http/FakeHttpAuthTransportTest.php deleted file mode 100644 index 3c34f1b..0000000 --- a/tests/src/Http/FakeHttpAuthTransportTest.php +++ /dev/null @@ -1,55 +0,0 @@ -fakeHttp() - ->withActor($actor) - ->withMiddleware(ActorReportingMiddleware::class, HeaderAuthMiddleware::class) - ->get('/get/query-params'); - - $response->assertOk(); - $response->assertBodySame($actor::class); - } - - public function testActorIsAuthenticatedThroughEveryTransport(): void - { - $actor = new \stdClass(); - - $response = $this->fakeHttp() - ->withActor($actor) - ->withMiddleware(ActorReportingMiddleware::class, AuthMiddleware::class) - ->get('/get/query-params'); - - $response->assertOk(); - $response->assertBodySame($actor::class); - } - - public function testRequestWithoutActorStaysUnauthenticated(): void - { - $response = $this->fakeHttp() - ->withMiddleware(ActorReportingMiddleware::class, HeaderAuthMiddleware::class) - ->get('/get/query-params'); - - $response->assertOk(); - $response->assertBodySame(ActorReportingMiddleware::NO_ACTOR); - } -} diff --git a/tests/src/Http/Stub/ActorReportingMiddleware.php b/tests/src/Http/Stub/ActorReportingMiddleware.php deleted file mode 100644 index 9066187..0000000 --- a/tests/src/Http/Stub/ActorReportingMiddleware.php +++ /dev/null @@ -1,26 +0,0 @@ -getAttribute(AuthMiddleware::ATTRIBUTE); - $actor = $context instanceof AuthContextInterface ? $context->getActor() : null; - - return new Response(200, body: $actor === null ? self::NO_ACTOR : $actor::class); - } -}