Skip to content

Commit

Permalink
[TASK] Add tests to show working regexp redirects with query parameter
Browse files Browse the repository at this point in the history
With #101739 a bug has been reported, which is
not correct.

This change adds functional tests to `ext:redirects`
to show and cover that:

* regexp redirects with a pattern not covering params
  but query arguments are given in the request uri and
  "Respect GET Parameters" has been set do not redirect.
* RegExp Redirects with a pattern not covering params
  and no GET arguments are given in the request uri but
  "Respect GET Parameters" has been set redirects to the
  target url.

Resolves: #101739
Releases: main, 12.4, 11.5
Change-Id: I023889ba6fefe5a4b06b392e02dece4b6ac517c0
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/80886
Tested-by: core-ci <typo3@b13.com>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
Tested-by: Stefan Bürk <stefan@buerk.tech>
  • Loading branch information
sbuerk committed Sep 6, 2023
1 parent 61d4c55 commit bd308eb
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
Expand Up @@ -20,3 +20,5 @@ sys_redirect,,,,,,,,,,,
,14,0,301,0,0,acme.com,#^/respect-keep-relative-target-([a-zA-Z]{1}[a-zA-Z0-9]+)\?param1=([a-zA-Z]{1}[a-zA-Z0-9]+)$#,/$1/$2,1,1,1
,15,0,301,0,0,acme.com,#^/other-relative-target-with-unsafe-capture-group-(.*)#,/offer-$1,1,1,0
,16,0,301,0,0,acme.com,#^/other-redirect-with-unsafe-capture-group-(.*)#,https://anotherdomain.com/offer$1,1,1,0
# * @see https://forge.typo3.org/issues/101739
,17,0,301,0,0,acme.com,#^/regexp-respect-get-parameter$#,https://anotherdomain.com/regexp-respect-get-parameter,1,1,0
Expand Up @@ -332,6 +332,64 @@ public function checkRegExpRedirects(string $url, int $expectedStatusCode, strin
self::assertEquals($expectedRedirectUri, $response->getHeader('location')[0]);
}

/**
* @test
* @see https://forge.typo3.org/issues/101739
*/
public function regexpWithNoParamRegexpAndRespectingGetParameteresIssuesNotFoundStatusIfParamsAreGivenInUrl(): void
{
$url = 'https://acme.com/regexp-respect-get-parameter?param1=value1';
$expectedStatusCode = 404;
$this->importCSVDataSet(__DIR__ . '/Fixtures/RedirectService_regexp.csv');
$this->writeSiteConfiguration(
'acme-com',
$this->buildSiteConfiguration(1, 'https://acme.com/')
);
$this->setUpFrontendRootPage(
1,
['typo3/sysext/redirects/Tests/Functional/Service/Fixtures/Redirects.typoscript']
);

$response = $this->executeFrontendSubRequest(
new InternalRequest($url),
null,
false
);
self::assertSame($expectedStatusCode, $response->getStatusCode());
}

/**
* @test
* @see https://forge.typo3.org/issues/101739
*/
public function regexpWithNoParamRegexpAndRespectingGetParameteresRedirectsIfNoParamsAreGiven(): void
{
$url = 'https://acme.com/regexp-respect-get-parameter';
$expectedStatusCode = 301;
$expectedRedirectUid = 17;
$expectedRedirectUri = 'https://anotherdomain.com/regexp-respect-get-parameter';
$this->importCSVDataSet(__DIR__ . '/Fixtures/RedirectService_regexp.csv');
$this->writeSiteConfiguration(
'acme-com',
$this->buildSiteConfiguration(1, 'https://acme.com/')
);
$this->setUpFrontendRootPage(
1,
['typo3/sysext/redirects/Tests/Functional/Service/Fixtures/Redirects.typoscript']
);

$response = $this->executeFrontendSubRequest(
new InternalRequest($url),
null,
false
);
self::assertSame($expectedStatusCode, $response->getStatusCode());
self::assertIsArray($response->getHeader('X-Redirect-By'));
self::assertIsArray($response->getHeader('location'));
self::assertSame('TYPO3 Redirect ' . $expectedRedirectUid, $response->getHeader('X-Redirect-By')[0]);
self::assertSame($expectedRedirectUri, $response->getHeader('location')[0]);
}

public function samePathWithSameDomainT3TargetDataProvider(): array
{
return [
Expand Down

0 comments on commit bd308eb

Please sign in to comment.