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