Skip to content
Snippets Groups Projects
Commit 4249feae authored by Stefan Bürk's avatar Stefan Bürk
Browse files

[TASK] Add tests to show working regexp redirects with query parameter

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/+/80848


Tested-by: default avatarcore-ci <typo3@b13.com>
Reviewed-by: default avatarStefan Bürk <stefan@buerk.tech>
Tested-by: default avatarStefan Bürk <stefan@buerk.tech>
parent 1943f86c
Branches
Tags
No related merge requests found
......@@ -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
......@@ -337,6 +337,64 @@ final class RedirectServiceTest extends FunctionalTestCase
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 static function samePathWithSameDomainT3TargetDataProvider(): array
{
return [
......
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