‪TYPO3CMS  11.5
InstallToolFormProtectionTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
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 
19 
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
27 class ‪InstallToolFormProtectionTest extends UnitTestCase
28 {
32  protected ‪$subject;
33 
37  protected function ‪setUp(): void
38  {
39  parent::setUp();
40  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = '';
41  $this->subject = $this->getAccessibleMock(
42  InstallToolFormProtection::class,
43  ['dummy']
44  );
45  }
46 
48  // Tests concerning the reading and saving of the tokens
50 
55  {
56  $sessionToken = '881ffea2159ac72182557b79dc0c723f5a8d20136f9fab56cdd4f8b3a1dbcfcd';
57  $formName = 'foo';
58  $action = 'edit';
59  $formInstanceName = '42';
60 
61  $tokenId = GeneralUtility::hmac($formName . $action . $formInstanceName . $sessionToken);
62 
63  $_SESSION['installToolFormToken'] = $sessionToken;
64 
65  $this->subject->_call('retrieveSessionToken');
66 
67  self::assertTrue(
68  $this->subject->validateToken($tokenId, $formName, $action, $formInstanceName)
69  );
70  }
71 
75  public function ‪persistSessionTokenWritesTokensToSession(): void
76  {
77  $_SESSION['installToolFormToken'] = 'foo';
78 
79  $this->subject->_set('sessionToken', '881ffea2159ac72182557b79dc0c723f5a8d20136f9fab56cdd4f8b3a1dbcfcd');
80 
81  $this->subject->persistSessionToken();
82 
83  self::assertEquals(
84  '881ffea2159ac72182557b79dc0c723f5a8d20136f9fab56cdd4f8b3a1dbcfcd',
85  $_SESSION['installToolFormToken']
86  );
87  }
88 }
‪TYPO3\CMS\Core\Tests\Unit\FormProtection\InstallToolFormProtectionTest\setUp
‪setUp()
Definition: InstallToolFormProtectionTest.php:36
‪TYPO3\CMS\Core\Tests\Unit\FormProtection\InstallToolFormProtectionTest\persistSessionTokenWritesTokensToSession
‪persistSessionTokenWritesTokensToSession()
Definition: InstallToolFormProtectionTest.php:74
‪TYPO3\CMS\Core\FormProtection\InstallToolFormProtection
Definition: InstallToolFormProtection.php:61
‪TYPO3\CMS\Core\Tests\Unit\FormProtection\InstallToolFormProtectionTest\tokenFromSessionDataIsAvailableForValidateToken
‪tokenFromSessionDataIsAvailableForValidateToken()
Definition: InstallToolFormProtectionTest.php:53
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Tests\Unit\FormProtection\InstallToolFormProtectionTest\$subject
‪TYPO3 CMS Core FormProtection InstallToolFormProtection PHPUnit Framework MockObject MockObject TYPO3 TestingFramework Core AccessibleObjectInterface $subject
Definition: InstallToolFormProtectionTest.php:31
‪TYPO3\CMS\Core\Tests\Unit\FormProtection
Definition: AbstractFormProtectionTest.php:18
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Core\Tests\Unit\FormProtection\InstallToolFormProtectionTest
Definition: InstallToolFormProtectionTest.php:28