‪TYPO3CMS  ‪main
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 
20 use PHPUnit\Framework\Attributes\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
24 use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\Scenario\DataHandlerFactory;
25 use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\Scenario\DataHandlerWriter;
26 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
27 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\ResponseContent;
28 
30 {
32  'SYS' => [
33  'devIPmask' => '123.123.123.123',
34  'encryptionKey' => '4408d27a916d51e624b69af3554f516dbab61037a9f7b9fd6f81b4d3bedeccb6',
35  ],
36  'FE' => [
37  'cacheHash' => [
38  'enforceValidation' => false,
39  ],
40  'debug' => false,
41  ],
42  ];
43 
44  protected function ‪setUp(): void
45  {
46  parent::setUp();
47  $this->withDatabaseSnapshot(function () {
48  $this->importCSVDataSet(__DIR__ . '/../Fixtures/be_users.csv');
49  $backendUser = $this->setUpBackendUser(1);
50  ‪$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->createFromUserPreferences($backendUser);
51  $scenarioFile = __DIR__ . '/Fixtures/SlugScenario.yaml';
52  $factory = DataHandlerFactory::fromYamlFile($scenarioFile);
53  $writer = DataHandlerWriter::withBackendUser($backendUser);
54  $writer->invokeFactory($factory);
55  static::failIfArrayIsNotEmpty($writer->getErrors());
56  $this->setUpFrontendRootPage(
57  1000,
58  [
59  'EXT:core/Tests/Functional/Fixtures/Frontend/JsonRenderer.typoscript',
60  'EXT:frontend/Tests/Functional/SiteHandling/Fixtures/JsonRenderer.typoscript',
61  ],
62  [
63  'title' => 'ACME Root',
64  ]
65  );
66  });
67  }
68 
70  {
71  $domainPaths = [
72  'https://website.local/',
73  ];
74  $queries = [
75  '',
76  'welcome',
77  ];
78  $customQueries = [
79  '?testing[value]=1',
80  '?testing[value]=1&cHash=',
81  '?testing[value]=1&cHash=WRONG',
82  ];
83  return self::wrapInArray(
84  self::keysFromValues(
85  ‪PermutationUtility::meltStringItems([$domainPaths, $queries, $customQueries])
86  )
87  );
88  }
89 
90  #[DataProvider('pageRenderingStopsWithInvalidCacheHashDataProvider')]
91  #[Test]
93  {
95  'website-local',
96  $this->‪buildSiteConfiguration(1000, 'https://website.local/'),
97  [],
98  $this->‪buildErrorHandlingConfiguration('PHP', [404])
99  );
100 
101  $response = $this->executeFrontendSubRequest(new InternalRequest($uri));
102  $json = json_decode((string)$response->getBody(), true);
103 
104  self::assertThat(
105  $json['message'] ?? null,
106  self::logicalOr(
107  self::identicalTo(null),
108  self::identicalTo('Request parameters could not be validated (&cHash comparison failed)')
109  )
110  );
111  }
112 
113  public static function ‪pageIsRenderedWithValidCacheHashDataProvider(): array
114  {
115  $domainPaths = [
116  'https://website.local/',
117  ];
118  // cHash has been calculated with encryption key set to
119  // '4408d27a916d51e624b69af3554f516dbab61037a9f7b9fd6f81b4d3bedeccb6'
120  $queries = [
121  // @todo Currently fails since cHash is verified after(!) redirect to page 1100
122  // '?cHash=7d1f13fa91159dac7feb3c824936b39d',
123  // '?cHash=7d1f13fa91159dac7feb3c824936b39d',
124  'welcome?cHash=f42b850e435f0cedd366f5db749fc1af',
125  ];
126  $customQueries = [
127  '&testing[value]=1',
128  ];
129  return self::wrapInArray(
130  self::keysFromValues(
131  ‪PermutationUtility::meltStringItems([$domainPaths, $queries, $customQueries])
132  )
133  );
134  }
135 
136  #[DataProvider('pageIsRenderedWithValidCacheHashDataProvider')]
137  #[Test]
138  public function ‪pageIsRenderedWithValidCacheHash($uri): void
139  {
141  'website-local',
142  $this->‪buildSiteConfiguration(1000, 'https://website.local/')
143  );
144 
145  $response = $this->executeFrontendSubRequest(new InternalRequest($uri));
146  $responseStructure = ResponseContent::fromString(
147  (string)$response->getBody()
148  );
149  self::assertSame(
150  '1',
151  $responseStructure->getScopePath('getpost/testing.value')
152  );
153  }
154 }
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory
Definition: LanguageServiceFactory.php:25
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\SlugSiteWithoutRequiredCHashRequestTest\pageIsRenderedWithValidCacheHashDataProvider
‪static pageIsRenderedWithValidCacheHashDataProvider()
Definition: SlugSiteWithoutRequiredCHashRequestTest.php:113
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\writeSiteConfiguration
‪writeSiteConfiguration(string $identifier, array $site=[], array $languages=[], array $errorHandling=[])
Definition: SiteBasedTestTrait.php:50
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\SlugSiteWithoutRequiredCHashRequestTest\$configurationToUseInTestInstance
‪array $configurationToUseInTestInstance
Definition: SlugSiteWithoutRequiredCHashRequestTest.php:31
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\AbstractTestCase
Definition: AbstractTestCase.php:29
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildSiteConfiguration
‪buildSiteConfiguration(int $rootPageId, string $base='')
Definition: SiteBasedTestTrait.php:88
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\SlugSiteWithoutRequiredCHashRequestTest\pageRequestSendsNotFoundResponseWithInvalidCacheHash
‪pageRequestSendsNotFoundResponseWithInvalidCacheHash(string $uri)
Definition: SlugSiteWithoutRequiredCHashRequestTest.php:92
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildErrorHandlingConfiguration
‪buildErrorHandlingConfiguration(string $handler, array $codes)
Definition: SiteBasedTestTrait.php:142
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\SlugSiteWithoutRequiredCHashRequestTest
Definition: SlugSiteWithoutRequiredCHashRequestTest.php:30
‪TYPO3\CMS\Core\Utility\PermutationUtility
Definition: PermutationUtility.php:24
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\SlugSiteWithoutRequiredCHashRequestTest\pageIsRenderedWithValidCacheHash
‪pageIsRenderedWithValidCacheHash($uri)
Definition: SlugSiteWithoutRequiredCHashRequestTest.php:138
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\SlugSiteWithoutRequiredCHashRequestTest\setUp
‪setUp()
Definition: SlugSiteWithoutRequiredCHashRequestTest.php:44
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling
Definition: AbstractTestCase.php:18
‪TYPO3\CMS\Core\Utility\PermutationUtility\meltStringItems
‪static string[] meltStringItems(array $payload, string $previousResult='')
Definition: PermutationUtility.php:36
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\SlugSiteWithoutRequiredCHashRequestTest\pageRenderingStopsWithInvalidCacheHashDataProvider
‪static pageRenderingStopsWithInvalidCacheHashDataProvider()
Definition: SlugSiteWithoutRequiredCHashRequestTest.php:69