[BUGFIX] Fix incomplete validation of source_host field
[Packages/TYPO3.CMS.git] / typo3 / sysext / redirects / Tests / Unit / Evaluation / SourceHostTest.php
1 <?php
2 declare(strict_types = 1);
3
4 namespace TYPO3\CMS\Redirects\Tests\Unit\Evaluation;
5
6 /*
7 * This file is part of the TYPO3 CMS project.
8 *
9 * It is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, either version 2
11 * of the License, or any later version.
12 *
13 * For the full copyright and license information, please read the
14 * LICENSE.txt file that was distributed with this source code.
15 *
16 * The TYPO3 project - inspiring people to share!
17 */
18
19 use TYPO3\CMS\Redirects\Evaluation\SourceHost;
20 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
21
22 class SourceHostTest extends UnitTestCase
23 {
24 /**
25 * @return array
26 */
27 public function evaluateFieldValueWorksWithDifferentInputsDataProvider(): array
28 {
29 return [
30 // Valid formats
31 'www.domain.com' => ['www.domain.com', 'www.domain.com'],
32 'domain.com' => ['domain.com', 'domain.com'],
33 '127.0.0.1' => ['127.0.0.1', '127.0.0.1'],
34 '2001:0db8:85a3:08d3::0370:7344' => ['2001:0db8:85a3:08d3::0370:7344', '2001:0db8:85a3:08d3::0370:7344'],
35 'http://127.0.0.1' => ['http://127.0.0.1', '127.0.0.1'],
36 'http://www.domain.com' => ['http://www.domain.com', 'www.domain.com'],
37 'https://www.domain.com' => ['https://www.domain.com', 'www.domain.com'],
38 'http://www.domain.com/subfolder/index.php?id=123&foo=bar' => [
39 'http://www.domain.com/subfolder/index.php?id=123&foo=bar',
40 'www.domain.com'
41 ],
42 'https://www.domain.com/subfolder/index.php?id=123&foo=bar' => [
43 'https://www.domain.com/subfolder/index.php?id=123&foo=bar',
44 'www.domain.com'
45 ],
46 'http://www.domain.com/subfolder/' => ['http://www.domain.com/subfolder/', 'www.domain.com'],
47 'https://www.domain.com/subfolder/' => ['https://www.domain.com/subfolder/', 'www.domain.com'],
48 'http://[2001:0db8:85a3:08d3::0370:7344]/' => [
49 'http://[2001:0db8:85a3:08d3::0370:7344]/',
50 '2001:0db8:85a3:08d3::0370:7344'
51 ],
52 'www.domain.com/subfolder/' => ['www.domain.com/subfolder/', 'www.domain.com'],
53 'domain.com/subfolder/' => ['domain.com/subfolder/', 'domain.com'],
54 'www.domain.com/subfolder/index.php?id=123&foo=bar' => [
55 'www.domain.com/subfolder/index.php?id=123&foo=bar',
56 'www.domain.com'
57 ],
58 'domain.com/subfolder/index.php?id=123&foo=bar' => [
59 'domain.com/subfolder/index.php?id=123&foo=bar',
60 'domain.com'
61 ],
62 // special case, * means all domains
63 '*' => ['*', '*'],
64
65 // Invalid formats
66 'mailto:foo@typo3.org' => ['mailto:foo@typo3.org', ''],
67 'mailto:foo@typo3.org?subject=bar' => ['mailto:foo@typo3.org?subject=bar', ''],
68 ];
69 }
70
71 /**
72 * @test
73 * @dataProvider evaluateFieldValueWorksWithDifferentInputsDataProvider
74 * @param string $input
75 * @param string $expected
76 */
77 public function evaluateFieldValueWorksWithDifferentInputs(string $input, string $expected)
78 {
79 $subject = new SourceHost();
80 $this->assertSame($expected, $subject->evaluateFieldValue($input));
81 }
82 }