‪TYPO3CMS  10.4
SlugSiteWithoutRequiredCHashRequestTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
22 use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\Scenario\DataHandlerFactory;
23 use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\Scenario\DataHandlerWriter;
24 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
25 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\ResponseContent;
26 
28 {
32  protected $configurationToUseInTestInstance = [
33  'SYS' => [
34  'devIPmask' => '123.123.123.123',
35  'encryptionKey' => '4408d27a916d51e624b69af3554f516dbab61037a9f7b9fd6f81b4d3bedeccb6',
36  ],
37  'FE' => [
38  'cacheHash' => [
39  'enforceValidation' => false,
40  ],
41  'debug' => false,
42  ],
43  ];
44 
45  protected function setUp(): void
46  {
47  parent::setUp();
48  $this->‪withDatabaseSnapshot(function () {
49  $this->importCSVDataSet(__DIR__ . '/../Fixtures/be_users.csv');
50  $backendUser = $this->setUpBackendUser(1);
52  $scenarioFile = __DIR__ . '/Fixtures/SlugScenario.yaml';
53  $factory = DataHandlerFactory::fromYamlFile($scenarioFile);
54  $writer = DataHandlerWriter::withBackendUser($backendUser);
55  $writer->invokeFactory($factory);
56  static::failIfArrayIsNotEmpty($writer->getErrors());
57  $this->setUpFrontendRootPage(
58  1000,
59  [
60  'typo3/sysext/core/Tests/Functional/Fixtures/Frontend/JsonRenderer.typoscript',
61  'typo3/sysext/frontend/Tests/Functional/SiteHandling/Fixtures/JsonRenderer.typoscript',
62  ],
63  [
64  'title' => 'ACME Root',
65  ]
66  );
67  });
68  }
69 
71  {
72  $domainPaths = [
73  'https://website.local/',
74  ];
75 
76  $queries = [
77  '',
78  'welcome',
79  ];
80 
81  $customQueries = [
82  '?testing[value]=1',
83  '?testing[value]=1&cHash=',
84  '?testing[value]=1&cHash=WRONG',
85  ];
86 
87  return $this->wrapInArray(
88  $this->keysFromValues(
89  ‪PermutationUtility::meltStringItems([$domainPaths, $queries, $customQueries])
90  )
91  );
92  }
93 
98  public function ‪pageRequestSendsNotFoundResponseWithInvalidCacheHash(string $uri): void
99  {
101  'website-local',
102  $this->‪buildSiteConfiguration(1000, 'https://website.local/'),
103  [],
104  $this->‪buildErrorHandlingConfiguration('PHP', [404])
105  );
106 
107  $response = $this->executeFrontendRequest(new InternalRequest($uri));
108  $json = json_decode((string)$response->getBody(), true);
109 
110  self::assertThat(
111  $json['message'] ?? null,
112  self::logicalOr(
113  self::identicalTo(null),
114  self::identicalTo('Request parameters could not be validated (&cHash comparison failed)')
115  )
116  );
117  }
118 
119  public function ‪pageIsRenderedWithValidCacheHashDataProvider(): array
120  {
121  $domainPaths = [
122  'https://website.local/',
123  ];
124 
125  // cHash has been calculated with encryption key set to
126  // '4408d27a916d51e624b69af3554f516dbab61037a9f7b9fd6f81b4d3bedeccb6'
127  $queries = [
128  // @todo Currently fails since cHash is verified after(!) redirect to page 1100
129  // '?cHash=7d1f13fa91159dac7feb3c824936b39d',
130  // '?cHash=7d1f13fa91159dac7feb3c824936b39d',
131  'welcome?cHash=f42b850e435f0cedd366f5db749fc1af',
132  ];
133 
134  $customQueries = [
135  '&testing[value]=1',
136  ];
137 
138  $dataSet = $this->wrapInArray(
139  $this->keysFromValues(
140  ‪PermutationUtility::meltStringItems([$domainPaths, $queries, $customQueries])
141  )
142  );
143 
144  return $dataSet;
145  }
146 
151  public function ‪pageIsRenderedWithValidCacheHash($uri): void
152  {
154  'website-local',
155  $this->‪buildSiteConfiguration(1000, 'https://website.local/')
156  );
157 
158  $response = $this->executeFrontendRequest(new InternalRequest($uri));
159  $responseStructure = ResponseContent::fromString(
160  (string)$response->getBody()
161  );
162  self::assertSame(
163  '1',
164  $responseStructure->getScopePath('getpost/testing.value')
165  );
166  }
167 }
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildErrorHandlingConfiguration
‪array buildErrorHandlingConfiguration(string $handler, array $codes)
Definition: SiteBasedTestTrait.php:184
‪TYPO3\CMS\Core\Utility\PermutationUtility\meltStringItems
‪static array meltStringItems(array $payload, string $previousResult='')
Definition: PermutationUtility.php:36
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\SlugSiteWithoutRequiredCHashRequestTest\pageIsRenderedWithValidCacheHashDataProvider
‪pageIsRenderedWithValidCacheHashDataProvider()
Definition: SlugSiteWithoutRequiredCHashRequestTest.php:118
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\SlugSiteWithoutRequiredCHashRequestTest\pageRenderingStopsWithInvalidCacheHashDataProvider
‪pageRenderingStopsWithInvalidCacheHashDataProvider()
Definition: SlugSiteWithoutRequiredCHashRequestTest.php:69
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\writeSiteConfiguration
‪writeSiteConfiguration(string $identifier, array $site=[], array $languages=[], array $errorHandling=[])
Definition: SiteBasedTestTrait.php:58
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\AbstractTestCase
Definition: AbstractTestCase.php:29
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\SlugSiteWithoutRequiredCHashRequestTest\pageRequestSendsNotFoundResponseWithInvalidCacheHash
‪pageRequestSendsNotFoundResponseWithInvalidCacheHash(string $uri)
Definition: SlugSiteWithoutRequiredCHashRequestTest.php:97
‪TYPO3\CMS\Core\Core\Bootstrap\initializeLanguageObject
‪static initializeLanguageObject()
Definition: Bootstrap.php:617
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\SlugSiteWithoutRequiredCHashRequestTest
Definition: SlugSiteWithoutRequiredCHashRequestTest.php:28
‪TYPO3\CMS\Core\Utility\PermutationUtility
Definition: PermutationUtility.php:24
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\SlugSiteWithoutRequiredCHashRequestTest\pageIsRenderedWithValidCacheHash
‪pageIsRenderedWithValidCacheHash($uri)
Definition: SlugSiteWithoutRequiredCHashRequestTest.php:150
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling
Definition: AbstractTestCase.php:18
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\SlugSiteWithoutRequiredCHashRequestTest\withDatabaseSnapshot
‪array< string, $configurationToUseInTestInstance=array('SYS'=>['devIPmask'=> '123.123.123.123', 'encryptionKey'=> '4408d27a916d51e624b69af3554f516dbab61037a9f7b9fd6f81b4d3bedeccb6',], 'FE'=>['cacheHash'=>['enforceValidation'=> false,], 'debug'=> false,],);protected setUp():void { parent::setUp();$this-> withDatabaseSnapshot(function() { $this->importCSVDataSet(__DIR__ . '/../Fixtures/be_users.csv'); $backendUser=$this->setUpBackendUser(1);Bootstrap::initializeLanguageObject(); $scenarioFile=__DIR__ . '/Fixtures/SlugScenario.yaml'; $factory=DataHandlerFactory::fromYamlFile($scenarioFile); $writer=DataHandlerWriter::withBackendUser($backendUser); $writer->invokeFactory($factory);static::failIfArrayIsNotEmpty($writer->getErrors()); $this->setUpFrontendRootPage(1000, ['typo3/sysext/core/Tests/Functional/Fixtures/Frontend/JsonRenderer.typoscript', 'typo3/sysext/frontend/Tests/Functional/SiteHandling/Fixtures/JsonRenderer.typoscript',], ['title'=> 'ACME Root',]);})
‪TYPO3\CMS\Core\Core\Bootstrap
Definition: Bootstrap.php:66
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildSiteConfiguration
‪array buildSiteConfiguration(int $rootPageId, string $base='')
Definition: SiteBasedTestTrait.php:109