‪TYPO3CMS  10.4
InstallToolFormProtectionTest.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 
20 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
21 
25 class ‪InstallToolFormProtectionTest extends UnitTestCase
26 {
30  protected ‪$subject;
31 
35  protected function ‪setUp(): void
36  {
37  parent::setUp();
38  $this->subject = $this->getAccessibleMock(
39  InstallToolFormProtection::class,
40  ['dummy']
41  );
42  }
43 
45  // Tests concerning the reading and saving of the tokens
47 
52  {
53  $sessionToken = '881ffea2159ac72182557b79dc0c723f5a8d20136f9fab56cdd4f8b3a1dbcfcd';
54  $formName = 'foo';
55  $action = 'edit';
56  $formInstanceName = '42';
57 
58  $tokenId = GeneralUtility::hmac($formName . $action . $formInstanceName . $sessionToken);
59 
60  $_SESSION['installToolFormToken'] = $sessionToken;
61 
62  $this->subject->_call('retrieveSessionToken');
63 
64  self::assertTrue(
65  $this->subject->validateToken($tokenId, $formName, $action, $formInstanceName)
66  );
67  }
68 
73  {
74  $_SESSION['installToolFormToken'] = 'foo';
75 
76  $this->subject->_set('sessionToken', '881ffea2159ac72182557b79dc0c723f5a8d20136f9fab56cdd4f8b3a1dbcfcd');
77 
78  $this->subject->persistSessionToken();
79 
80  self::assertEquals(
81  '881ffea2159ac72182557b79dc0c723f5a8d20136f9fab56cdd4f8b3a1dbcfcd',
82  $_SESSION['installToolFormToken']
83  );
84  }
85 }
‪TYPO3\CMS\Core\Tests\Unit\FormProtection\InstallToolFormProtectionTest\setUp
‪setUp()
Definition: InstallToolFormProtectionTest.php:34
‪TYPO3\CMS\Core\Tests\Unit\FormProtection\InstallToolFormProtectionTest\persistSessionTokenWritesTokensToSession
‪persistSessionTokenWritesTokensToSession()
Definition: InstallToolFormProtectionTest.php:71
‪TYPO3\CMS\Core\FormProtection\InstallToolFormProtection
Definition: InstallToolFormProtection.php:61
‪TYPO3\CMS\Core\Tests\Unit\FormProtection\InstallToolFormProtectionTest\tokenFromSessionDataIsAvailableForValidateToken
‪tokenFromSessionDataIsAvailableForValidateToken()
Definition: InstallToolFormProtectionTest.php:50
‪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:29
‪TYPO3\CMS\Core\Tests\Unit\FormProtection
Definition: AbstractFormProtectionTest.php:18
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Tests\Unit\FormProtection\InstallToolFormProtectionTest
Definition: InstallToolFormProtectionTest.php:26