‪TYPO3CMS  10.4
DebugExceptionHandlerTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Prophecy\Argument;
19 use Psr\Log\LoggerInterface;
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
27 class ‪DebugExceptionHandlerTest extends UnitTestCase
28 {
32  protected ‪$subject;
33 
37  protected function ‪setUp(): void
38  {
39  parent::setUp();
40  $this->subject = $this->getMockBuilder(DebugExceptionHandler::class)
41  ->setMethods(['sendStatusHeaders', 'writeLogEntries'])
42  ->disableOriginalConstructor()
43  ->getMock();
44  }
45 
50  {
51  $message = '<b>b</b><script>alert(1);</script>';
52  $exception = new \Exception($message, 1476049363);
53  ob_start();
54  $this->subject->echoExceptionWeb($exception);
55  ‪$output = ob_get_contents();
56  ob_end_clean();
57  self::assertStringContainsString(htmlspecialchars($message), ‪$output);
58  self::assertStringNotContainsString($message, ‪$output);
59  }
60 
66  public function ‪exampleUrlsForTokenAnonymization(): array
67  {
68  return [
69  'url with valid token' => [
70  'http://localhost/typo3/index.php?M=foo&moduleToken=5f1f7d447f22886e8ea206693b0d530ccd6b2b36',
71  'http://localhost/typo3/index.php?M=foo&moduleToken=--AnonymizedToken--'
72  ],
73  'url with valid token in the middle' => [
74  'http://localhost/typo3/index.php?M=foo&moduleToken=5f1f7d447f22886e8ea206693b0d530ccd6b2b36&param=asdf',
75  'http://localhost/typo3/index.php?M=foo&moduleToken=--AnonymizedToken--&param=asdf'
76  ],
77  'url with invalid token' => [
78  'http://localhost/typo3/index.php?M=foo&moduleToken=5f1f7d447f22886e8/e',
79  'http://localhost/typo3/index.php?M=foo&moduleToken=5f1f7d447f22886e8/e',
80  ],
81  'url with empty token' => [
82  'http://localhost/typo3/index.php?M=foo&moduleToken=',
83  'http://localhost/typo3/index.php?M=foo&moduleToken=',
84  ],
85  'url with no token' => [
86  'http://localhost/typo3/index.php?M=foo',
87  'http://localhost/typo3/index.php?M=foo',
88  ],
89  ];
90  }
91 
98  public function ‪logEntriesContainAnonymousTokens(string $originalUrl, string $expectedUrl)
99  {
101  $logger = $this->prophesize(LoggerInterface::class);
102  $logger->critical(Argument::containingString($expectedUrl), Argument::cetera())->shouldBeCalled();
103  ‪$subject->setLogger($logger->reveal());
104 
105  GeneralUtility::setIndpEnv('TYPO3_REQUEST_URL', $originalUrl);
106 
107  $exception = new \Exception('message', 1476049367);
108  ob_start();
109  ‪$subject->‪echoExceptionWeb($exception);
110  // output is caught, so it does not pollute the test run
111  ob_end_clean();
112  }
113 }
‪TYPO3\CMS\Core\Error\DebugExceptionHandler
Definition: DebugExceptionHandler.php:28
‪TYPO3\CMS\Core\Tests\Unit\Error
Definition: DebugExceptionHandlerTest.php:16
‪TYPO3\CMS\Core\Tests\Unit\Error\DebugExceptionHandlerTest\logEntriesContainAnonymousTokens
‪logEntriesContainAnonymousTokens(string $originalUrl, string $expectedUrl)
Definition: DebugExceptionHandlerTest.php:97
‪TYPO3\CMS\Core\Tests\Unit\Error\DebugExceptionHandlerTest\exampleUrlsForTokenAnonymization
‪string[][] exampleUrlsForTokenAnonymization()
Definition: DebugExceptionHandlerTest.php:65
‪TYPO3\CMS\Core\Tests\Unit\Error\DebugExceptionHandlerTest\echoExceptionWebEscapesExceptionMessage
‪echoExceptionWebEscapesExceptionMessage()
Definition: DebugExceptionHandlerTest.php:48
‪TYPO3\CMS\Core\Tests\Unit\Error\DebugExceptionHandlerTest
Definition: DebugExceptionHandlerTest.php:28
‪TYPO3\CMS\Core\Tests\Unit\Error\DebugExceptionHandlerTest\$subject
‪TYPO3 CMS Core Error DebugExceptionHandler PHPUnit Framework MockObject MockObject $subject
Definition: DebugExceptionHandlerTest.php:31
‪$output
‪$output
Definition: annotationChecker.php:119
‪TYPO3\CMS\Core\Tests\Unit\Error\DebugExceptionHandlerTest\setUp
‪setUp()
Definition: DebugExceptionHandlerTest.php:36
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Error\DebugExceptionHandler\echoExceptionWeb
‪echoExceptionWeb(\Throwable $exception)
Definition: DebugExceptionHandler.php:44