[TASK] Anonymize token in Exception handlers
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Error / AbstractExceptionHandlerTest.php
1 <?php
2 declare(strict_types=1);
3 namespace TYPO3\CMS\Core\Tests\Unit\Error;
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
18 use TYPO3\CMS\Core\Error\AbstractExceptionHandler;
19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
20
21 /**
22 * Testcase for the AbstractExceptionHandlerTest class
23 */
24 class AbstractExceptionHandlerTest extends UnitTestCase
25 {
26 /**
27 * Data provider with allowed contexts.
28 *
29 * @return array
30 */
31 public function exampleUrlsForTokenAnonymization(): array
32 {
33 return [
34 'url with valid token' => [
35 'http://localhost/typo3/index.php?M=foo&moduleToken=5f1f7d447f22886e8ea206693b0d530ccd6b2b36',
36 'http://localhost/typo3/index.php?M=foo&moduleToken=--AnonymizedToken--'
37 ],
38 'url with valid token in the middle' => [
39 'http://localhost/typo3/index.php?M=foo&moduleToken=5f1f7d447f22886e8ea206693b0d530ccd6b2b36&param=asdf',
40 'http://localhost/typo3/index.php?M=foo&moduleToken=--AnonymizedToken--&param=asdf'
41 ],
42 'url with invalid token' => [
43 'http://localhost/typo3/index.php?M=foo&moduleToken=5f1f7d447f22886e8/e',
44 'http://localhost/typo3/index.php?M=foo&moduleToken=5f1f7d447f22886e8/e',
45 ],
46 'url with empty token' => [
47 'http://localhost/typo3/index.php?M=foo&moduleToken=',
48 'http://localhost/typo3/index.php?M=foo&moduleToken=',
49 ],
50 'url with no token' => [
51 'http://localhost/typo3/index.php?M=foo',
52 'http://localhost/typo3/index.php?M=foo',
53 ],
54 ];
55 }
56
57 /**
58 * @test
59 * @dataProvider exampleUrlsForTokenAnonymization
60 * @param string $originalUrl
61 * @param string $expectedUrl
62 */
63 public function anonymizeTokenReturnsCorrectModifiedUrl(string $originalUrl, string $expectedUrl)
64 {
65 $mock = $this->getAccessibleMockForAbstractClass(AbstractExceptionHandler::class, ['dummy']);
66 $anonymizedUrl = $mock->_call('anonymizeToken', $originalUrl);
67 $this->assertSame($expectedUrl, $anonymizedUrl);
68 }
69 }