‪TYPO3CMS  10.4
RedirectServiceTest.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 Psr\Log\LoggerInterface;
33 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
34 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
35 
36 class ‪RedirectServiceTest extends FunctionalTestCase
37 {
39 
43  protected ‪$coreExtensionsToLoad = ['redirects'];
44 
48  protected ‪$testFilesToDelete = [];
49 
53  protected $configurationToUseInTestInstance = [
54  'FE' => [
55  'cacheHash' => [
56  'excludedParameters' => ['L', 'pk_campaign', 'pk_kwd', 'utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'gclid', 'fbclid', 'msclkid'],
57  // @todo this should be tested explicitly - enabled and disabled
58  'enforceValidation' => false,
59  ],
60  ],
61  ];
62 
63  protected function tearDown(): void
64  {
65  foreach ($this->‪testFilesToDelete as $filename) {
66  if (@is_file($filename)) {
67  unlink($filename);
68  }
69  }
70  parent::tearDown();
71  }
72 
76  public function linkForRedirectToAccessRestrictedPageIsBuild(): void
77  {
78  $this->‪importDataSet(__DIR__ . '/Fixtures/RedirectToAccessRestrictedPages.xml');
79 
81  'acme-com',
82  $this->‪buildSiteConfiguration(1, 'https://acme.com/')
83  );
84 
85  ‪$typoscriptFile = ‪Environment::getVarPath() . '/transient/setup.typoscript';
86  file_put_contents(‪$typoscriptFile, 'page = PAGE' . PHP_EOL . 'page.typeNum = 0');
88  $this->setUpFrontendRootPage(1, [‪$typoscriptFile]);
89 
90  ‪$logger = $this->prophesize(LoggerInterface::class);
93 
94  ‪$siteFinder = GeneralUtility::makeInstance(SiteFinder::class);
95  ‪$uri = new ‪Uri('https://acme.com/redirect-to-access-restricted-site');
96  ‪$request = ‪$GLOBALS['TYPO3_REQUEST'] = (new ‪ServerRequest(‪$uri))
97  ->withAttribute('site', ‪$siteFinder->getSiteByRootPageId(1))
98  ->withAttribute('frontend.user', ‪$frontendUserAuthentication)
99  ->withAttribute('applicationType', ‪SystemEnvironmentBuilder::REQUESTTYPE_FE);
100 
101  ‪$linkServiceProphecy = $this->prophesize(LinkService::class);
102  ‪$linkServiceProphecy->resolve('t3://page?uid=2')->willReturn(
103  [
104  'pageuid' => 2,
106  ]
107  );
108 
111  ‪$linkServiceProphecy->reveal(),
113  );
114  ‪$redirectService->setLogger(‪$logger->reveal());
115 
116  // Assert correct redirect is matched
117  ‪$redirectMatch = ‪$redirectService->matchRedirect(‪$uri->getHost(), ‪$uri->getPath(), ‪$uri->getQuery());
118  self::assertEquals(1, ‪$redirectMatch['uid']);
119  self::assertEquals('t3://page?uid=2', ‪$redirectMatch['target']);
120 
121  // Ensure we deal with an unauthorized request!
122  self::assertFalse(GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('frontend.user', 'isLoggedIn'));
123 
124  // Assert link to access restricted page is build
125  ‪$targetUrl = ‪$redirectService->getTargetUrl(
127  ‪$request->getQueryParams(),
128  ‪$request->getAttribute('frontend.user'),
129  ‪$request->getUri(),
130  ‪$request->getAttribute('site')
131  );
132  self::assertEquals(new ‪Uri('https://acme.com/access-restricted'), ‪$targetUrl);
133  }
134 
135  public function ‪redirectsDataProvider(): array
136  {
137  return [
138  [
139  'https://acme.com/redirect-301',
140  301,
141  'https://acme.com/',
142  1,
143  ],
144  [
145  'https://acme.com/redirect-308',
146  308,
147  'https://acme.com/page2',
148  2,
149  ],
150  [
151  'https://acme.com/redirect-302',
152  302,
153  'https://www.typo3.org',
154  3,
155  ],
156  ];
157  }
158 
163  public function ‪checkReponseCodeOnRedirect($url, $statusCode, ‪$targetUrl, $redirectUid): void
164  {
165  $this->‪importDataSet(__DIR__ . '/Fixtures/RedirectToPages.xml');
166 
168  'acme-com',
169  $this->‪buildSiteConfiguration(1, 'https://acme.com/')
170  );
171 
172  $this->setUpFrontendRootPage(
173  1,
174  ['typo3/sysext/redirects/Tests/Functional/Service/Fixtures/Redirects.typoscript']
175  );
176 
177  $response = $this->executeFrontendRequest(
178  new InternalRequest($url)
179  );
180  self::assertEquals($statusCode, $response->getStatusCode());
181  self::assertIsArray($response->getHeader('X-Redirect-By'));
182  self::assertIsArray($response->getHeader('location'));
183  self::assertEquals('TYPO3 Redirect ' . $redirectUid, $response->getHeader('X-Redirect-By')[0]);
184  self::assertEquals(‪$targetUrl, $response->getHeader('location')[0]);
185  }
186 
187  public function ‪checkRegExpRedirectsDataProvider(): array
188  {
189  return [
190  'regexp redirect respecting query parameter but not keeping them' => [
191  'https://acme.com/index.php?option=com_content&page=some_page',
192  301,
193  'https://anotherdomain.com/some_page',
194  1,
195  ],
196  'regexp redirect respecting query parameter and keeping them' => [
197  'https://acme.com/index.php?option=com_content2&page=some_page',
198  301,
199  'https://anotherdomain.com/some_page?option=com_content2&page=some_page',
200  2,
201  ],
202  'regexp redirect not respecting query parameters and not keeping them' => [
203  'https://acme.com/some-old-page-others?option=com_content',
204  301,
205  'https://anotherdomain.com/others',
206  3,
207  ],
208  'regexp redirect not respecting query parameters but keeping them' => [
209  'https://acme.com/some-page-others',
210  301,
211  'https://anotherdomain.com/others',
212  4,
213  ],
214  'regexp redirect not respecting query parameters and not keeping them, with query parameter in request' => [
215  'https://acme.com/some-old-page-others?option=com_content',
216  301,
217  'https://anotherdomain.com/others',
218  3,
219  ],
220  'regexp redirect not respecting query parameters but keeping them, without query parameter in request' => [
221  'https://acme.com/some-page-others',
222  301,
223  'https://anotherdomain.com/others',
224  4,
225  ],
226  // check against unsafe regexp captching group
227  'regexp redirect with unsafe captching group, respecting query parameters and not keeping them, with query parameter in request' => [
228  'https://acme.com/unsafe-captchinggroup-matching-queryparameters-others?option=com_content',
229  301,
230  'https://anotherdomain.com/others',
231  5,
232  ],
233  // checks against unsafe regexp captching group, but as keeping query parameters this may be undetected,
234  // and as such this test acts as counterpart to tests above
235  'regexp redirect with unsafe captching group, respecting query parameters but keeping them, with query parameter in request' => [
236  'https://acme.com/another-unsafe-captchinggroup-matching-queryparameters-others?option=com_content',
237  301,
238  'https://anotherdomain.com/others?option=com_content',
239  6,
240  ],
241  // check against safe regexp captching group
242  'regexp redirect safe captching group, respecting query parameters and not keeping them, with query parameter in request' => [
243  'https://acme.com/safe-captchinggroup-not-matching-queryparameters-others?option=com_content',
244  301,
245  'https://anotherdomain.com/others',
246  7,
247  ],
248  // checks against safe regexp captching group
249  'regexp redirect safe captching group, respecting query parameters but keeping them, with query parameter in request' => [
250  'https://acme.com/another-safe-captchinggroup-not-matching-queryparameters-others?option=com_content',
251  301,
252  'https://anotherdomain.com/others?option=com_content',
253  8,
254  ],
255  // check against more safe regexp captching group - this tests path fallback even with queryparameters in
256  // request for non query regexp with $ as end matching in regexp
257  'regexp redirect safe captching group, not respecting query parameters and not keeping them, with query parameter in request' => [
258  'https://acme.com/more-safe-captchinggroup-not-matching-queryparameters-others?option=com_content',
259  301,
260  'https://anotherdomain.com/others',
261  9,
262  ],
263  'regexp redirect safe captching group, not respecting query parameters but keeping them, with query parameter in request' => [
264  'https://acme.com/another-more-safe-captchinggroup-not-matching-queryparameters-others?option=com_content',
265  301,
266  'https://anotherdomain.com/others?option=com_content',
267  10,
268  ],
269  'regexp capture group with relative target' => [
270  'https://acme.com/relative-target-page2',
271  301,
272  '/page2',
273  11,
274  ],
275  'regexp capture group with relative target - keep query params' => [
276  'https://acme.com/relative-target-keep-page2?param1=value1',
277  301,
278  '/page2?param1=value1',
279  12,
280  ],
281  'regexp capture group with relative target - respect query param' => [
282  'https://acme.com/respect-relative-target-page2?param1=subpage',
283  301,
284  '/page2/subpage',
285  13,
286  ],
287  'regexp capture group with relative target - respect query param and keep them' => [
288  'https://acme.com/respect-keep-relative-target-page2?param1=subpage',
289  301,
290  '/page2/subpage?param1=subpage',
291  14,
292  ],
293  // test for https://forge.typo3.org/issues/89799#note-14
294  'regexp relative target redirect with unsafe regexp and without ending $' => [
295  'https://acme.com/other-relative-target-with-unsafe-capture-group-new',
296  301,
297  '/offer-new',
298  15,
299  ],
300  // test for https://forge.typo3.org/issues/89799#note-14
301  'regexp redirect with unsafe regexp and without ending $' => [
302  'https://acme.com/other-redirect-with-unsafe-capture-group-new',
303  301,
304  'https://anotherdomain.com/offernew',
305  16,
306  ],
307  ];
308  }
309 
314  public function ‪checkRegExpRedirects(string $url, int $expectedStatusCode, string $expectedRedirectUri, int $expectedRedirectUid)
315  {
316  $this->‪importDataSet(__DIR__ . '/Fixtures/RedirectService_regexp.xml');
318  'acme-com',
319  $this->‪buildSiteConfiguration(1, 'https://acme.com/')
320  );
321  $this->setUpFrontendRootPage(
322  1,
323  ['typo3/sysext/redirects/Tests/Functional/Service/Fixtures/Redirects.typoscript']
324  );
325 
326  $response = $this->executeFrontendRequest(
327  new InternalRequest($url)
328  );
329  self::assertEquals($expectedStatusCode, $response->getStatusCode());
330  self::assertIsArray($response->getHeader('X-Redirect-By'));
331  self::assertIsArray($response->getHeader('location'));
332  self::assertEquals('TYPO3 Redirect ' . $expectedRedirectUid, $response->getHeader('X-Redirect-By')[0]);
333  self::assertEquals($expectedRedirectUri, $response->getHeader('location')[0]);
334  }
335 
336  public function ‪samePathWithSameDomainT3TargetDataProvider(): array
337  {
338  return [
339  'flat' => [
340  'https://acme.com/flat-samehost-1',
341  'https://acme.com/',
342  200,
343  null,
344  null,
345  ],
346  // this should redirect and not pass through
347  'flat - with query parameters' => [
348  'https://acme.com/flat-samehost-1?param1=value1&cHash=e0527192caa60a6dac1e30af7cfeaf64',
349  'https://acme.com/',
350  301,
351  'https://acme.com/flat-samehost-1',
352  1,
353  ],
354  'flat keep_query_parameters' => [
355  'https://acme.com/flat-samehost-2',
356  'https://acme.com/',
357  200,
358  null,
359  null,
360  ],
361  'flat keep_query_parameters - with query parameters' => [
362  'https://acme.com/flat-samehost-2?param1=value1&cHash=e0527192caa60a6dac1e30af7cfeaf64',
363  'https://acme.com/',
364  200,
365  null,
366  null,
367  ],
368  'flat respect_query_parameters' => [
369  'https://acme.com/flat-samehost-3',
370  'https://acme.com/',
371  200,
372  null,
373  null,
374  ],
375  // this should redirect and not pass through
376  'flat respect_query_parameters - with query parameters' => [
377  'https://acme.com/flat-samehost-3?param1=value1',
378  'https://acme.com/',
379  301,
380  'https://acme.com/flat-samehost-3',
381  3,
382  ],
383  'flat respect_query_parameters and keep_query_parameters' => [
384  'https://acme.com/flat-samehost-4',
385  'https://acme.com/',
386  200,
387  null,
388  null,
389  ],
390  'flat respect_query_parameters and keep_query_parameters - with query parameters' => [
391  'https://acme.com/flat-samehost-4?param1=value1&cHash=caa2156411affc2d7c8c5169652c6e13',
392  'https://acme.com/',
393  200,
394  null,
395  null,
396  ],
397  'regexp' => [
398  'https://acme.com/regexp-samehost-1',
399  'https://acme.com/',
400  200,
401  null,
402  null,
403  ],
404  // this should redirect and not pass through
405  'regexp - with query parameters' => [
406  'https://acme.com/regexp-samehost-1?param1=value1',
407  'https://acme.com/',
408  301,
409  'https://acme.com/regexp-samehost-1',
410  5,
411  ],
412  'regexp keep_query_parameters' => [
413  'https://acme.com/regexp-samehost-2',
414  'https://acme.com/',
415  200,
416  null,
417  null,
418  ],
419  'regexp keep_query_parameters - with query parameters' => [
420  'https://acme.com/regexp-samehost-2?param1=value1&cHash=feced69fa13ce7d3bf0483c21ff03064',
421  'https://acme.com/',
422  200,
423  null,
424  null,
425  ],
426  // this should redirect and not pass through
427  'regexp keep_query_parameters - with query parameters but without cHash' => [
428  'https://acme.com/regexp-samehost-2?param1=value1',
429  'https://acme.com/',
430  301,
431  'https://acme.com/regexp-samehost-2?param1=value1&cHash=feced69fa13ce7d3bf0483c21ff03064',
432  6,
433  ],
434  'regexp respect_query_parameters' => [
435  'https://acme.com/regexp-samehost-3',
436  'https://acme.com/',
437  200,
438  null,
439  null,
440  ],
441  // this should redirect and not pass through
442  'regexp respect_query_parameters - with query parameters but without cHash' => [
443  'https://acme.com/regexp-samehost-3?param1=value1',
444  'https://acme.com/',
445  301,
446  'https://acme.com/regexp-samehost-3',
447  7,
448  ],
449  'same host as external target with query arguments in another order than target should pass instead of redirect' => [
450  'https://acme.com/sanatize-samehost-3?param1=value1&param2=value2&param3=&cHash=69f1b01feb7ed14b95b85cbc66ee2a3a',
451  'https://acme.com/',
452  200,
453  null,
454  null,
455  ],
456  'same host as external target with fragment should pass instead of redirect' => [
457  'https://acme.com/sanatize-samehost-4',
458  'https://acme.com/',
459  200,
460  null,
461  null,
462  ],
463  ];
464  }
465 
470  public function ‪samePathWithSameDomainT3Target(string $url, string $baseUri, int $expectedStatusCode, ?string $expectedRedirectUri, ?int $expectedRedirectUid): void
471  {
472  $this->importCSVDataSet(__DIR__ . '/Fixtures/RedirectService_samePathWithSameDomainT3Target.csv');
474  'acme-com',
475  $this->‪buildSiteConfiguration(1, $baseUri)
476  );
477  $this->setUpFrontendRootPage(
478  1,
479  ['typo3/sysext/redirects/Tests/Functional/Service/Fixtures/Redirects.typoscript']
480  );
481 
482  $response = $this->executeFrontendRequest(
483  new InternalRequest($url),
484  null,
485  false
486  );
487  self::assertEquals($expectedStatusCode, $response->getStatusCode());
488  if ($expectedRedirectUri) {
489  self::assertIsArray($response->getHeader('X-Redirect-By'));
490  self::assertIsArray($response->getHeader('location'));
491  self::assertEquals('TYPO3 Redirect ' . $expectedRedirectUid, $response->getHeader('X-Redirect-By')[0]);
492  self::assertEquals($expectedRedirectUri, $response->getHeader('location')[0]);
493  }
494  }
495 
497  {
498  return [
499  'flat' => [
500  'https://acme.com/flat-samehost-1',
501  'https://acme.com/',
502  200,
503  null,
504  null,
505  ],
506  // this should redirect and not pass through
507  'flat - with query parameters' => [
508  'https://acme.com/flat-samehost-1?param1=value1&cHash=e0527192caa60a6dac1e30af7cfeaf64',
509  'https://acme.com/',
510  301,
511  '/flat-samehost-1',
512  1,
513  ],
514  'flat keep_query_parameters' => [
515  'https://acme.com/flat-samehost-2',
516  'https://acme.com/',
517  200,
518  null,
519  null,
520  ],
521  'flat keep_query_parameters - with query parameters' => [
522  'https://acme.com/flat-samehost-2?param1=value1&cHash=e0527192caa60a6dac1e30af7cfeaf64',
523  'https://acme.com/',
524  200,
525  null,
526  null,
527  ],
528  'flat respect_query_parameters' => [
529  'https://acme.com/flat-samehost-3',
530  'https://acme.com/',
531  200,
532  null,
533  null,
534  ],
535  // this should redirect and not pass through
536  'flat respect_query_parameters - with query parameters' => [
537  'https://acme.com/flat-samehost-3?param1=value1',
538  'https://acme.com/',
539  301,
540  '/flat-samehost-3',
541  3,
542  ],
543  'flat respect_query_parameters and keep_query_parameters' => [
544  'https://acme.com/flat-samehost-4',
545  'https://acme.com/',
546  200,
547  null,
548  null,
549  ],
550  'flat respect_query_parameters and keep_query_parameters - with query parameters' => [
551  'https://acme.com/flat-samehost-4?param1=value1&cHash=caa2156411affc2d7c8c5169652c6e13',
552  'https://acme.com/',
553  200,
554  null,
555  null,
556  ],
557  'regexp' => [
558  'https://acme.com/regexp-samehost-1',
559  'https://acme.com/',
560  200,
561  null,
562  null,
563  ],
564  // this should redirect and not pass through
565  'regexp - with query parameters' => [
566  'https://acme.com/regexp-samehost-1?param1=value1',
567  'https://acme.com/',
568  301,
569  '/regexp-samehost-1',
570  5,
571  ],
572  'regexp keep_query_parameters' => [
573  'https://acme.com/regexp-samehost-2',
574  'https://acme.com/',
575  200,
576  null,
577  null,
578  ],
579  'regexp keep_query_parameters - with query parameters' => [
580  'https://acme.com/regexp-samehost-2?param1=value1&cHash=feced69fa13ce7d3bf0483c21ff03064',
581  'https://acme.com/',
582  200,
583  null,
584  null,
585  ],
586  'regexp keep_query_parameters - with query parameters but without cHash' => [
587  'https://acme.com/regexp-samehost-2?param1=value1',
588  'https://acme.com/',
589  200,
590  null,
591  null,
592  ],
593  'regexp respect_query_parameters' => [
594  'https://acme.com/regexp-samehost-3',
595  'https://acme.com/',
596  200,
597  null,
598  null,
599  ],
600  // this should redirect and not pass through
601  'regexp respect_query_parameters - with query parameters but without cHash' => [
602  'https://acme.com/regexp-samehost-3?param1=value1',
603  'https://acme.com/',
604  301,
605  '/regexp-samehost-3',
606  7,
607  ],
608  ];
609  }
610 
615  public function ‪samePathWithSameDomainAndRelativeTarget(string $url, string $baseUri, int $expectedStatusCode, ?string $expectedRedirectUri, ?int $expectedRedirectUid): void
616  {
617  $this->importCSVDataSet(__DIR__ . '/Fixtures/RedirectService_samePathWithSameDomainAndRelativeTarget.csv');
619  'acme-com',
620  $this->‪buildSiteConfiguration(1, $baseUri)
621  );
622  $this->setUpFrontendRootPage(
623  1,
624  ['typo3/sysext/redirects/Tests/Functional/Service/Fixtures/Redirects.typoscript']
625  );
626 
627  $response = $this->executeFrontendRequest(
628  new InternalRequest($url),
629  null,
630  false
631  );
632  self::assertEquals($expectedStatusCode, $response->getStatusCode());
633  if ($expectedRedirectUri) {
634  self::assertIsArray($response->getHeader('X-Redirect-By'));
635  self::assertIsArray($response->getHeader('location'));
636  self::assertEquals('TYPO3 Redirect ' . $expectedRedirectUid, $response->getHeader('X-Redirect-By')[0]);
637  self::assertEquals($expectedRedirectUri, $response->getHeader('location')[0]);
638  }
639  }
640 
642  {
643  return [
644  'flat' => [
645  'https://acme.com/flat-samehost-1',
646  'https://acme.com/',
647  301,
648  'https://external.acme.com/flat-samehost-1',
649  1,
650  ],
651  'flat - with query parameters' => [
652  'https://acme.com/flat-samehost-1?param1=value1&cHash=e0527192caa60a6dac1e30af7cfeaf64',
653  'https://acme.com/',
654  301,
655  'https://external.acme.com/flat-samehost-1',
656  1,
657  ],
658  'flat keep_query_parameters' => [
659  'https://acme.com/flat-samehost-2',
660  'https://acme.com/',
661  301,
662  'https://external.acme.com/flat-samehost-2',
663  2,
664  ],
665  'flat keep_query_parameters - with query parameters' => [
666  'https://acme.com/flat-samehost-2?param1=value1',
667  'https://acme.com/',
668  301,
669  'https://external.acme.com/flat-samehost-2?param1=value1',
670  2,
671  ],
672  // following will not match at all, so it is expected to be resolved with 200
673  'flat respect_query_parameters' => [
674  'https://acme.com/flat-samehost-3',
675  'https://acme.com/',
676  200,
677  null,
678  null,
679  ],
680  'flat respect_query_parameters - with query parameters' => [
681  'https://acme.com/flat-samehost-3?param1=value1',
682  'https://acme.com/',
683  301,
684  'https://external.acme.com/flat-samehost-3',
685  3,
686  ],
687  // following will not match at all, so it is expected to be resolved with 200
688  'flat respect_query_parameters and keep_query_parameters' => [
689  'https://acme.com/flat-samehost-4',
690  'https://acme.com/',
691  200,
692  null,
693  null,
694  ],
695  'flat respect_query_parameters and keep_query_parameters - with query parameters' => [
696  'https://acme.com/flat-samehost-4?param1=value1',
697  'https://acme.com/',
698  301,
699  'https://external.acme.com/flat-samehost-4?param1=value1',
700  4,
701  ],
702  'regexp' => [
703  'https://acme.com/regexp-samehost-1',
704  'https://acme.com/',
705  301,
706  'https://external.acme.com/regexp-samehost-1',
707  5,
708  ],
709  'regexp - with query parameters' => [
710  'https://acme.com/regexp-samehost-1?param1=value1',
711  'https://acme.com/',
712  301,
713  'https://external.acme.com/regexp-samehost-1',
714  5,
715  ],
716  'regexp keep_query_parameters' => [
717  'https://acme.com/regexp-samehost-2',
718  'https://acme.com/',
719  301,
720  'https://external.acme.com/regexp-samehost-2',
721  6,
722  ],
723  'regexp keep_query_parameters - with query parameters' => [
724  'https://acme.com/regexp-samehost-2?param1=value1',
725  'https://acme.com/',
726  301,
727  'https://external.acme.com/regexp-samehost-2?param1=value1',
728  6,
729  ],
730  'regexp respect_query_parameters' => [
731  'https://acme.com/regexp-samehost-3',
732  'https://acme.com/',
733  301,
734  'https://external.acme.com/regexp-samehost-3',
735  7,
736  ],
737  // this should redirect and not pass through
738  'regexp respect_query_parameters - with query parameters but without cHash' => [
739  'https://acme.com/regexp-samehost-3?param1=value1',
740  'https://acme.com/',
741  301,
742  'https://external.acme.com/regexp-samehost-3',
743  7,
744  ],
745  'same host as external target with port should pass instead of redirect' => [
746  'https://acme.com/sanatize-samehost-1',
747  'https://acme.com/',
748  200,
749  null,
750  null,
751  ],
752  'same host as external target with userinfo should pass instead of redirect' => [
753  'https://acme.com/sanatize-samehost-2',
754  'https://acme.com/',
755  200,
756  null,
757  null,
758  ],
759  'same host as external target with query arguments in another order than target should pass instead of redirect' => [
760  'https://acme.com/sanatize-samehost-3?param1=value1&param2=value2&param3=',
761  'https://acme.com/',
762  200,
763  null,
764  null,
765  ],
766  'same host as external target with fragment should pass instead of redirect' => [
767  'https://acme.com/sanatize-samehost-4',
768  'https://acme.com/',
769  200,
770  null,
771  null,
772  ],
773  ];
774  }
775 
780  public function ‪samePathRedirectsWithExternalTarget(string $url, string $baseUri, int $expectedStatusCode, ?string $expectedRedirectUri, ?int $expectedRedirectUid): void
781  {
782  $this->importCSVDataSet(__DIR__ . '/Fixtures/RedirectService_samePathRedirectsWithExternalTarget.csv');
784  'acme-com',
785  $this->‪buildSiteConfiguration(1, $baseUri)
786  );
787  $this->setUpFrontendRootPage(
788  1,
789  ['typo3/sysext/redirects/Tests/Functional/Service/Fixtures/Redirects.typoscript']
790  );
791 
792  $response = $this->executeFrontendRequest(
793  new InternalRequest($url),
794  null,
795  false
796  );
797  self::assertEquals($expectedStatusCode, $response->getStatusCode());
798  if ($expectedRedirectUri) {
799  self::assertIsArray($response->getHeader('X-Redirect-By'));
800  self::assertIsArray($response->getHeader('location'));
801  self::assertEquals('TYPO3 Redirect ' . $expectedRedirectUid, $response->getHeader('X-Redirect-By')[0]);
802  self::assertEquals($expectedRedirectUri, $response->getHeader('location')[0]);
803  }
804  }
805 }
‪TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest\samePathWithSameDomainAndRelativeTargetDataProvider
‪samePathWithSameDomainAndRelativeTargetDataProvider()
Definition: RedirectServiceTest.php:492
‪TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest\checkRegExpRedirects
‪checkRegExpRedirects(string $url, int $expectedStatusCode, string $expectedRedirectUri, int $expectedRedirectUid)
Definition: RedirectServiceTest.php:310
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder
Definition: SystemEnvironmentBuilder.php:42
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait
Definition: SiteBasedTestTrait.php:36
‪TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest\importDataSet
‪array< string, $configurationToUseInTestInstance=array('FE'=>['cacheHash'=>['excludedParameters'=>[ 'L', 'pk_campaign', 'pk_kwd', 'utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'gclid', 'fbclid', 'msclkid'], 'enforceValidation'=> false,],],);protected tearDown():void { foreach( $this->testFilesToDelete as $filename) { if( @is_file( $filename)) { unlink( $filename);} } parent::tearDown();} public function linkForRedirectToAccessRestrictedPageIsBuild():void { $this-> importDataSet(__DIR__ . '/Fixtures/RedirectToAccessRestrictedPages.xml')
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\writeSiteConfiguration
‪writeSiteConfiguration(string $identifier, array $site=[], array $languages=[], array $errorHandling=[])
Definition: SiteBasedTestTrait.php:58
‪TYPO3\CMS\Redirects\Service\RedirectService
Definition: RedirectService.php:48
‪TYPO3\CMS\Core\Site\SiteFinder
Definition: SiteFinder.php:31
‪TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest\samePathWithSameDomainT3TargetDataProvider
‪samePathWithSameDomainT3TargetDataProvider()
Definition: RedirectServiceTest.php:332
‪TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest\$coreExtensionsToLoad
‪string[] $coreExtensionsToLoad
Definition: RedirectServiceTest.php:41
‪TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest\$linkServiceProphecy
‪$linkServiceProphecy
Definition: RedirectServiceTest.php:97
‪TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest\samePathRedirectsWithExternalTarget
‪samePathRedirectsWithExternalTarget(string $url, string $baseUri, int $expectedStatusCode, ?string $expectedRedirectUri, ?int $expectedRedirectUid)
Definition: RedirectServiceTest.php:776
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:53
‪TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest\testFilesToDelete
‪$this testFilesToDelete[]
Definition: RedirectServiceTest.php:83
‪TYPO3\CMS\Core\Http\Uri
Definition: Uri.php:29
‪TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest\samePathWithSameDomainT3Target
‪samePathWithSameDomainT3Target(string $url, string $baseUri, int $expectedStatusCode, ?string $expectedRedirectUri, ?int $expectedRedirectUid)
Definition: RedirectServiceTest.php:466
‪TYPO3\CMS\Redirects\Service\RedirectCacheService
Definition: RedirectCacheService.php:33
‪TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest\$targetUrl
‪$targetUrl
Definition: RedirectServiceTest.php:121
‪TYPO3\CMS\Redirects\Tests\Functional\Service
Definition: IntegrityServiceTest.php:18
‪TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest\samePathWithSameDomainAndRelativeTarget
‪samePathWithSameDomainAndRelativeTarget(string $url, string $baseUri, int $expectedStatusCode, ?string $expectedRedirectUri, ?int $expectedRedirectUid)
Definition: RedirectServiceTest.php:611
‪TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest\checkRegExpRedirectsDataProvider
‪checkRegExpRedirectsDataProvider()
Definition: RedirectServiceTest.php:183
‪TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest\$request
‪$request
Definition: RedirectServiceTest.php:92
‪TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest\redirectsDataProvider
‪redirectsDataProvider()
Definition: RedirectServiceTest.php:131
‪TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest\$logger
‪$logger
Definition: RedirectServiceTest.php:86
‪TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest\$testFilesToDelete
‪string[] $testFilesToDelete
Definition: RedirectServiceTest.php:45
‪TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest\$siteFinder
‪$siteFinder
Definition: RedirectServiceTest.php:90
‪TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest
Definition: RedirectServiceTest.php:37
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:37
‪TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest\checkReponseCodeOnRedirect
‪checkReponseCodeOnRedirect($url, $statusCode, $targetUrl, $redirectUid)
Definition: RedirectServiceTest.php:159
‪TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest\samePathRedirectsWithExternalTargetDataProvider
‪samePathRedirectsWithExternalTargetDataProvider()
Definition: RedirectServiceTest.php:637
‪TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest\$uri
‪$uri
Definition: RedirectServiceTest.php:91
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:40
‪TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest\$redirectMatch
‪$redirectMatch
Definition: RedirectServiceTest.php:113
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildSiteConfiguration
‪array buildSiteConfiguration(int $rootPageId, string $base='')
Definition: SiteBasedTestTrait.php:109
‪TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest\$frontendUserAuthentication
‪$frontendUserAuthentication
Definition: RedirectServiceTest.php:87
‪TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest\$redirectService
‪$redirectService
Definition: RedirectServiceTest.php:105
‪TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication
Definition: FrontendUserAuthentication.php:30
‪TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest\$typoscriptFile
‪$typoscriptFile
Definition: RedirectServiceTest.php:81
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder\REQUESTTYPE_FE
‪const REQUESTTYPE_FE
Definition: SystemEnvironmentBuilder.php:44
‪TYPO3\CMS\Core\Core\Environment\getVarPath
‪static string getVarPath()
Definition: Environment.php:192