Skip to content
Snippets Groups Projects
Commit 7b3d41fd authored by Nikita Hovratov's avatar Nikita Hovratov Committed by Stefan Bürk
Browse files

[TASK] Replace prophecy in EXT:core VerifyHostHeaderTest

Resolves: #98769
Releases: main
Change-Id: I260228d27ee9176be215910a0016faa4531d722f
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/76801


Tested-by: default avatarOliver Klee <typo3-coding@oliverklee.de>
Tested-by: default avatarcore-ci <typo3@b13.com>
Tested-by: default avatarStefan Bürk <stefan@buerk.tech>
Reviewed-by: default avatarOliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: default avatarStefan Bürk <stefan@buerk.tech>
parent 76cae730
Branches
Tags
No related merge requests found
......@@ -17,17 +17,14 @@ declare(strict_types=1);
namespace TYPO3\CMS\Core\Tests\Unit\Middleware;
use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use TYPO3\CMS\Core\Http\Response;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Core\Middleware\VerifyHostHeader;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
class VerifyHostHeaderTest extends UnitTestCase
{
use ProphecyTrait;
/**
* @test
*/
......@@ -214,49 +211,37 @@ class VerifyHostHeaderTest extends UnitTestCase
}
/**
* @param string $httpHost HTTP_HOST string
* @param string $hostNamePattern trusted hosts pattern
* @test
* @dataProvider hostnamesNotMatchingTrustedHostsConfigurationDataProvider
*/
public function processThrowsExceptionForNotAllowedHostnameValues(string $httpHost, string $hostNamePattern): void
{
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionCode(1396795884);
$serverParams = $_SERVER;
$serverParams['HTTP_HOST'] = $httpHost;
$subject = new VerifyHostHeader($hostNamePattern);
$request = new ServerRequest(serverParams: $serverParams);
$requestHandlerMock = $this->createMock(RequestHandlerInterface::class);
$requestProphecy = $this->prophesize(ServerRequestInterface::class);
$requestProphecy->getServerParams()->willReturn($serverParams);
$requestHandlerProphecy = $this->prophesize(RequestHandlerInterface::class);
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionCode(1396795884);
$subject->process($requestProphecy->reveal(), $requestHandlerProphecy->reveal());
$subject->process($request, $requestHandlerMock);
}
/**
* @param string $httpHost HTTP_HOST string
* @param string $hostNamePattern trusted hosts pattern (not used in this test currently)
* @test
* @dataProvider hostnamesNotMatchingTrustedHostsConfigurationDataProvider
*/
public function processAllowsAllHostnameValuesIfHostPatternIsSetToAllowAll(string $httpHost, string $hostNamePattern): void
public function processAllowsAllHostnameValuesIfHostPatternIsSetToAllowAll(string $httpHost): void
{
$serverParams = $_SERVER;
$serverParams['HTTP_HOST'] = $httpHost;
$subject = new VerifyHostHeader(VerifyHostHeader::ENV_TRUSTED_HOSTS_PATTERN_ALLOW_ALL);
$requestProphecy = $this->prophesize(ServerRequestInterface::class);
$requestProphecy->getServerParams()->willReturn($serverParams);
$responseProphecy = $this->prophesize(ResponseInterface::class);
$request = new ServerRequest(serverParams: $serverParams);
$requestHandlerMock = $this->createMock(RequestHandlerInterface::class);
$requestHandlerProphecy = $this->prophesize(RequestHandlerInterface::class);
$requestHandlerProphecy->handle($requestProphecy)->willReturn($responseProphecy->reveal())->shouldBeCalled();
$requestHandlerMock->expects(self::atLeastOnce())->method('handle')->with($request)->willReturn(new Response());
$subject->process($requestProphecy->reveal(), $requestHandlerProphecy->reveal());
$subject->process($request, $requestHandlerMock);
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment